Use more X509_REQ_get0_pubkey & X509_get0_pubkey
authorFdaSilvaYY <fdasilvayy@gmail.com>
Wed, 6 Apr 2016 22:20:11 +0000 (00:20 +0200)
committerRich Salz <rsalz@openssl.org>
Wed, 20 Jul 2016 05:35:38 +0000 (01:35 -0400)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1284)

apps/req.c
crypto/x509/t_req.c
test/ssltest_old.c

index f1ee9515a44b62fea0e69784fe232df77053db8a..e459a712135a7538bc9ad6dbd496b0c02ffa5e62 100644 (file)
@@ -727,15 +727,14 @@ int req_main(int argc, char **argv)
         goto end;
 
     if (pubkey) {
-        EVP_PKEY *tpubkey;
-        tpubkey = X509_REQ_get_pubkey(req);
+        EVP_PKEY *tpubkey = X509_REQ_get0_pubkey(req);
+
         if (tpubkey == NULL) {
             BIO_printf(bio_err, "Error getting public key\n");
             ERR_print_errors(bio_err);
             goto end;
         }
         PEM_write_bio_PUBKEY(out, tpubkey);
-        EVP_PKEY_free(tpubkey);
     }
 
     if (text) {
@@ -758,9 +757,9 @@ int req_main(int argc, char **argv)
         EVP_PKEY *tpubkey;
 
         if (x509)
-            tpubkey = X509_get_pubkey(x509ss);
+            tpubkey = X509_get0_pubkey(x509ss);
         else
-            tpubkey = X509_REQ_get_pubkey(req);
+            tpubkey = X509_REQ_get0_pubkey(req);
         if (tpubkey == NULL) {
             fprintf(stdout, "Modulus=unavailable\n");
             goto end;
@@ -774,7 +773,6 @@ int req_main(int argc, char **argv)
         } else
 #endif
             fprintf(stdout, "Wrong Algorithm type");
-        EVP_PKEY_free(tpubkey);
         fprintf(stdout, "\n");
     }
 
index 0d0447bd2b07c75e91f3bedc1a2ca04b7d651831..dbe4be3db15b88fd9768f05bd9d505b53a3474d4 100644 (file)
@@ -86,13 +86,12 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags,
         if (BIO_puts(bp, "\n") <= 0)
             goto err;
 
-        pkey = X509_REQ_get_pubkey(x);
+        pkey = X509_REQ_get0_pubkey(x);
         if (pkey == NULL) {
             BIO_printf(bp, "%12sUnable to load Public Key\n", "");
             ERR_print_errors(bp);
         } else {
             EVP_PKEY_print_public(bp, pkey, 16, NULL);
-            EVP_PKEY_free(pkey);
         }
     }
 
index 74908b0087b3398ef2ebc0364b9a02c665f85df9..8863465f99dde866c6f1b7519a601ccced30abe9 100644 (file)
@@ -852,11 +852,11 @@ static void print_details(SSL *c_ssl, const char *prefix)
                SSL_CIPHER_get_version(ciph), SSL_CIPHER_get_name(ciph));
     cert = SSL_get_peer_certificate(c_ssl);
     if (cert != NULL) {
-        pkey = X509_get_pubkey(cert);
-        if (pkey != NULL) {
+        EVP_PKEY* pubkey = X509_get0_pubkey(cert);
+
+        if (pubkey != NULL) {
             BIO_puts(bio_stdout, ", ");
-            print_key_details(bio_stdout, pkey);
-            EVP_PKEY_free(pkey);
+            print_key_details(bio_stdout, pubkey);
         }
         X509_free(cert);
     }