Skip to content

Commit 9927cdb

Browse files
kdienescron2
authored andcommitted
tls_ctx_load_ca: Improve certificate error messages
If a CA certificate file includes intermediate certificates, and any of them fail to verify, the current code will file with "Cannot load CA certificate file". Instead, generate a more specific error message identifying the specific sub-certificate(s) which did not validate. Acked-by: Steffan Karger <[email protected]> Message-Id: <CAK6ywbLVtSgRZEt4N+02fz+vQ0GNp==5KdsbqWtZ+fgUzrZq+g@mail.gmail.com> URL: http://article.gmane.org/gmane.network.openvpn.devel/7837 Signed-off-by: Gert Doering <[email protected]>
1 parent 16e24da commit 9927cdb

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/openvpn/ssl_openssl.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ tls_ctx_load_ca (struct tls_root_ctx *ctx, const char *ca_file,
743743
X509_STORE *store = NULL;
744744
X509_NAME *xn = NULL;
745745
BIO *in = NULL;
746-
int i, added = 0;
746+
int i, added = 0, prev = 0;
747747

748748
ASSERT(NULL != ctx);
749749

@@ -770,6 +770,11 @@ tls_ctx_load_ca (struct tls_root_ctx *ctx, const char *ca_file,
770770
if (info->crl)
771771
X509_STORE_add_crl (store, info->crl);
772772

773+
if (tls_server && !info->x509)
774+
{
775+
msg (M_SSLERR, "X509 name was missing in TLS mode");
776+
}
777+
773778
if (info->x509)
774779
{
775780
X509_STORE_add_cert (store, info->x509);
@@ -799,15 +804,31 @@ tls_ctx_load_ca (struct tls_root_ctx *ctx, const char *ca_file,
799804
sk_X509_NAME_push (cert_names, xn);
800805
}
801806
}
807+
808+
if (tls_server) {
809+
int cnum = sk_X509_NAME_num (cert_names);
810+
if (cnum != (prev + 1)) {
811+
msg (M_WARN, "Cannot load CA certificate file %s (entry %d did not validate)", np(ca_file), added);
812+
}
813+
prev = cnum;
814+
}
815+
802816
}
803817
sk_X509_INFO_pop_free (info_stack, X509_INFO_free);
804818
}
805819

806820
if (tls_server)
807821
SSL_CTX_set_client_CA_list (ctx->ctx, cert_names);
808822

809-
if (!added || (tls_server && sk_X509_NAME_num (cert_names) != added))
810-
msg (M_SSLERR, "Cannot load CA certificate file %s", np(ca_file));
823+
if (!added)
824+
msg (M_SSLERR, "Cannot load CA certificate file %s (no entries were read)", np(ca_file));
825+
826+
if (tls_server) {
827+
int cnum = sk_X509_NAME_num (cert_names);
828+
if (cnum != added)
829+
msg (M_SSLERR, "Cannot load CA certificate file %s (only %d of %d entries were valid X509 names)", np(ca_file), cnum, added);
830+
}
831+
811832
if (in)
812833
BIO_free (in);
813834
}

0 commit comments

Comments
 (0)