Skip to content

Commit

Permalink
fixup! x509_vfy.c and x509_lu.c: refactor find_issuer(), X509_STORE_C…
Browse files Browse the repository at this point in the history
…TX_get1_issuer(), etc.
  • Loading branch information
DDvO committed Nov 15, 2024
1 parent 1ebcc6c commit 205564f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
20 changes: 4 additions & 16 deletions crypto/x509/x509_lu.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,12 +651,10 @@ STACK_OF(X509) *X509_STORE_get1_all_certs(X509_STORE *store)

/*-
* Collect from |ctx->store| all certs with subject matching |nm|.
* Caller must free on ret == 1 the resulting list |*certs|.
* Caller must also free its entries if up_refs != 0.
* Returns NULL on internal/fatal error, empty stack if not found.
*/
STACK_OF(X509) *ossl_x509_store_ctx_get_certs(X509_STORE_CTX *ctx,
const X509_NAME *nm, int up_refs)
STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx,
const X509_NAME *nm)
{
int i, idx, cnt;
STACK_OF(X509) *sk = NULL;
Expand Down Expand Up @@ -693,12 +691,9 @@ STACK_OF(X509) *ossl_x509_store_ctx_get_certs(X509_STORE_CTX *ctx,
for (i = 0; i < cnt; i++, idx++) {
obj = sk_X509_OBJECT_value(store->objs, idx);
x = obj->data.x509;
if (!X509_add_cert(sk, x, up_refs ? X509_ADD_FLAG_UP_REF : 0)) {
if (!X509_add_cert(sk, x, X509_ADD_FLAG_UP_REF)) {
X509_STORE_unlock(store);
if (up_refs)
OSSL_STACK_OF_X509_free(sk);
else
sk_X509_free(sk);
OSSL_STACK_OF_X509_free(sk);
return NULL;
}
}
Expand All @@ -707,13 +702,6 @@ STACK_OF(X509) *ossl_x509_store_ctx_get_certs(X509_STORE_CTX *ctx,
return sk;
}

/* Returns NULL on internal/fatal error, empty stack if not found */
STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx,
const X509_NAME *nm)
{
return ossl_x509_store_ctx_get_certs(ctx, nm, 1 /* up_refs */);
}

/* Returns NULL on internal/fatal error, empty stack if not found */
STACK_OF(X509_CRL) *X509_STORE_CTX_get1_crls(const X509_STORE_CTX *ctx,
const X509_NAME *nm)
Expand Down
12 changes: 6 additions & 6 deletions crypto/x509/x509_vfy.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,16 +423,16 @@ static X509 *get0_best_issuer_sk(X509_STORE_CTX *ctx, int trusted,
*/
int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
{
const X509_NAME *xn = X509_get_issuer_name(x);
STACK_OF(X509) *certs = ossl_x509_store_ctx_get_certs(ctx, xn, 0);
STACK_OF(X509) *certs = X509_STORE_CTX_get1_certs(ctx, X509_get_issuer_name(x));
int ret = 0;

if (certs == NULL)
return -1;
*issuer = get0_best_issuer_sk(ctx, 1 /* trusted */, 0, certs, x);
sk_X509_free(certs);
if (*issuer == NULL)
return 0;
return X509_up_ref(*issuer) ? 1 : -1;
if (*issuer != NULL)
ret = X509_up_ref(*issuer) ? 1 : -1;
OSSL_STACK_OF_X509_free(certs);
return ret;
}

/* Check that the given certificate |x| is issued by the certificate |issuer| */
Expand Down
2 changes: 0 additions & 2 deletions include/crypto/x509.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,6 @@ int ossl_a2i_ipadd(unsigned char *ipout, const char *ipasc);
int ossl_x509_set1_time(int *modified, ASN1_TIME **ptm, const ASN1_TIME *tm);
int ossl_x509_print_ex_brief(BIO *bio, X509 *cert, unsigned long neg_cflags);
int ossl_x509v3_cache_extensions(X509 *x);
STACK_OF(X509) *ossl_x509_store_ctx_get_certs(X509_STORE_CTX *ctx,
const X509_NAME *nm, int up_refs);
int ossl_x509_init_sig_info(X509 *x);

int ossl_x509_set0_libctx(X509 *x, OSSL_LIB_CTX *libctx, const char *propq);
Expand Down

0 comments on commit 205564f

Please sign in to comment.