summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-07-27 23:38:37 -0400
committerJune McEnroe <june@causal.agency>2020-07-31 12:12:53 -0400
commita62da8761cac35da97d180e5d8221966c1425b78 (patch)
tree8aa3ab9604274fe532adde6da276ca773982fefe
parenttls_ocsp: Use ASN1_TIME_to_tm (diff)
downloadlibretls-a62da8761cac35da97d180e5d8221966c1425b78.tar.gz
libretls-a62da8761cac35da97d180e5d8221966c1425b78.zip
tls_ocsp: Use X509_STORE_CTX_new and X509_OBJECT_new
-rw-r--r--tls_ocsp.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/tls_ocsp.c b/tls_ocsp.c
index d85d79c..3ba45fc 100644
--- a/tls_ocsp.c
+++ b/tls_ocsp.c
@@ -130,8 +130,8 @@ tls_ocsp_get_certid(X509 *main_cert, STACK_OF(X509) *extra_certs,
 {
 	X509_NAME *issuer_name;
 	X509 *issuer;
-	X509_STORE_CTX storectx;
-	X509_OBJECT tmpobj;
+	X509_STORE_CTX *storectx = NULL;
+	X509_OBJECT *tmpobj = NULL;
 	OCSP_CERTID *cid = NULL;
 	X509_STORE *store;
 
@@ -146,15 +146,24 @@ tls_ocsp_get_certid(X509 *main_cert, STACK_OF(X509) *extra_certs,
 
 	if ((store = SSL_CTX_get_cert_store(ssl_ctx)) == NULL)
 		return NULL;
-	if (X509_STORE_CTX_init(&storectx, store, main_cert, extra_certs) != 1)
+	if ((storectx = X509_STORE_CTX_new()) == NULL)
 		return NULL;
-	if (X509_STORE_get_by_subject(&storectx, X509_LU_X509, issuer_name,
-		&tmpobj) == 1) {
-		cid = OCSP_cert_to_id(NULL, main_cert, tmpobj.data.x509);
-		X509_OBJECT_free_contents(&tmpobj);
+	if (X509_STORE_CTX_init(storectx, store, main_cert, extra_certs) != 1)
+		goto err;
+	if ((tmpobj = X509_OBJECT_new()) == NULL)
+		goto err;
+	if (X509_STORE_get_by_subject(storectx, X509_LU_X509, issuer_name,
+		tmpobj) == 1) {
+		cid = OCSP_cert_to_id(NULL, main_cert, X509_OBJECT_get0_X509(tmpobj));
+		X509_OBJECT_free(tmpobj);
 	}
-	X509_STORE_CTX_cleanup(&storectx);
+	X509_STORE_CTX_free(storectx);
 	return cid;
+
+ err:
+	X509_OBJECT_free(tmpobj);
+	X509_STORE_CTX_free(storectx);
+	return NULL;
 }
 
 struct tls_ocsp *