Skip to content

Commit

Permalink
Make sure that a cert with extensions gets version number 2 (v3)
Browse files Browse the repository at this point in the history
Fixes openssl#4419

Reviewed-by: Tim Hudson <[email protected]>
(Merged from openssl#4420)
  • Loading branch information
levitte committed Sep 26, 2017
1 parent 28c0a61 commit 4881d84
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion apps/ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,6 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
/* Lets add the extensions, if there are any */
if (ext_sect) {
X509V3_CTX ctx;
X509_set_version(ret, 2);

/* Initialize the context structure */
if (selfsign)
Expand Down Expand Up @@ -1790,6 +1789,15 @@ static int do_body(X509 **xret, EVP_PKEY *pkey, X509 *x509,
goto end;
}

{
const STACK_OF(X509_EXTENSION) *exts = X509_get0_extensions(ret);

if (exts != NULL && sk_X509_EXTENSION_num(exts) > 0)
/* Make it an X509 v3 certificate. */
if (!X509_set_version(ret, 2))
goto end;
}

/* Set the right value for the noemailDN option */
if (email_dn == 0) {
if (!X509_set_subject_name(ret, dn_subject))
Expand Down

0 comments on commit 4881d84

Please sign in to comment.