[rs-commit] r81 - /redwax-tool/trunk/redwax_openssl.c

rs-commit at redwax.eu rs-commit at redwax.eu
Thu Nov 25 13:45:38 CET 2021


Author: minfrin at redwax.eu
Date: Thu Nov 25 13:45:38 2021
New Revision: 81

Log:
Import CRLs from pkcs12 files.

Modified:
    redwax-tool/trunk/redwax_openssl.c

Modified: redwax-tool/trunk/redwax_openssl.c
==============================================================================
--- redwax-tool/trunk/redwax_openssl.c	(original)
+++ redwax-tool/trunk/redwax_openssl.c	Thu Nov 25 13:45:38 2021
@@ -699,6 +699,17 @@
     return APR_SUCCESS;
 }
 
+#if 0
+static apr_status_t cleanup_x509_crl(void *dummy)
+{
+    if (dummy) {
+        X509_CRL_free(dummy);
+    }
+
+    return APR_SUCCESS;
+}
+#endif
+
 static apr_status_t cleanup_pkcs12(void *dummy)
 {
     if (dummy) {
@@ -1002,7 +1013,12 @@
 
                 crl->origin = file;
 
-//                 X509_CRL_free(c);
+                /* no cleanup because of sk_X509_CRL_push() */
+#if 0
+                apr_pool_cleanup_register(r->pool, c, cleanup_x509_crl,
+                        apr_pool_cleanup_null);
+#endif
+
              }
 
         }
@@ -1866,18 +1882,18 @@
 
         p8inf = PKCS12_SAFEBAG_get0_p8inf(bag);
 
+        key = apr_array_push(r->keys_in);
+
+        apr_pool_create(&key->pool, r->pool);
+
         if ((kbio = BIO_new(BIO_s_mem())) == NULL) {
             return APR_ENOMEM;
         }
 
-        apr_pool_cleanup_register(r->pool, kbio, cleanup_bio,
+        apr_pool_cleanup_register(key->pool, kbio, cleanup_bio,
                 apr_pool_cleanup_null);
 
         i2d_PKCS8_PRIV_KEY_INFO_bio(kbio, (PKCS8_PRIV_KEY_INFO *)p8inf);
-
-        key = apr_array_push(r->keys_in);
-
-        apr_pool_create(&key->pool, r->pool);
 
         key->len = BIO_get_mem_data(kbio, &key->der);
 
@@ -1931,18 +1947,18 @@
         apr_pool_cleanup_register(r->pool, p8inf, cleanup_p8inf,
                 apr_pool_cleanup_null);
 
+        key = apr_array_push(r->keys_in);
+
+        apr_pool_create(&key->pool, r->pool);
+
         if ((kbio = BIO_new(BIO_s_mem())) == NULL) {
             return APR_ENOMEM;
         }
 
-        apr_pool_cleanup_register(r->pool, kbio, cleanup_bio,
+        apr_pool_cleanup_register(key->pool, kbio, cleanup_bio,
                 apr_pool_cleanup_null);
 
         i2d_PKCS8_PRIV_KEY_INFO_bio(kbio, (PKCS8_PRIV_KEY_INFO *)p8inf);
-
-        key = apr_array_push(r->keys_in);
-
-        apr_pool_create(&key->pool, r->pool);
 
         key->len = BIO_get_mem_data(kbio, &key->der);
 
@@ -1956,7 +1972,7 @@
                         label->value.bmpstring->length);
                 key->label_len = strlen(key->label);
 
-                apr_pool_cleanup_register(r->pool, key->label, cleanup_alloc,
+                apr_pool_cleanup_register(key->pool, key->label, cleanup_alloc,
                         apr_pool_cleanup_null);
             }
         }
@@ -2026,7 +2042,7 @@
             return APR_ENOMEM;
         }
 
-        apr_pool_cleanup_register(r->pool, bio, cleanup_bio,
+        apr_pool_cleanup_register(cert->pool, bio, cleanup_bio,
                 apr_pool_cleanup_null);
 
         i2d_X509_bio(bio, x);
@@ -2043,12 +2059,59 @@
                         label->value.bmpstring->length);
                 cert->label_len = strlen(cert->label);
 
-                apr_pool_cleanup_register(r->pool, cert->label, cleanup_alloc,
+                apr_pool_cleanup_register(cert->pool, cert->label, cleanup_alloc,
                         apr_pool_cleanup_null);
             }
         }
 
         rt_run_normalise_certificate(r, cert, 1);
+
+        break;
+    }
+    case NID_crlBag: {
+
+        redwax_crl_t *crl;
+
+        BIO *bio;
+
+        X509_CRL *c;
+
+        if (PKCS12_SAFEBAG_get_bag_nid(bag) != NID_x509Crl) {
+            break;
+        }
+
+        c = PKCS12_SAFEBAG_get1_crl(bag);
+
+        if (c) {
+
+            redwax_print_error(r, "pkcs12-in: crl: %s\n",
+                    redwax_openssl_name(r->pool, X509_CRL_get_issuer(c)));
+
+            sk_X509_CRL_push(crl_index, c);
+
+            crl = apr_array_push(r->crls_in);
+
+            apr_pool_create(&crl->pool, r->pool);
+
+            if ((bio = BIO_new(BIO_s_mem())) == NULL) {
+                return APR_ENOMEM;
+            }
+
+            apr_pool_cleanup_register(crl->pool, bio, cleanup_bio,
+                    apr_pool_cleanup_null);
+
+            i2d_X509_CRL_bio(bio, c);
+
+            crl->len = BIO_get_mem_data(bio, &crl->der);
+
+            crl->origin = file;
+
+            /* no cleanup because of sk_X509_CRL_push() */
+#if 0
+            apr_pool_cleanup_register(r->pool, c, cleanup_x509_crl,
+                    apr_pool_cleanup_null);
+#endif
+        }
 
         break;
     }



More information about the rs-commit mailing list