Allow to continue on UNABLE_TO_VERIFY_LEAF_SIGNATURE
authorAndré Klitzing <aklitzing@gmail.com>
Wed, 18 Mar 2020 15:04:06 +0000 (16:04 +0100)
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>
Thu, 8 Oct 2020 14:49:29 +0000 (16:49 +0200)
This unifies the behaviour of a single certificate with
an unknown CA certificate with a self-signed certificate.
The user callback can mask that error to retrieve additional
error information. So the user application can decide to
abort the connection instead to be forced by openssl.

This change in behaviour is backward compatible as user callbacks
who don't want to ignore UNABLE_TO_VERIFY_LEAF_SIGNATURE will
still abort the connection by default.

CLA: trivial
Fixes #11297

Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13083)

crypto/x509/x509_vfy.c

index cf89179dfd7f3a6e7d47c5007d5dadd2babdaf4a..710939b619901e6bd0523d183d0001d53a9d0fac 100644 (file)
@@ -1804,9 +1804,15 @@ static int internal_verify(X509_STORE_CTX *ctx)
             xs = xi;
             goto check_cert_time;
         }
-        if (n <= 0)
-            return verify_cb_cert(ctx, xi, 0,
-                                  X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE);
+        if (n <= 0) {
+            if (!verify_cb_cert(ctx, xi, 0,
+                                X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE))
+                return 0;
+
+            xs = xi;
+            goto check_cert_time;
+        }
+
         n--;
         ctx->error_depth = n;
         xs = sk_X509_value(ctx->chain, n);