diff options
Diffstat (limited to 'crypto/x509')
-rw-r--r-- | crypto/x509/x509_lu.c | 56 | ||||
-rw-r--r-- | crypto/x509/x509_set.c | 3 | ||||
-rw-r--r-- | crypto/x509/x509_vfy.c | 3 | ||||
-rw-r--r-- | crypto/x509/x509cset.c | 3 | ||||
-rw-r--r-- | crypto/x509/x_crl.c | 6 | ||||
-rw-r--r-- | crypto/x509/x_req.c | 2 | ||||
-rw-r--r-- | crypto/x509/x_x509.c | 2 |
7 files changed, 48 insertions, 27 deletions
diff --git a/crypto/x509/x509_lu.c b/crypto/x509/x509_lu.c index b53ec48032..3b0daf1269 100644 --- a/crypto/x509/x509_lu.c +++ b/crypto/x509/x509_lu.c @@ -194,8 +194,13 @@ X509_STORE *X509_STORE_new(void) if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data)) goto err; + ret->lock = CRYPTO_THREAD_lock_new(); + if (ret->lock == NULL) + goto err; + ret->references = 1; return ret; + err: X509_VERIFY_PARAM_free(ret->param); sk_X509_OBJECT_free(ret->objs); @@ -228,7 +233,7 @@ void X509_STORE_free(X509_STORE *vfy) if (vfy == NULL) return; - i = CRYPTO_add(&vfy->references, -1, CRYPTO_LOCK_X509_STORE); + CRYPTO_atomic_add(&vfy->references, -1, &i, vfy->lock); REF_PRINT_COUNT("X509_STORE", vfy); if (i > 0) return; @@ -245,9 +250,22 @@ void X509_STORE_free(X509_STORE *vfy) CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, vfy, &vfy->ex_data); X509_VERIFY_PARAM_free(vfy->param); + CRYPTO_THREAD_lock_free(vfy->lock); OPENSSL_free(vfy); } +int X509_STORE_up_ref(X509_STORE *vfy) +{ + int i; + + if (CRYPTO_atomic_add(&vfy->references, 1, &i, vfy->lock) <= 0) + return 0; + + REF_PRINT_COUNT("X509_STORE", a); + REF_ASSERT_ISNT(i < 2); + return ((i > 1) ? 1 : 0); +} + X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m) { int i; @@ -284,9 +302,9 @@ int X509_STORE_get_by_subject(X509_STORE_CTX *vs, X509_LOOKUP_TYPE type, X509_OBJECT stmp, *tmp; int i, j; - CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_write_lock(ctx->lock); tmp = X509_OBJECT_retrieve_by_subject(ctx->objs, type, name); - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->lock); if (tmp == NULL || type == X509_LU_CRL) { for (i = vs->current_method; @@ -332,7 +350,7 @@ int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) obj->type = X509_LU_X509; obj->data.x509 = x; - CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_write_lock(ctx->lock); X509_OBJECT_up_ref_count(obj); @@ -345,7 +363,7 @@ int X509_STORE_add_cert(X509_STORE *ctx, X509 *x) } else sk_X509_OBJECT_push(ctx->objs, obj); - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->lock); return ret; } @@ -365,7 +383,7 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) obj->type = X509_LU_CRL; obj->data.crl = x; - CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_write_lock(ctx->lock); X509_OBJECT_up_ref_count(obj); @@ -377,7 +395,7 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) } else sk_X509_OBJECT_push(ctx->objs, obj); - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->lock); return ret; } @@ -474,7 +492,7 @@ STACK_OF(X509) *X509_STORE_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) X509 *x; X509_OBJECT *obj; sk = sk_X509_new_null(); - CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_write_lock(ctx->ctx->lock); idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt); if (idx < 0) { /* @@ -482,16 +500,16 @@ STACK_OF(X509) *X509_STORE_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) * cache */ X509_OBJECT xobj; - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->ctx->lock); if (!X509_STORE_get_by_subject(ctx, X509_LU_X509, nm, &xobj)) { sk_X509_free(sk); return NULL; } X509_OBJECT_free_contents(&xobj); - CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_write_lock(ctx->ctx->lock); idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_X509, nm, &cnt); if (idx < 0) { - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->ctx->lock); sk_X509_free(sk); return NULL; } @@ -501,13 +519,13 @@ STACK_OF(X509) *X509_STORE_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) x = obj->data.x509; X509_up_ref(x); if (!sk_X509_push(sk, x)) { - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->ctx->lock); X509_free(x); sk_X509_pop_free(sk, X509_free); return NULL; } } - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->ctx->lock); return sk; } @@ -528,10 +546,10 @@ STACK_OF(X509_CRL) *X509_STORE_get1_crls(X509_STORE_CTX *ctx, X509_NAME *nm) return NULL; } X509_OBJECT_free_contents(&xobj); - CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_write_lock(ctx->ctx->lock); idx = x509_object_idx_cnt(ctx->ctx->objs, X509_LU_CRL, nm, &cnt); if (idx < 0) { - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->ctx->lock); sk_X509_CRL_free(sk); return NULL; } @@ -541,13 +559,13 @@ STACK_OF(X509_CRL) *X509_STORE_get1_crls(X509_STORE_CTX *ctx, X509_NAME *nm) x = obj->data.crl; X509_CRL_up_ref(x); if (!sk_X509_CRL_push(sk, x)) { - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->ctx->lock); X509_CRL_free(x); sk_X509_CRL_pop_free(sk, X509_CRL_free); return NULL; } } - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->ctx->lock); return sk; } @@ -621,7 +639,7 @@ int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x) /* Else find index of first cert accepted by 'check_issued' */ ret = 0; - CRYPTO_w_lock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_write_lock(ctx->ctx->lock); idx = X509_OBJECT_idx_by_subject(ctx->ctx->objs, X509_LU_X509, xn); if (idx != -1) { /* should be true as we've had at least one * match */ @@ -648,7 +666,7 @@ int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x) } } } - CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); + CRYPTO_THREAD_unlock(ctx->ctx->lock); if (*issuer) X509_up_ref(*issuer); return ret; diff --git a/crypto/x509/x509_set.c b/crypto/x509/x509_set.c index 9330a544bd..360ead87d3 100644 --- a/crypto/x509/x509_set.c +++ b/crypto/x509/x509_set.c @@ -148,7 +148,8 @@ int X509_set_pubkey(X509 *x, EVP_PKEY *pkey) void X509_up_ref(X509 *x) { - CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); + int i; + CRYPTO_atomic_add(&x->references, 1, &i, x->lock); } long X509_get_version(X509 *x) diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c index ae07f37f36..e2b1b9654b 100644 --- a/crypto/x509/x509_vfy.c +++ b/crypto/x509/x509_vfy.c @@ -2160,8 +2160,9 @@ X509_STORE_CTX *X509_STORE_CTX_new(void) void X509_STORE_CTX_free(X509_STORE_CTX *ctx) { - if (!ctx) + if (ctx == NULL) return; + X509_STORE_CTX_cleanup(ctx); OPENSSL_free(ctx); } diff --git a/crypto/x509/x509cset.c b/crypto/x509/x509cset.c index bc14374d06..ab5f192a15 100644 --- a/crypto/x509/x509cset.c +++ b/crypto/x509/x509cset.c @@ -134,7 +134,8 @@ int X509_CRL_sort(X509_CRL *c) void X509_CRL_up_ref(X509_CRL *crl) { - CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509_CRL); + int i; + CRYPTO_atomic_add(&crl->references, 1, &i, crl->lock); } long X509_CRL_get_version(X509_CRL *crl) diff --git a/crypto/x509/x_crl.c b/crypto/x509/x_crl.c index af4927109c..0be84057ab 100644 --- a/crypto/x509/x_crl.c +++ b/crypto/x509/x_crl.c @@ -329,7 +329,7 @@ static void setup_idp(X509_CRL *crl, ISSUING_DIST_POINT *idp) DIST_POINT_set_dpname(idp->distpoint, X509_CRL_get_issuer(crl)); } -ASN1_SEQUENCE_ref(X509_CRL, crl_cb, CRYPTO_LOCK_X509_CRL) = { +ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = { ASN1_EMBED(X509_CRL, crl, X509_CRL_INFO), ASN1_EMBED(X509_CRL, sig_alg, X509_ALGOR), ASN1_EMBED(X509_CRL, signature, ASN1_BIT_STRING) @@ -435,9 +435,9 @@ static int def_crl_lookup(X509_CRL *crl, * under a lock to avoid race condition. */ if (!sk_X509_REVOKED_is_sorted(crl->crl.revoked)) { - CRYPTO_w_lock(CRYPTO_LOCK_X509_CRL); + CRYPTO_THREAD_write_lock(crl->lock); sk_X509_REVOKED_sort(crl->crl.revoked); - CRYPTO_w_unlock(CRYPTO_LOCK_X509_CRL); + CRYPTO_THREAD_unlock(crl->lock); } idx = sk_X509_REVOKED_find(crl->crl.revoked, &rtmp); if (idx < 0) diff --git a/crypto/x509/x_req.c b/crypto/x509/x_req.c index c1caf09c67..2fdf015003 100644 --- a/crypto/x509/x_req.c +++ b/crypto/x509/x_req.c @@ -105,7 +105,7 @@ ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = { IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO) -ASN1_SEQUENCE_ref(X509_REQ, 0, CRYPTO_LOCK_X509_REQ) = { +ASN1_SEQUENCE_ref(X509_REQ, 0) = { ASN1_EMBED(X509_REQ, req_info, X509_REQ_INFO), ASN1_EMBED(X509_REQ, sig_alg, X509_ALGOR), ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING) diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c index 09004ef604..34639555ba 100644 --- a/crypto/x509/x_x509.c +++ b/crypto/x509/x_x509.c @@ -123,7 +123,7 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, } -ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = { +ASN1_SEQUENCE_ref(X509, x509_cb) = { ASN1_EMBED(X509, cert_info, X509_CINF), ASN1_EMBED(X509, sig_alg, X509_ALGOR), ASN1_EMBED(X509, signature, ASN1_BIT_STRING) |