Fix verify algorithm.
authorDr. Stephen Henson <steve@openssl.org>
Tue, 24 Mar 2015 16:21:21 +0000 (16:21 +0000)
committerMatt Caswell <matt@openssl.org>
Mon, 20 Apr 2015 12:42:17 +0000 (13:42 +0100)
Disable loop checking when we retry verification with an alternative path.
This fixes the case where an intermediate CA is explicitly trusted and part
of the untrusted certificate list. By disabling loop checking for this case
the untrusted CA can be replaced by the explicitly trusted case and
verification will succeed.

Signed-off-by: Matt Caswell <matt@openssl.org>
(cherry picked from commit e5991ec528b1c339062440811e2641f5ea2b328b)

Reviewed-by: Rich Salz <rsalz@openssl.org>
crypto/x509/x509_vfy.c

index f3e9c56b0917158b83ebf69002f893cc1f3a5994..c0f6a5dfff82dd24370bbcd9de8d81d46de0aac7 100644 (file)
@@ -370,8 +370,16 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
             && !(ctx->param->flags & X509_V_FLAG_TRUSTED_FIRST)
             && !(ctx->param->flags & X509_V_FLAG_NO_ALT_CHAINS)) {
             while (j-- > 1) {
+                STACK_OF(X509) *chtmp = ctx->chain;
                 xtmp2 = sk_X509_value(ctx->chain, j - 1);
+                /*
+                 * Temporarily set chain to NULL so we don't discount
+                 * duplicates: the same certificate could be an untrusted
+                 * CA found in the trusted store.
+                 */
+                ctx->chain = NULL;
                 ok = ctx->get_issuer(&xtmp, ctx, xtmp2);
+                ctx->chain = chtmp;
                 if (ok < 0)
                     goto end;
                 /* Check if we found an alternate chain */