summaryrefslogtreecommitdiff
path: root/lib/libcrypto
AgeCommit message (Collapse)Author
2024-01-14Tidy a few more includes in cms/Theo Buehler
2024-01-13Prepare for removing most of the X509_TRUST APITheo Buehler
X509_check_trust() is of course used by the verifier. Unfortunately M2Crypto exposes it. The only other part of the X509_TRUST API that are still needed are the X509_TRUST_* macros in x509.h, as they are used via *_set_trust and indirectly via the purpose stuff. The rest will be removed. X509_TRUST_add() was defanged recently, in particular it no longer hangs strdup()'ed strings off the global struct. Nothing ever cleaned these up. TRUST_cleanup() attempted to do so, but since it checked the dynamic/dynamic strings flags in the wrong order, that cleanup call ended up doing nothing, so that code was removed at some point. As a consequence, the struct can now be made const. Use a CTASSERT() to ensure size assumptions on X509_TRUST_COUNT, X509_TRUST_MAX, and X509_TRUST_MIN hold true. Remove the global variable underlying X509_TRUST_set_default()'s functionality and move its accessor down to all the other functions that will be deleted. Inline a few things in X509_check_trust(), so we can excise the internals of X509_TRUST_get0(), X509_TRUST_get_by_id(). Since the default trust function can no longer be changed, call obj_trust() directly. ok jsing
2024-01-13Remove check{,obj_cleanup}_defer documentationTheo Buehler
Both check_defer() and the global variable obj_cleanup_defer were removed from the public API two years ago. Now they were removed from the internals as well, simplifying the cleanup process greatly. We no longer need them to have a chance to understand the cleanup process. Also remove references to EVP_cleanup() since this has long been deprecated and now it doesn't clean up things anymore.
2024-01-13Remove calls to OpenSSL_add_all_{ciphers,digests}()Theo Buehler
2024-01-13Move errno.h inclusion where it belongsTheo Buehler
2024-01-13Clean up EVP_MD_CTX_init() usage in ASN1_item_sign()joshua
ok tb@
2024-01-13Prepare to remove the EVP_PKEY_meth_* APITheo Buehler
After removing the last caller of EVP_PKEY_meth_find() from libssl, none of these is used. And with EVP_PKEY_meth_new() gone, there will no longer be a way to get your hands onto an EVP_PKEY_METHOD that is writable, so none of the silent failures (because they're void functions) should matter in the few weeks until we bump. ok jsing
2024-01-13The OBJ_NAME API joins the party in evp_names.cTheo Buehler
... and another file without license disappears.
2024-01-13Move EVP_add_{cipher,digest}() to the trashcanTheo Buehler
They will await their removal in the next major bump.
2024-01-13Open a garbage bin at the bottom of evp_names.cTheo Buehler
First to move is EVP_cleanup(), which should probably be moved to an evp_lib.c if such a file is reinstated.
2024-01-13Remove obj_cleanup_deferTheo Buehler
With check_defer() gone, this is never set to anything but 0, so the two conditional branches it is still involved in are dead code.
2024-01-13Garbage collect check_defer()Theo Buehler
This was a mechanism to ensure that OBJ_cleanup() doesn't remove the ASN1_OBJECT associated with a custom cipher or digest (that was added with EVP_add_{cipher,digest}(), while the latter is still referenced in the OBJ_NAME table. It had the effect that OBJ_cleanup() wasn't actually called ever from OPENSSL_cleanup() (it is only called if you load the OID conf module). Oh, and of course it was once part of the public API. I fixed that two years ago, almost exactly to the day. Still mentioned in OBJ_create.3.
2024-01-13Neuter EVP_add_{cipher,digest}()Theo Buehler
This makes them noops. They are used in the wild for adding ciphers that are always added by the library init code. This is a historic leftover. This removes the last (and only ever) calls to check_defer(). ok jsing
2024-01-13Remove most of EVP_add_{cipher,digest}() internalsTheo Buehler
OBJ_NAME_add() is a noop now, so remove all calls and simplify the remainder of these two functions a bit. Intermediate step to a larger diff that was ok jsing
2024-01-13Remove OBJ_NAME_cleanup() calls from EVP_cleanup()Theo Buehler
This is a noop now, so no need to call it.
2024-01-13Remove the guts of the OBJ_NAME APITheo Buehler
With one exception, none of this is used anymore. All of it will be removed in the next major bump. The exception is OBJ_NAME_add(). scurity/xca ran into issues with their cert renewal logic because RSA certs had a way of mapping the signature algorithms to a hash, but a similar mechanism wasn't available for ECDSA certs. So xca uses EVP_add_digest_alias() to have corresponding aliases for ECDSA. This is a macro wrapping OBJ_NAME_add(). xca now has better logic using the more appropriate OBJ_find_sigid_algs() (which wasn't available back then). We will still add the alias entries that xca still adds ourselves to make sure there are no unexpected side effects. They make sense anyway. The diff will hopefully land in a few days. If your life depends on ECDSA cert renewal in xca please hold off on updating to a new snap. ok jsing
2024-01-13Stub out {OpenSSL,OPENSSL}_add*Theo Buehler
These serve no purpose anymore (and really haven't for many years) but will have to be kept since there's a number of software that still uses them because many years ago they had to. Relocate the stubs to crypto_init.c since library initialization's what they were there for. ok jsing
2024-01-13Reimplement EVP_get_{cipher,digest}byname()Theo Buehler
Instead of a hashtable lookup do a bsearch() over the static table. This needs about the same number of strcmp and is a lot simpler. ok jsing
2024-01-13Reimplement {EVP_CIPHER,EVP_MD,OBJ_NAME}_do_all{,_sorted}(3)Theo Buehler
This implements the do_all API by simple loops over the tables of digests and ciphers. Since some ciphers are only available on some platforms, we need to skip them if necessary. We use loops in each of the functions rather the convoluted way of reducing some of the loops to others. Since the tables are sorted, as ensured by regress, both do_all() and do_all_sorted() walk the lists in order. In particular, we no longer need to allocate to be able to sort hash tables by name on the fly in a void function that may end up doing nothing because allocation failed. We still need to do an unchecked OPENSSL_init_crypto() call. But that's what prayer and clean living are there for (as beck put it). The OBJ_NAME API is completely misnamed. It has little to do with objects and a lot to do with EVP. Therefore we implement what will remain from its saner replacement in the evp directory, i.e., evp_names.c. ok jsing
2024-01-13Add a table of digest names, digests and aliasesTheo Buehler
This is the corresponding commit for digests and their aliases. It only adds a table to be used in upcoming commits. What was said about ciphers applies mutatis mutandis to digests. ok jsing
2024-01-13Add a table of cipher names, ciphers and aliasesTheo Buehler
This arranges the data provided by dynamic library initialization in a static table and will help avoid gross code with missing error checking and other defects on every use of the library. This table isn't pretty due to various naming inconsistecies accumulated over the decades. It will significantly simplify the implementation of API such as EVP_get_cipherbyname() and EVP_CIPHER_do_all(). All the table does is map strings to ciphers, typically used on the openssl(1) command line or in code it's the mechanism that underlies the map from NID_chacha20 to the data returned by EVP_chacha20(). It's of course more complicated because it just had to be stupid. This is one of the places where the use of bsearch() is justified. The price to pay for the simplification is that adding custom aliases and custom ciphers to this table will no longer be supported. It is one significant user of the LHASH madness. That's just another piece of the awful "toolkit aspect"-guided misdesign that contributes to making this codebase so terrible. A corresponding table for the digests will be added in the next commit. ok jsing
2024-01-12Remove X509_STORE_CTX_purpose_inherit(3) documentationTheo Buehler
This abomination of an API will be removed. Remove the hairy details of its internals and make the documentation of X509_STORE_CTX_set_trust(3) and X509_STORE_CTX_set_purpose(3) independent of it. Neither of these two remaining APIs can be recommended. Once set, trust and purpose are sticky. Setting the trust to a different (valid) value will indicate success but leave the value unchanged. I suppose it means the new trust value was successfully ignored. Also, setting the trust to X509_TRUST_DEFAULT can succeed or fail depending on which OpenSSL derivative you use. Setting the purpose will also set the trust (unless it is already set). Setting some purposes may or may not fail depending on the OpenSSL lib. The only way you have a chance of knowing what will be set is by calling only one of these functions directly after X509_STORE_CTX_init(). This isn't really safe either because in some versions the user can override the values stored in a global table by writing directly to it. The actual contributions here are rather minimal. State more explicitly that 0 is invalid (but results in success being returned), document the error values to be accurate across implementations and call out some of the nonsense in a CAVEATS section. Many thanks to schwarze for the very helpful review with lots of input. ok schwarze
2024-01-10X509_TRUST: tidy up includesTheo Buehler
2024-01-10X509_TRUST: group together all trust_*() functionsTheo Buehler
Now they are next to the trstandard[] table and listed in the order they appear in the table.
2024-01-10X509_TRUST: hoist trust_compat() to the other end of the fileTheo Buehler
2024-01-10X509_TRUST: start shuffling some code aroundTheo Buehler
Hoist obj_trust() to the top and move the static default_trust() next to its setter.
2024-01-10Rework X509_STORE_CTX_set_{purpose,trust}()Theo Buehler
Split the two codepaths in x509_vfy_purpose_inherit() into its two callers. What remains is gross, but at least a reader has a chance of following all this nonsense without leaving a significant amount of hair behind. In short, purpose and trust are only overridden if they're not already set. Otherwise silently ignore valid purpose and trust identifiers that were passed in and succeed. Error on almost all invalid trust or purpose ids, except 0, because... well... who knows, really? ok jsing
2024-01-10Inline rsa_is_pss() and rsa_pkey_is_pss()Theo Buehler
It's more explicit and not that much longer. ok jsing
2024-01-10Drop an unnecessary castTheo Buehler
from jsing
2024-01-10Fix print_fp()Theo Buehler
The callback-based printing needs to die. But first BIO_set() will die. We have a FILE *. We have fprintf(). No need to use a static BIO to dump error codes to said stream. This basically undoes an unrelated change of "Move crpytlib.h prior bio.h" from 19 years ago (OpenSSL 25a66ee3). Except we don't cast and check len. ok jsing (who had a nearly identical diff)
2024-01-09Fix copy-paste error that broke openssl-ruby and openssl regressTheo Buehler
Noticed by anton
2024-01-08Disable X509_STORE_CTX_purpose_inherit()Theo Buehler
Nothing uses this function, except two internal callers. So split its guts temporarily into a helper function and disable the gross general case. The internal helper can be simplified by observing that def_purpose == 0: Overriding 0 by 0 doesn't do anything, so drop that bit. Rename ptmp into purp, and inline X509_PURPOSE_get_by_id(), i.e., make appropriate checks and subtract X509_PURPOSE_MIN. The fallback to X509_PURPOSE_get_by_id(0) will always fail since X509_PURPOSE_MIN == 1. So ditch that call. In particular, X509_STORE_CTX_set_purpose(ctx, X509_PURPOSE_ANY) fails in current because of this. That's nonsense. So remove the purp->trust == X509_TRUST_DEFAULT check as only change of behavior. This matches what OpenSSL do nowadays. They now set def_purpose = purpose if purpose != 0 and def_purpose == 0, so in all real-world uses of this function they will just fetch the same purpose again and do not check for default trust the second time around. Finally, X509_TRUST_get_by_id() is only used to ensure that a non-zero (or overridden) trust is between X509_TRUST_MIN and X509_TRUST_MAX. So expand that into its explicit form. ok jsing
2024-01-08Inline X509_{TRUST,PUPROSE}_set() in their only callersTheo Buehler
They are now unused and will join the exodus to the attic in the next bump. ok jsing
2024-01-08const correct aesni_{128,256}_cbc_hmac_sha1_cipherTheo Buehler
2024-01-08Fix logic error (&& -> ||)Theo Buehler
CID 477172
2024-01-07Garbage collect call to X509_TRUST_cleanup()Theo Buehler
Since x509_trs.c r1.33, this is a noop.
2024-01-07Minor cleanup in X509_STORE_CTX_purpose_inherit()Theo Buehler
Make a few checks against 0 explicit to reduce noise in an upcoming diff and tiny KNF tweaks.
2024-01-07purpose/trust: Improve comments about COUNT/MAX confusionTheo Buehler
2024-01-07const-correct r4_hmac_md5_cipherTheo Buehler
2024-01-07Convert the remaining legacy ciphers to C99 initializersTheo Buehler
No change in the generated aarch64 assembly apart from line number changes. ok jsing
2024-01-07Improve EVP_CIPHER_{get,set}_asn1_iv()Theo Buehler
Use iv_len for the variables storing the IV length, formerly l and j. Remove use of the unnecessary variable i and unindent the whole mess. Some return values are fishy. That will be addressed in subsequent commits. ok jsing
2024-01-07Remove X509_TRUST extensibilityTheo Buehler
This is pretty much identical to the X509_PURPOSE case: remove the stack used for extending and overriding the trust table and make X509_TRUST_add() always fail. Simplify some other bits accordingly. ok jsing
2024-01-06Zap some more CRL method thingsTheo Buehler
2024-01-06Remove X509_PURPOSE_cleanup() call in OPENSSL_cleanup()Theo Buehler
Since x509_purp.c r1.34 this is a noop since there is nothing to clean up anymore. Remove the last caller.
2024-01-06Remove X509_CRL_METHOD internalsTheo Buehler
Another complication of dubious value that nobody's ever used. crl_init(), crl_free() and the meth_data are dead weight, as are their accessors. Inline def_crl_verify() in X509_CRL_verify() so that the latter becomes the trivial wrapper of ASN1_item_verify() that one would expect it to be. It is quite unclear what kind of customization would make sense here... def_crl_lookup() is renamed into crl_lookup() and its two callers, X509_CRL_lookup_by_{serial,cert}(), are moved below it so that we don't need a prototype. ok jsing
2024-01-06Remove X509_PURPOSE extensibilityTheo Buehler
Another bit of global state without lock protection. The by now familiar complications of a stack to make this user configurable, which, of course, no one ever did. The table is not currently const, and the API exposes its entries directly, so anyone can modify it. This fits very well with the safety guarantees of Rust's 'static lifetime, which is how rust-openssl exposes it (for no good reason). Remove the stack and make the X509_PURPOSE_add() API always fail. Simplify the other bits accordingly. In addition, this API inflicts the charming difference between purpose identifiers and purpose indexes (the former minus one) onto the user. Neither of the two obvious solutions to avoid this trap seems to have crossed the implementer's mind. ok jsing
2024-01-05EVP_PKEY_asn1_find_str() tweaksTheo Buehler
Switch i to a size_t and improve a flag check. Part of an earlier diff that was ok jsing but were lost when I reworked the diff.
2024-01-05evp_key.c: Remove more unnecessary parenthesesTheo Buehler
2024-01-05Minor tweaks in EVP_read_pw_string_min()Theo Buehler
Remove unnecessary parentheses and use a better place to break an overlong line.
2024-01-05Plug a leak in EVP_read_pw_string_min()Theo Buehler
Use an error exit that frees the ui in case the UI_add_* fail. Also add a few empty lines for readability. ok joshua