summaryrefslogtreecommitdiff
path: root/lib/libcrypto/x509/x509_lu.c
AgeCommit message (Collapse)Author
2021-11-19As long as X509_OBJECT_free_contents(3) is a public API function,Ingo Schwarze
make sure it fully re-initializes the object rather than leaving behind a stale pointer and a stale type in the object. The old behaviour was dangerous because X509_OBJECT_get_type(3) would then return the stale type to the user and one of X509_OBJECT_get0_X509(3) or X509_OBJECT_get0_X509_CRL(3) would then return the stale pointer to the user, provoking a use-after-free bug in the application program. Having these functions return X509_LU_NONE and NULL is better because those are the documented return values for these functions when the object is empty. OK tb@
2021-11-07In X509_STORE_CTX, rename the X509_STORE store rather than ctx.Theo Buehler
ok gnezdo jsing
2021-11-06Start cleaning up X509_STORE_get1_issuer()Theo Buehler
Get rid of the last X509_OBJECT_free_contents() call by moving the object from the stack to the heap. I deliberately kept the obj variable to keep obj and pobj separate. Rename the out parameter from issuer to out_issuer to ensure that we only assign it when we have acquired a reference that we can return. Add a new X509 *issuer. In the first part of the function, acquire an extra reference before check_issuer/check_time. In the second part of the function, acquire a reference inside the lock to avoid a race. Deal with ret only in one place. ok jsing
2021-11-06In X509_STORE_get1_issuer() do not call the verify callback fromTheo Buehler
x509_check_cert_time(). Matches a change made in OpenSSL 70dd3c65. ok jsing
2021-11-06Refactor X509_STORE_get1_certs()Theo Buehler
Split the retrieval of the certs in the store's cache that match the desired subject into a separate function. This greatly simplifies locking, error handling and the flow of the function. with/ok jsing
2021-11-05First pass of streamlining X509_STORE_get1_{certs,crls}()Theo Buehler
These functions are quite messy. On top of the tricky logic querying the cache, then refreshing the cache (unconditionally or not), then querying again, then extracting a list of certs/crls and bumping their refcounts, things are intermixed with locking and needlessly early allocations that then need to be cleaned up again. Use X509_STORE_CTX_get_obj_by_subject() to avoid using an object on the stack and defer allocation of the returned stack of certs to later. Flatten the logic a bit and prepare for further refactoring. ok jsing
2021-11-05Trade an abort() neutered by a comment for a blank line elsewhere.Theo Buehler
2021-11-05Clean up X509_STORE_add_{cert,crl}().Theo Buehler
Add a X509_STORE_add_object() function that adds an X509 object to the store and takes care of locking and cleaning up. This way we can set up an X509_OBJECT for both the cert and CRL case and hand over to the new function. There is one intentional change of behavior: if there is an attempt to add an object which is already present in the store, succeed instead of throwing an error. This makes sense and is also the OpenSSL behavior. As pointed out by jsing, this is a partial fix for the long standing GH issue #100 on libtls where connections would fail if the store contains duplicate certificates. Also: remove the internal X509_OBJECT_dec_ref_count(), which is no longer used. ok jsing
2021-11-05Unify variable names in X509_STORE_{free,up_ref,add_lookup}().Theo Buehler
simplify the flow of X509_add_lookup(). ok jsing
2021-11-05Rename the ret variable in X509_OBJECT_new() to obj..Theo Buehler
ok jsing
2021-11-05Garbage collect the unused skip member of X509_LOOKUP andTheo Buehler
the unused cache member of X509_STORE. ok jsing
2021-11-05Use calloc() to remove the need of silly zeroing of most members.Theo Buehler
Check for allocation failures and if one happens push an error on the stack and clean up using X509_STORE_free(). ok jsing
2021-11-05Streamline and shorten x509_object_cmp() a bit.Theo Buehler
ok jsing
2021-11-05Drop a bunch of unnecesary parentheses and unify the order in whichTheo Buehler
callbacks are called. ok jsing
2021-11-05Cleanup X509_LOOKUP_new()Theo Buehler
Switch from malloc() to calloc() and drop a bunch of initializations to 0. Call the returned object lu instead of the generic ret. ok jsing
2021-11-05Garbage collect xobj->data.{ptr,pkey}Theo Buehler
Both these are essentially unused. Remove the last use of data.ptr by initializing and copying the X509_OBJECT using memset() and struct assignment in X509_STORE_CTX_get_subject_by_name() and add a missing error check for X509_OBJECT_up_ref_count() while there. ok beck
2021-11-01In X509_STORE_CTX_get_obj_from_subject() rename X509_OBJECT fromTheo Buehler
the generic 'ret' to obj' in X509. Requested by jsing
2021-10-31Prepare to provide X509_STORE_CTX_get_obj_by_subject(), a wrapperTheo Buehler
around X509_STORE_get_by_subject() that eliminates the need of allocating an object on the heap by hand. ok beck inoguchi jsing
2021-10-31Switch various X509 API to use the new X509_LOOKUP_TYPE to matchTheo Buehler
OpenSSL's signatures. ok beck inoguchi jsing
2021-10-24Prepare to provide X509_OBJECT_{new,free}()Theo Buehler
ok beck inoguchi jsing
2021-10-21Simplify a return value check for X509_STORE_get_by_subject() nowTheo Buehler
that we know that it only returns 0 or 1. Eliminate the last uses of X509_LU_{FAIL,RETRY}. ok jsing
2021-10-21Sync parts of X509_STORE_get_by_subject() with OpenSSLTheo Buehler
Initialize stmp.type and stmp.data.ptr so that a user-defined lookup method need not take responsibility of initializing those. Get rid of current_method, which was never really used. Stop potentially returning a negative value since most callers assume Boolean return values already. In addition, garbage collect the pointless j variable. ok jsing
2021-10-06X509_STORE_CTX_init() allows the store to be NULL on init. Add checksClaudio Jeker
for a NULL ctx->ctx in the lookup functions using X509_STORE_CTX. This affects X509_STORE_get1_certs(), X509_STORE_get1_crls(), X509_STORE_CTX_get1_issuer() and X509_STORE_get_by_subject(). With this X509_verify_cert() no longer crashes with a NULL store. With and OK tb@
2018-08-24Make X509_OBJECT_up_ref_count return an int.Theo Buehler
Based on OpenSSL commit c5ebfcab713a82a1d46a51c8c2668c419425b387 tested in a bulk by sthen ok jsing
2018-05-18X509_LOOKUP_by_alias() now takes a 'const char str *' andTheo Buehler
X509_LOOKUP_by_fingerprint() 'const unsigned char *bytes'. tested in a bulk build by sthen ok jsing
2018-03-17Provide X509_STORE_get0_param()Theo Buehler
ok jsing
2018-03-17Provide X509_OBJECT_get_type(). Instead of the X509_LOOKUP_TYPE enumTheo Buehler
(which we don't have) it returns a plain int. ok jsing
2018-02-22Provide X509_STORE_get0_objects(), X509_STORE_get_ex_data() andJoel Sing
X509_STORE_set_ex_data().
2018-02-22Provide X509_OBJECT_get0_X509() and X509_OBJECT_get0_X509_CRL().Joel Sing
2018-02-22Provide X509_STORE_up_ref().Joel Sing
2017-01-29Send the function codes from the error functions to the bit bucket,Bob Beck
as was done earlier in libssl. Thanks inoguchi@ for noticing libssl had more reacharounds into this. ok jsing@ inoguchi@
2016-11-13Fix previous change to X509_STORE_add_{cert,crl} to not free the inputMiod Vallat
object in the error path - we don't own it.
2016-11-08Check for stack push failure, and correctly destroy the object we failedMiod Vallat
to push in that case. While there replace an inline version of X509_OBJECT_free_contents() by a call to said function. ok beck@
2015-04-25Don't ignore the reference count in X509_STORE_free.Doug Hogan
Based on this upstream commit: bff9ce4db38b297c72a6d84617d71ae2934450f7 which didn't make it into a release until 1.0.2. Thanks to william at 25thandclement dot com for reporting this! ok deraadt@ jsing@ beck@
2015-02-10Remove more IMPLEMENT_STACK_OF noops that have been hiding for the lastJoel Sing
15 years.
2014-09-26X509_STORE_new(): do not leak memory upon error.Miod Vallat
X509_STORE_get1_certs(), X509_STORE_get1_crls(): check the result of allocations. ok tedu@
2014-07-11When looking for the issuer of a certificate, if the current candidate isMiod Vallat
expired or not valid yet, continue looking; only return an expired certificate if no valid certificates have been found. OpenSSL PR #3359 via OpenSSL trunk.
2014-07-11Only import cryptlib.h in the four source files that actually need it.Joel Sing
Remove the openssl public includes from cryptlib.h and add a small number of includes into the source files that actually need them. While here, also sort/group/tidy the includes. ok beck@ miod@
2014-06-12tags as requested by miod and teduTheo de Raadt
2014-06-07malloc() result does not need a cast.Theo de Raadt
ok miod
2014-04-20KNF.Joel Sing
2014-04-18blunt force knfTed Unangst
2014-04-17fix some more leaks, mostly suggestions from miodJonathan Gray
ok miod@
2014-04-17fix some of the leaksJonathan Gray
ok miod@ looks good deraadt@
2014-04-17Change library to use intrinsic memory allocation functions instead ofBob Beck
OPENSSL_foo wrappers. This changes: OPENSSL_malloc->malloc OPENSSL_free->free OPENSSL_relloc->realloc OPENSSL_freeFunc->free
2012-10-13resolve conflictsDamien Miller
2010-10-01resolve conflicts, fix local changesDamien Miller
2008-09-06resolve conflictsDamien Miller
2002-05-15OpenSSL 0.9.7 stable 2002 05 08 mergeBob Beck
2000-12-15openssl-engine-0.9.6 mergeBob Beck