x509 Certificate verification fails when basicConstraints=CA:FALSE,pathlen:0 on self-signed leaf certs
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
openssl (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
Focal |
Fix Released
|
Medium
|
Matthew Ruffell | ||
Groovy |
Fix Released
|
Medium
|
Matthew Ruffell | ||
Hirsute |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
[Impact]
In openssl 1.1.1f, the below commit was merged:
commit ba4356ae4002a04
Author: Bernd Edlinger <email address hidden>
Date: Sat Jan 4 15:54:53 2020 +0100
Subject: Fix error handling in x509v3_
Link: https:/
This introduced a regression which caused certificate validation to fail when certificates violate RFC 5280 [1], namely, when a certificate has "basicConstrain
Because of this, openssl 1.1.1f rejects these certificates and they cannot be used in the system certificate store, and ssl connections fail when you try to use them to connect to a ssl endpoint.
The error you see when you try verify is:
$ openssl verify -CAfile CA/rootCA_cert.pem -untrusted CA/subCA_cert.pem user1_cert.pem
error 20 at 0 depth lookup: unable to get local issuer certificate
error user1_cert.pem: verification failed
The exact same certificates work fine on Xenial, Bionic and Hirsute.
[1] https:/
[Testcase]
We will create our own root CA, intermediate CA and leaf server certificate.
Create necessary directories:
$ mkdir reproducer
$ cd reproducer
$ mkdir CA
Write openssl configuration files to disk for each CA and cert:
$ cat << EOF >> rootCA.cnf
[ req ]
prompt = no
distinguished_name = req_distinguish
x509_extensions = usr_cert
[ req_distinguish
C = DE
O = Test Org
CN = Test RSA PSS Root-CA
[ usr_cert ]
basicConstraints = critical,CA:TRUE
keyUsage = critical,
subjectKeyIdent
authorityKeyIde
EOF
$ cat << EOF >> subCA.cnf
[ req ]
prompt = no
distinguished_name = req_distinguish
x509_extensions = usr_cert
[ req_distinguish
C = DE
O = Test Org
CN = Test RSA PSS Sub-CA
[ usr_cert ]
basicConstraints = critical,
keyUsage = critical,
subjectKeyIdent
authorityKeyIde
EOF
$ cat << EOF >> user.cnf
[ req ]
prompt = no
distinguished_name = req_distinguish
x509_extensions = usr_cert
[ req_distinguish
C = DE
O = Test Org
CN = Test User
[ usr_cert ]
basicConstraints = critical,
keyUsage = critical,
extendedKeyUsage = clientAuth,
subjectKeyIdent
authorityKeyIde
EOF
Then generate the necessary RSA keys and form certificates:
$ openssl genpkey -algorithm RSA-PSS -out rootCA_key.pem -pkeyopt rsa_keygen_
$ openssl req -config rootCA.cnf -set_serial 01 -new -batch -sha256 -nodes -x509 -days 9125 -out CA/rootCA_cert.pem -key rootCA_key.pem -sigopt rsa_padding_
$ openssl genpkey -algorithm RSA-PSS -out subCA_key.pem -pkeyopt rsa_keygen_
$ openssl req -config subCA.cnf -new -out subCA_req.pem -key subCA_key.pem -sigopt rsa_padding_
$ openssl x509 -req -sha256 -in subCA_req.pem -CA CA/rootCA_cert.pem -CAkey rootCA_key.pem -out CA/subCA_cert.pem -CAserial rootCA_serial.txt -CAcreateserial -extfile subCA.cnf -extensions usr_cert -days 4380 -sigopt rsa_padding_
$ c_rehash CA
$ openssl genpkey -algorithm RSA-PSS -out user1_key.pem -pkeyopt rsa_keygen_
$ openssl req -config user.cnf -new -out user1_req.pem -key user1_key.pem -sigopt rsa_padding_
$ openssl x509 -req -sha256 -in user1_req.pem -CA CA/subCA_cert.pem -CAkey subCA_key.pem -out user1_cert.pem -CAserial subCA_serial.txt -CAcreateserial -extfile user.cnf -extensions usr_cert -days 1825 -sigopt rsa_padding_
Now, let's try verify the generated certificates:
$ openssl version
OpenSSL 1.1.1f 31 Mar 2020
$ openssl verify -CAfile CA/rootCA_cert.pem -untrusted CA/subCA_cert.pem user1_cert.pem
error 20 at 0 depth lookup: unable to get local issuer certificate
error user1_cert.pem: verification failed
There are test packages available in the following ppa:
https:/
If you install these test packages, and attempt to verify, things work as planned.
$ openssl verify -CAfile CA/rootCA_cert.pem -untrusted CA/subCA_cert.pem user1_cert.pem
user1_cert.pem: OK
[Where problems could occur]
If a regression were to occur, it would occur around x509 certificate parsing and validation. It may cause certificates which had previously passed to fail, or certificates which failed to pass. It could potentially cause all certificates to fail or pass.
Since this is the openssl package and the package is security-critical, this will need a lot of validation, testing, and likely a review by the security team.
One of the commits which fixes the issue adds two testcases to the openssl testsuite, which tests the "CA:FALSE, pathlen:0" certificates with and without -x509_strict, and tests to see if it passes without, and fails with.
[Other info]
This was reported in the upstream issue #11456 [2]:
[2] https:/
I believe these three commits fix the issue:
commit 00a0da2f021e6a0
Author: Tomas Mraz <email address hidden>
Date: Thu Apr 2 15:56:12 2020 +0200
Subject: Allow certificates with Basic Constraints CA:false, pathlen:0
Link: https:/
commit 29e94f285f7f05b
Author: Tomas Mraz <email address hidden>
Date: Thu Apr 2 17:31:21 2020 +0200
Subject: Set X509_V_
Link: https:/
commit e78f2a8f269a4dc
Author: Tomas Mraz <email address hidden>
Date: Fri Apr 3 10:24:40 2020 +0200
Subject: Add test cases for the non CA certificate with pathlen:0
Link: https:/
These landed in openssl 1.1.1g, and hirsute already has these fixes.
Changed in openssl (Ubuntu): | |
status: | New → Fix Released |
Changed in openssl (Ubuntu Hirsute): | |
status: | New → Fix Released |
Changed in openssl (Ubuntu Focal): | |
status: | New → In Progress |
Changed in openssl (Ubuntu Groovy): | |
status: | New → In Progress |
Changed in openssl (Ubuntu Focal): | |
importance: | Undecided → Medium |
Changed in openssl (Ubuntu Groovy): | |
importance: | Undecided → Medium |
Changed in openssl (Ubuntu Focal): | |
assignee: | nobody → Matthew Ruffell (mruffell) |
Changed in openssl (Ubuntu Groovy): | |
assignee: | nobody → Matthew Ruffell (mruffell) |
tags: | added: focal groovy sts |
description: | updated |
description: | updated |
tags: | added: sts-sponsor |
Attached is a debdiff for openssl on Focal which fixes this bug.