summaryrefslogtreecommitdiff
path: root/lib/libcrypto/x509/x509_addr.c
AgeCommit message (Collapse)Author
2022-11-26Make internal header file names consistentTheo Buehler
Libcrypto currently has a mess of *_lcl.h, *_locl.h, and *_local.h names used for internal headers. Move all these headers we inherited from OpenSSL to *_local.h, reserving the name *_internal.h for our own code. Similarly, move dtls_locl.h and ssl_locl.h to dtls_local and ssl_local.h. constant_time_locl.h is moved to constant_time.h since it's special. Adjust all .c files in libcrypto, libssl and regress. The diff is mechanical with the exception of tls13_quic.c, where #include <ssl_locl.h> was fixed manually. discussed with jsing, no objection bcook
2022-11-14Hide public symbols in libcrypto/x509 .c filesBob Beck
ok tb@
2022-05-25Remove an unnecessary XXX comment. The suggested check is part ofTheo Buehler
extract_min_max().
2022-05-17Rewrite make_addressRange() using CBSTheo Buehler
Factor the trimming of the end and the counting of unused bits into helper functions and reuse an ASN.1 bit string API to set the unused bits and the ASN1_STRING_FLAG_BITS_SET. With a couple of explanatory comments it becomes much clearer what the code is actually doing and why. ok jsing
2022-05-17Simplify make_addressPrefix()Theo Buehler
In order to set the BIT STRING containing an address prefix, use existing helper functions from the ASN.1 code instead of redoing everything by hand. Make the function single exit and rename a few variables to make it clearer what is being done. ok jsing
2022-04-21Clarify comments at the start of {asid,addr}_validate_path_internal()Theo Buehler
Requested by jsing
2022-04-21Avoid expensive RFC 3779 checks during cert verificationTheo Buehler
X509v3_{addr,asid}_is_canonical() check that the ipAddrBlocks and autonomousSysIds extension conform to RFC 3779. These checks are not cheap. Certs containing non-conformant extensions should not be considered valid, so mark them with EXFLAG_INVALID while caching the extension information in x509v3_cache_extensions(). This way the expensive check while walking the chains during X509_verify_cert() is replaced with a cheap check of the extension flags. This avoids a lot of superfluous work when validating numerous certs with similar chains against the same roots as is done in rpki-client. Issue noticed and fix suggested by claudio ok claudio inoguchi jsing
2022-03-16Make gcc 4 happier about x509_addr.cTheo Buehler
gcc 4 on sparc64 issues a few 'warning: value computed is not used'. There are two cases: sk_set_cmp_function() returns the old comparison function of the stack which we don't care about. The one warning about an sk_delete() is about a return value that we know already and which we will free a few lines down. ok inoguchi miod
2022-02-04Remove a strange inheritance check from addr_validate_path_internal()Theo Buehler
The trust anchor can't inherit, but the code says that it can inherit just not if the leaf tries to inherit from that. This makes no sense and doesn't match what is done on the asid side. ok jsing
2022-01-06minor tweaks, no code changeTheo Buehler
Adjust a comment to reality, zap a stray empty line and fix whitespace before comment after #endif
2022-01-05Unindent a few lines of code and avoid shadowed variables.Theo Buehler
2022-01-05Rename {c,p}_{min,max} into {child,parent}_{min,max}Theo Buehler
2022-01-05Two minor KNF tweaksTheo Buehler
2022-01-05Use child_aor and parent_aor instead of aorc and aorpTheo Buehler
suggested by jsing
2022-01-05Rename fp and fc into parent_af and child_af for readability.Theo Buehler
suggested by jsing
2022-01-05Globally rename all IPAddressFamily *f into af since this is slightlyTheo Buehler
more readable. Repeated complaints by jsing
2022-01-05Add a helper function to turn unchecked (but sound) use ofTheo Buehler
sk_find + sk_value into something easier to follow and swallow. ok inoguchi jsing
2022-01-05Hoist IPAddressFamily_cmp() to the other IPAddressFamily functions.Theo Buehler
ok inoguchi jsing
2022-01-05Call x a cert for readability.Theo Buehler
2022-01-05Now that i is free, rename j to i for use as loop variable inTheo Buehler
various loops in addr_validate_path_internal().
2022-01-05In addr_validate_path_internal() rename i to depth because that'sTheo Buehler
what it is.
2022-01-05Turn the validation_err() macro into a functionTheo Buehler
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
2022-01-05Move variable declarations in X509v3_addr_canonize() to the top ofTheo Buehler
the function and unindent some code. ok inoguchi jsing
2022-01-05Remove a bogus memcmp in range_should_be_prefix()Theo Buehler
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
2022-01-05Polish X509v3_addr_subset() a bitTheo Buehler
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
2022-01-05Readability tweaks in addr_contains()Theo Buehler
Assign to local variables to avoid ugly line wrapping. ok inoguchi jsing
2022-01-05Fix a bug in addr_contains() introduced in OpenSSL commit be71c372Theo Buehler
by returning 0 instead of -1 on extract_min_max() failure. Callers would interpret -1 as success of addr_contains(). ok inoguchi jsing
2022-01-04Readability tweaks in the print helper i2r_IPAddressOrRanges.Theo Buehler
Assign repeated nested expressions to local variables and avoid some awkward line wrapping.
2022-01-04Consistently name variables with a _len suffix instead of mixingTheo Buehler
things like prefixlen, afi_length, etc. suggested by jsing
2022-01-04Only check the parent to be canonical once we know it is non-NULL.Theo Buehler
suggested by jsing during review
2022-01-04Refactor extract_min_max()Theo Buehler
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
2022-01-04Remove checks that are duplicated in extract_min_max()Theo Buehler
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
2022-01-04Make X509v3_addr_get_range() readable.Theo Buehler
Instead of checking everything in a single if statement, group the checks according to their purposes. ok inoguchi jsing
2022-01-04Add a length check to make_addressPrefix()Theo Buehler
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
2022-01-04Remove some dead codeTheo Buehler
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
2022-01-04Drop a pointless NULL checkTheo Buehler
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
2022-01-04First pass over x509_addr_validate_path()Theo Buehler
Replace reaching into the structs with IPAddressFamily accessors and add a few comments that explain what the code is actually doing. ok inoguchi jsing
2022-01-04Refactor IPAddressFamily accessorsTheo Buehler
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
2021-12-28Fix typo in commentTheo Buehler
2021-12-28Use lowercase letters for hexadecimal constants, as both jsing and ITheo Buehler
prefer this.
2021-12-28Rewrite X509v3_addr_canonize() with new accessorsTheo Buehler
This is again a straightforward conversion and leads to something which matches our usual style more. ok jsing
2021-12-28Validate AFIs before sorting in X509v3_adr_canonize()Theo Buehler
Again, we're dealing with necessarily not fully validated data here, so a check up front seems prudent. ok jsing
2021-12-28Rewrite/simplify X509v3_addr_is_canonical()Theo Buehler
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
2021-12-28Check AFI/SAFI before comparing them in X509v3_addr_is_canonical()Theo Buehler
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
2021-12-28Make IPAddressFamily_cmp() more pleasing on the eyeTheo Buehler
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
2021-12-28Style improvements in X509v3_addr_add_range()Theo Buehler
ok jsing
2021-12-28Style improvements in X509v3_addr_add_prefix()Theo Buehler
ok jsing
2021-12-28Another small readability tweak in X509v3_addr_inherits()Theo Buehler
Declare IPAddressFamily before using it.
2021-12-28Use an accessor in X509v3_addr_inherits()Theo Buehler
2021-12-28Add a comment to i2r_IPAddrBlocks that we may want/have to deal withTheo Buehler
unknown address family types. Pointed out by jsing during review.