From 1fd1843385f46c67dcd9ba798ea641e06e10454f Mon Sep 17 00:00:00 2001 From: WillChilds-Klein Date: Wed, 21 Feb 2024 22:31:00 +0000 Subject: [PATCH] Add misc. x509 un/lock and set1 functions --- crypto/x509/x509_lu.c | 28 ++++++++++++++++++++++++++++ include/openssl/x509.h | 4 ++++ 2 files changed, 32 insertions(+) diff --git a/crypto/x509/x509_lu.c b/crypto/x509/x509_lu.c index cb25ae71c69..13194774162 100644 --- a/crypto/x509/x509_lu.c +++ b/crypto/x509/x509_lu.c @@ -200,6 +200,16 @@ X509_STORE *X509_STORE_new(void) { return NULL; } +int X509_STORE_lock(X509_STORE *v) { + CRYPTO_MUTEX_lock_write(&v->objs_lock); + return 1; +} + +int X509_STORE_unlock(X509_STORE *v) { + CRYPTO_MUTEX_unlock_write(&v->objs_lock); + return 1; +} + int X509_STORE_up_ref(X509_STORE *store) { CRYPTO_refcount_inc(&store->references); return 1; @@ -410,6 +420,24 @@ X509_CRL *X509_OBJECT_get0_X509_CRL(const X509_OBJECT *a) { return a->data.crl; } +int X509_OBJECT_set1_X509(X509_OBJECT *a, X509 *obj) { + if (a == NULL || !X509_up_ref(obj)) + return 0; + + a->type = X509_LU_X509; + a->data.x509 = obj; + return 1; +} + +int X509_OBJECT_set1_X509_CRL(X509_OBJECT *a, X509_CRL *obj) { + if (a == NULL || !X509_CRL_up_ref(obj)) + return 0; + + a->type = X509_LU_CRL; + a->data.crl = obj; + return 1; +} + static int x509_object_idx_cnt(STACK_OF(X509_OBJECT) *h, int type, X509_NAME *name, int *pnmatch) { X509_OBJECT stmp; diff --git a/include/openssl/x509.h b/include/openssl/x509.h index 5068f0aef79..b1558b53f6e 100644 --- a/include/openssl/x509.h +++ b/include/openssl/x509.h @@ -2800,7 +2800,11 @@ OPENSSL_EXPORT int X509_OBJECT_get_type(const X509_OBJECT *a); OPENSSL_EXPORT X509 *X509_OBJECT_get0_X509(const X509_OBJECT *a); // X509_OBJECT_get0_X509_CRL returns the |X509_CRL| associated with |a| OPENSSL_EXPORT X509_CRL *X509_OBJECT_get0_X509_CRL(const X509_OBJECT *a); +int X509_OBJECT_set1_X509(X509_OBJECT *a, X509 *obj); +int X509_OBJECT_set1_X509_CRL(X509_OBJECT *a, X509_CRL *obj); OPENSSL_EXPORT X509_STORE *X509_STORE_new(void); +OPENSSL_EXPORT int X509_STORE_lock(X509_STORE *v); +OPENSSL_EXPORT int X509_STORE_unlock(X509_STORE *v); OPENSSL_EXPORT int X509_STORE_up_ref(X509_STORE *store); OPENSSL_EXPORT void X509_STORE_free(X509_STORE *v);