summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509 (follow)
Commit message (Collapse)AuthorAgeFilesLines
...
* Hoist IPAddressFamily_cmp() to the other IPAddressFamily functions.tb2022-01-051-29/+29
| | | | ok inoguchi jsing
* Call x a cert for readability.tb2022-01-051-13/+13
|
* Now that i is free, rename j to i for use as loop variable intb2022-01-051-10/+10
| | | | various loops in addr_validate_path_internal().
* In addr_validate_path_internal() rename i to depth because that'stb2022-01-051-17/+15
| | | | what it is.
* Turn the validation_err() macro into a functiontb2022-01-051-31/+44
| | | | | | | | | | | | validation_err() is an ugly macro with side effects and a goto in it. At the cost of a few lines of code we can turn this into a function where the side effects are explicit and ret is now explicitly set in the main body of addr_validate_path_internal(). We get to a point where it is halfway possible to reason about the convoluted control flow in this function. ok inoguchi jsing
* Move variable declarations in X509v3_addr_canonize() to the top oftb2022-01-051-17/+19
| | | | | | the function and unindent some code. ok inoguchi jsing
* Remove a bogus memcmp in range_should_be_prefix()tb2022-01-051-3/+6
| | | | | | | | | | | | | | | | | | range_should_be_prefix() currently always fails. The reason for this is that OpenSSL commit 42d7d7dd incorrectly moved a memcmp() out of an assertion. As a consequence, the library emits and accepts incorrectly encoded ipAddrBlock extensions since it will never detect ranges that MUST be encoded as a prefix according to RFC 3779, 2.2.3.7. The return -1 from this memcmp() indicates to the callers that the range should be expressed as a range, so callers must check beforehand that min <= max to be able to fail. Thus, remove this memcmp() and add a check to make_addressRange(), the only caller that didn't already ensure that min <= max. This fixes the noisy output in regress/lib/libcrypto/x509/rfc3779. ok inoguchi jsing
* Polish X509v3_addr_subset() a bittb2022-01-051-15/+28
| | | | | | | | | Use child and parent instead of a and b. Split unrelated checks. Use accessors and assign to local variables to avoid ugly line wrapping. Declare vriables up front instead of mixing declarations with assignments from function returns. ok inoguchi jsing
* Readability tweaks in addr_contains()tb2022-01-051-5/+13
| | | | | | Assign to local variables to avoid ugly line wrapping. ok inoguchi jsing
* Fix a bug in addr_contains() introduced in OpenSSL commit be71c372tb2022-01-051-2/+2
| | | | | | | by returning 0 instead of -1 on extract_min_max() failure. Callers would interpret -1 as success of addr_contains(). ok inoguchi jsing
* Readability tweaks in the print helper i2r_IPAddressOrRanges.tb2022-01-041-9/+17
| | | | | Assign repeated nested expressions to local variables and avoid some awkward line wrapping.
* Consistently name variables with a _len suffix instead of mixingtb2022-01-041-35/+35
| | | | | | things like prefixlen, afi_length, etc. suggested by jsing
* Only check the parent to be canonical once we know it is non-NULL.tb2022-01-041-6/+5
| | | | suggested by jsing during review
* Refactor extract_min_max()tb2022-01-041-11/+28
| | | | | | | | | | extract_min_max() crammed all the work in two return statements inside a switch. Make this more readable by splitting out the extraction of the min and max as BIT STRINGs from an addressPrefix or an addressRange and once that's done expanding them to raw addresses. ok inoguchi jsing
* Remove checks that are duplicated in extract_min_max()tb2022-01-041-8/+1
| | | | | | | | The NULL checks and the checks that aor->type is reasonable are already performed in extract_min_max(), so it is unnecessary to repeat them in X509v3_addr_get_range() ok inoguchi jsing
* Make X509v3_addr_get_range() readable.tb2022-01-041-7/+17
| | | | | | | Instead of checking everything in a single if statement, group the checks according to their purposes. ok inoguchi jsing
* Add a length check to make_addressPrefix()tb2022-01-041-12/+25
| | | | | | | | | | Make the callers pass in the afi so that make_addressPrefix() can check prefixlen to be reasonable. If the afi is anything else than IPv4 or IPv6, cap its length at the length needed for IPv6. This way we avoid arbitrary out-of-bounds reads if the caller decides to pass in something stupid. ok inoguchi jsing
* Remove some dead codetb2022-01-041-7/+1
| | | | | | | IPAddressRange_new() populates both its min and max members, so they won't ever be NULL and will never need to be allocated. ok inoguchi jsing
* Drop a pointless NULL checktb2022-01-041-3/+2
| | | | | | | | IPAddressOrRange_new() instantiates a choice type, so we need to allocate one member of the union ourselves, so aor->u.addressPrefix will always be NULL. ok inoguchi jsing
* First pass over x509_addr_validate_path()tb2022-01-041-37/+79
| | | | | | | Replace reaching into the structs with IPAddressFamily accessors and add a few comments that explain what the code is actually doing. ok inoguchi jsing
* Refactor IPAddressFamily accessorstb2022-01-041-37/+90
| | | | | | | | | | | Introduce a helper function that allows fetching the AFI and the optional SAFI out of an IPAddressFamily. Also add two wrappers that only fetch and validate the AFI, where validation currently only means that the length is between 2 and 3. Use these accessors throughout to simplify and streamline the code. ok inoguchi jsing
* Fix typo in commenttb2021-12-281-2/+2
|
* Use lowercase letters for hexadecimal constants, as both jsing and Itb2021-12-281-15/+15
| | | | prefer this.
* Rewrite X509v3_addr_canonize() with new accessorstb2021-12-281-7/+9
| | | | | | | This is again a straightforward conversion and leads to something which matches our usual style more. ok jsing
* Validate AFIs before sorting in X509v3_adr_canonize()tb2021-12-281-1/+7
| | | | | | | Again, we're dealing with necessarily not fully validated data here, so a check up front seems prudent. ok jsing
* Rewrite/simplify X509v3_addr_is_canonical()tb2021-12-281-40/+36
| | | | | | | | This is a more or less straightforward conversion using the new IPAddressFamily accessor API. As a result, some checks have become a bit stricter, which is only desirable here. ok jsing
* Check AFI/SAFI before comparing them in X509v3_addr_is_canonical()tb2021-12-281-1/+8
| | | | | | | | | As mentioned in a previous commit, IPAddressFamily_cmp() can't really check for trailing garbage in addressFamily->data. Since the path validation and hence the X.509 validator call X509v3_addr_is_canonical(), this deals with only partially validated data. ok jsing
* Make IPAddressFamily_cmp() more pleasing on the eyetb2021-12-281-4/+11
| | | | | | | | | | | | | | Define and use MINIMUM() instead of a ternary operator and separate the code from the declarations. Also, we can spare a line to make the return legible instead of squeezing it into another ternary operator. addressFamily->data contains a two-bytes AFI and an optional one-byte SAFI. This function currently also compares any trailing garbage that may be present. Since comparison functions can't really error, this needs to be checked bofore it is used. Such checks will be added in subsequent commits. ok jsing
* Style improvements in X509v3_addr_add_range()tb2021-12-281-8/+15
| | | | ok jsing
* Style improvements in X509v3_addr_add_prefix()tb2021-12-281-7/+16
| | | | ok jsing
* Another small readability tweak in X509v3_addr_inherits()tb2021-12-281-2/+3
| | | | Declare IPAddressFamily before using it.
* Use an accessor in X509v3_addr_inherits()tb2021-12-281-2/+2
|
* Add a comment to i2r_IPAddrBlocks that we may want/have to deal withtb2021-12-281-1/+2
| | | | | | unknown address family types. Pointed out by jsing during review.
* Add a few accessors for IPAddressFamily and make first use of themtb2021-12-281-25/+94
| | | | | | | | | | | | | | One reason why this file is hard to read are endless repetitions of checks and assignments reaching deep inside structs. This can be made much more readable by adding a bunch of accessors. As a first step, we deal with IPAddressFamily, where we want to check the type of the ipAddressChoice member, check whether the inheritance element is present or access the addressOrRanges field. This diff already makes minimal use of these accessors to appease -Werror. More use and additional accessors will follow in later passes. ok inoguchi jsing
* Simplify and explain expand_addr() a bittb2021-12-281-12/+23
| | | | | | | | | | | | | | | | RFC 3779 section 2.1.2 does a decent job of explaining how IP addresses are encoded in. What's stored amounts to a prefix with all trailing zero octets omitted. If there are trailing zero bits in the last non-zero octet, bs->flags & 7 indicates how many. addr_expand() expands this to an address of length 4 or 16 depending on whether we deal with IPv4 or IPv6. Since an address can be the lower or the upper bound of a prefix or address range, expansion needs to be able to zero-fill or one-fill the unused bits/octets. No other expansion is ever used, so simplify the meaning of fill accordingly. There's no need to special case the case that there are no unused bits, the masking/filling is a noop. ok jsing
* Add a comment so I don't forget to think about input validationtb2021-12-281-1/+3
| | | | in make_IPAddressFamily()
* Convert make_IPAddressFamily to CBS/CBBtb2021-12-281-13/+26
| | | | | | | | | | | | | | | The IPAddrBlocks type, which represents the IPAddrBlocks extension, should have exactly one IPAddressFamily per AFI+SAFI combination to be delegated. make_IPAddressFamily() first builds up a search key from the afi and safi arguments and then looks for an existing IPAddressFamily with that key in the IPAddrBlocks that was passed in. It returns that if it finds it or allocates and adds a new one. This diff preserves the current behavior that the afi and *safi arguments are truncated to 2 and 1 bytes, respectively. This may change in the future. ok inoguchi jsing
* Remove two pointless NULL checks and allocationstb2021-12-281-7/+1
| | | | | | | The ASN.1 template for IPAddressFamily doesn't mark either of its two members as optional, so they are allocated by IPAddressFamily_new(). ok inoguchi jsing
* Check for trailing garbage in X509_addr_get_afi()tb2021-12-281-1/+5
| | | | | | | | | | | | Per RFC 3779 2.2.3.3, the addressFamily field contains the 2-byte AFI and an optional 1-byte SAFI. Nothing else. The optional SAFI is nowhere exposed in the API. It is used expliclty only for pretty printing. There are implicit uses in a few places, notably for sorting/comparing where trailing garbage would be erroneously taken into account. Erroring in this situation will let us avoid this in upcoming revisions. ok inoguchi jsing
* Convert X509v3_adr_get_afi() to CBStb2021-12-281-6/+21
| | | | | | | | | | | The manual byte bashing is performed more safely using this API which would have avoided the out-of-bounds read that this API had until a few years back. The API is somewhat strange in that it uses the reserved AFI 0 as an in-band error but it doesn't care about the reserved AFI 65535. ok inoguchi jsing
* zap doubled semicolontb2021-12-261-2/+2
|
* Fix some weird line wrapping and a minor KNF nittb2021-12-251-10/+6
|
* No need for assert.h in here.tb2021-12-251-2/+1
|
* drop a meaningless XXXtb2021-12-251-2/+1
|
* Use C99 initializers for v3_addr, v3_asid and v3_ct_scts[]tb2021-12-252-24/+30
| | | | | | as is done for most other X.509 v3 extension methods. discussed with jsing
* Undo commenting of OPENSSL_NO_RFC3779tb2021-12-241-4/+4
| | | | | | | | | | | The define implies that we have the RFC 3779 API and corresponding symbols publicly exposed. We don't do that since there are still concerns about its suitability and security. oss-fuzz has code depending on this define and this broke its build as tracked down by jsing. This commit gets us oss-fuzz builds back while keeping job happy since the extension pretty printing will continue to work. ok jsing
* Fix a typo in a comment and add some empty lines for readabilitytb2021-12-241-2/+6
|
* Fix some KNF issues in the RFC 3779 section that have bothered me fortb2021-12-241-54/+55
| | | | way too long.
* KNF nittb2021-12-241-2/+2
|
* Remove asserts from asid_validate_path_internal()tb2021-12-241-11/+22
| | | | | | | | | | | The first asserts ensure that things checked in the callers hold true. Turn them into error checks and set the error on the X509_STORE_CTX if it's present. Checking sk_value(..., i) with i < sk_num(...) isn't useful, particularly if that check is done via an assert. Turn one remaining assert into a NULL check. Finally, simplify the sk_num() checks in the callers. ok jsing