spkac: Check return values of NETSCAPE_SPKI functions
authorVladimir Panteleev <git@vladimir.panteleev.md>
Tue, 3 Mar 2020 18:04:00 +0000 (18:04 +0000)
committerDmitry Belyavskiy <beldmit@gmail.com>
Mon, 9 Mar 2020 08:51:51 +0000 (11:51 +0300)
Fixes silently producing an invalid SPKAC with non-RSA keys.

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/11224)

apps/spkac.c

index dbd3d45216306ab4b70ebeef9f1e21297f12ff70..17c4e5b8d0681262cfbf21b6787546baa54ace77 100644 (file)
@@ -145,8 +145,15 @@ int spkac_main(int argc, char **argv)
         if (challenge != NULL)
             ASN1_STRING_set(spki->spkac->challenge,
                             challenge, (int)strlen(challenge));
-        NETSCAPE_SPKI_set_pubkey(spki, pkey);
-        NETSCAPE_SPKI_sign(spki, pkey, EVP_md5());
+        if (!NETSCAPE_SPKI_set_pubkey(spki, pkey)) {
+            BIO_printf(bio_err, "Error setting public key\n");
+            goto end;
+        }
+        i = NETSCAPE_SPKI_sign(spki, pkey, EVP_md5());
+        if (i <= 0) {
+            BIO_printf(bio_err, "Error signing SPKAC\n");
+            goto end;
+        }
         spkstr = NETSCAPE_SPKI_b64_encode(spki);
         if (spkstr == NULL)
             goto end;