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

rs-commit at redwax.eu rs-commit at redwax.eu
Thu Nov 25 12:52:47 CET 2021


Author: minfrin at redwax.eu
Date: Thu Nov 25 12:52:46 2021
New Revision: 80

Log:
Remove duplicated reads of the key type.

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 12:52:46 2021
@@ -1098,14 +1098,6 @@
 
             apr_pool_create(&key->pool, r->pool);
 
-            // fixme normalise should do this
-            switch(EVP_PKEY_base_id(pkey)) {
-            case EVP_PKEY_RSA: {
-                key->common.type = REDWAX_KEY_RSA;
-                break;
-            }
-            }
-
             key->header = header;
             key->len = BIO_get_mem_data(kbio, &key->der);
 
@@ -1859,7 +1851,6 @@
 static apr_status_t import_bag(redwax_tool_t *r, const char *file, const char *secret,
         const PKCS12_SAFEBAG *bag, const char **pass, apr_size_t *pass_len)
 {
-    EVP_PKEY *pkey;
     const STACK_OF(X509_ATTRIBUTE) *attrs;
     const PKCS8_PRIV_KEY_INFO *p8inf;
 
@@ -1875,14 +1866,6 @@
 
         p8inf = PKCS12_SAFEBAG_get0_p8inf(bag);
 
-        if (!(pkey = EVP_PKCS82PKEY(p8inf))) {
-            redwax_openssl_print_errors(r);
-            return APR_EINVAL;
-        }
-
-        apr_pool_cleanup_register(r->pool, pkey, cleanup_evp_pkey,
-                apr_pool_cleanup_null);
-
         if ((kbio = BIO_new(BIO_s_mem())) == NULL) {
             return APR_ENOMEM;
         }
@@ -1895,14 +1878,6 @@
         key = apr_array_push(r->keys_in);
 
         apr_pool_create(&key->pool, r->pool);
-
-        // fixme duped by normalise key?
-        switch(EVP_PKEY_base_id(pkey)) {
-        case EVP_PKEY_RSA: {
-            key->common.type = REDWAX_KEY_RSA;
-            break;
-        }
-        }
 
         key->len = BIO_get_mem_data(kbio, &key->der);
 
@@ -1956,14 +1931,6 @@
         apr_pool_cleanup_register(r->pool, p8inf, cleanup_p8inf,
                 apr_pool_cleanup_null);
 
-        if ((pkey = EVP_PKCS82PKEY(p8inf)) == NULL) {
-            redwax_openssl_print_errors(r);
-            return APR_EINVAL;
-        }
-
-        apr_pool_cleanup_register(r->pool, pkey, cleanup_evp_pkey,
-                apr_pool_cleanup_null);
-
         if ((kbio = BIO_new(BIO_s_mem())) == NULL) {
             return APR_ENOMEM;
         }
@@ -1976,14 +1943,6 @@
         key = apr_array_push(r->keys_in);
 
         apr_pool_create(&key->pool, r->pool);
-
-        // fixme duped by normalise key?
-        switch(EVP_PKEY_base_id(pkey)) {
-        case EVP_PKEY_RSA: {
-            key->common.type = REDWAX_KEY_RSA;
-            break;
-        }
-        }
 
         key->len = BIO_get_mem_data(kbio, &key->der);
 
@@ -2958,7 +2917,7 @@
     /*
      * DER encoded key is present, but the components are not.
      */
-    if (key->der && !key->rsa) {
+    if (key->der && key->common.type == REDWAX_KEY_NONE) {
 
         PKCS8_PRIV_KEY_INFO *p8inf = NULL;
         EVP_PKEY *pkey = NULL;
@@ -3092,7 +3051,8 @@
                     key->rsa->coefficient_len);
             BN_bn2bin(iqmp, key->rsa->coefficient);
 
-
+            /* key type is RSA */
+            key->common.type = REDWAX_KEY_RSA;
 
             /* ID is a SHA1 hash of the modulus */
             EVP_Digest(key->rsa->modulus, key->rsa->modulus_len, digest, &len,



More information about the rs-commit mailing list