check_sig_alg_match(): weaken sig nid comparison to allow RSA{,PSS} key verify RSA-PSS

This is an upstream fix for #13931

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13968)
This commit is contained in:
Dr. David von Oheimb 2021-01-26 11:53:15 +01:00 committed by Dr. David von Oheimb
parent 03f5c8930c
commit 199df4a93f
8 changed files with 133 additions and 18 deletions

View File

@ -362,18 +362,20 @@ static int setup_crldp(X509 *x)
}
/* Check that issuer public key algorithm matches subject signature algorithm */
static int check_sig_alg_match(const EVP_PKEY *pkey, const X509 *subject)
static int check_sig_alg_match(const EVP_PKEY *issuer_key, const X509 *subject)
{
int pkey_nid;
int signer_nid, subj_sig_nid;
if (pkey == NULL)
if (issuer_key == NULL)
return X509_V_ERR_NO_ISSUER_PUBLIC_KEY;
signer_nid = EVP_PKEY_base_id(issuer_key);
if (OBJ_find_sigid_algs(OBJ_obj2nid(subject->cert_info.signature.algorithm),
NULL, &pkey_nid) == 0)
return X509_V_ERR_UNSUPPORTED_SIGNATURE_ALGORITHM;
if (EVP_PKEY_type(pkey_nid) != EVP_PKEY_base_id(pkey))
return X509_V_ERR_SIGNATURE_ALGORITHM_MISMATCH;
return X509_V_OK;
NULL, &subj_sig_nid) == 0)
return X509_V_ERR_UNSUPPORTED_SIGNATURE_ALGORITHM;
if (signer_nid == EVP_PKEY_type(subj_sig_nid)
|| (signer_nid == NID_rsaEncryption && subj_sig_nid == NID_rsassaPss))
return X509_V_OK;
return X509_V_ERR_SIGNATURE_ALGORITHM_MISMATCH;
}
#define V1_ROOT (EXFLAG_V1|EXFLAG_SS)

View File

@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDXjCCAhagAwIBAgIBAjA9BgkqhkiG9w0BAQowMKANMAsGCWCGSAFlAwQCAaEa
MBgGCSqGSIb3DQEBCDALBglghkgBZQMEAgGiAwIBIDASMRAwDgYDVQQDDAdSb290
IENBMCAXDTIxMDEyNjEwMDUwOFoYDzIxMjEwM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5Rcf/w3GQ/4xNPgo2HXpo7uIgu+jcuJTYgVFTeAxl++qnRDSWA2eBp4yuxsI
Vl1lDz9mjsI2oBH/wFk1/Ukc3RxCMwZ4rgQ4I+XndWfTlK1aqUAfrFkQ9QzBZK1K
xMY1U7OWaoIbFYvRmavknm+UqtKW5Vf7jJFkijwkFsbSGb6CYBM7YrDtPh2zyvlr
3zG5ep5LR2inKcc/SuIiJ7TvkGPX79ByST5brbkb1Ctvhmjd1XMSuEPJ3EEPoqNG
T4tniIQPYf55NB9KiR+3AgMBAAGjfjB8MB0GA1UdDgQWBBTnm+IqrYpsOst2UeWO
B5gil+FzojAfBgNVHSMEGDAWgBQZ+aED9VzFaSHtVQEfFR0cdAuCsDAJBgNVHRME
AjAAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMBoGA1UdEQQTMBGCD0VFLVBTUy13cm9u
ZzEuNTALBgkqhkiG9w0BAQsDggEBAJYxCmTZfgjCfhf1r4dS+nebCM1qQ2WsOvwS
SXSMOxVs0sRc2KUjiTR00j/pgASaRVPauom5y+Qp6J2NUUBcwkQhGbQPDr8pdmWv
NPXX3UwfIl2gO9Bo5z0G0BOZmhCgNqbHcuJrW1tLRLwQWHsqm7gcqIq+/0Wsz5SA
QETZfmMbPAlj+aotLJmc2UvcGyz7jAeEJ3xIikey9c8HK73c4UyXepeUckQKsTRe
hs6+TluxaJerm3/1MRTOrq9aBGxoxNUc5cpJDZFF1rG9BtQgXxyGpiItkZX60N/3
P1js8/l2FH8fEcb63WeChKMmqnw18fQUmunVyZWvsFiQVRHterM=
-----END CERTIFICATE-----

View File

@ -116,6 +116,19 @@ genroot() {
}
genca() {
local OPTIND=1
local purpose=
while getopts p: o
do
case $o in
p) purpose="$OPTARG";;
*) echo "Usage: $0 genca [-p EKU] cn keyname certname cakeyname cacertname" >&2
return 1;;
esac
done
shift $((OPTIND - 1))
local cn=$1; shift
local key=$1; shift
local cert=$1; shift
@ -127,17 +140,16 @@ genca() {
local akid="authorityKeyIdentifier = keyid"
exts=$(printf "%s\n%s\n%s\n" "$bcon" "$ku" "$skid" "$akid")
for eku in "$@"
do
exts=$(printf "%s\nextendedKeyUsage = %s\n" "$exts" "$eku")
done
if [ -n "$purpose" ]; then
exts=$(printf "%s\nextendedKeyUsage = %s\n" "$exts" "$purpose")
fi
if [ -n "$NC" ]; then
exts=$(printf "%s\nnameConstraints = %s\n" "$exts" "$NC")
fi
csr=$(req "$key" "CN = $cn") || return 1
echo "$csr" |
cert "$cert" "$exts" -CA "${cacert}.pem" -CAkey "${cakey}.pem" \
-set_serial 2 -days "${DAYS}"
-set_serial 2 -days "${DAYS}" "$@"
}
gen_nonbc_ca() {

View File

@ -125,7 +125,7 @@ OPENSSL_KEYBITS=768 \
# client intermediate ca: cca-cert
# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth
#
./mkcert.sh genca "CA" ca-key cca-cert root-key root-cert clientAuth
./mkcert.sh genca -p clientAuth "CA" ca-key cca-cert root-key root-cert
#
openssl x509 -in cca-cert.pem -trustout \
-addtrust serverAuth -out cca+serverAuth.pem
@ -143,7 +143,7 @@ openssl x509 -in cca-cert.pem -trustout \
# server intermediate ca: sca-cert
# trust variants: +serverAuth, -serverAuth, +clientAuth, -clientAuth, -anyEKU, +anyEKU
#
./mkcert.sh genca "CA" ca-key sca-cert root-key root-cert serverAuth
./mkcert.sh genca -p serverAuth "CA" ca-key sca-cert root-key root-cert
#
openssl x509 -in sca-cert.pem -trustout \
-addtrust serverAuth -out sca+serverAuth.pem
@ -392,9 +392,16 @@ REQMASK=MASK:0x800 ./mkcert.sh req badalt7-key "O = Bad NC Test Certificate 7" \
# SHA1
./mkcert.sh genee PSS-SHA1 ee-key ee-pss-sha1-cert ca-key ca-cert \
-sha1 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest
# SHA256
# EE SHA256
./mkcert.sh genee PSS-SHA256 ee-key ee-pss-sha256-cert ca-key ca-cert \
-sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest
-sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:digest
# CA-PSS
./mkcert.sh genca "CA-PSS" ca-pss-key ca-pss-cert root-key root-cert \
-sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1
./mkcert.sh genee "EE-PSS" ee-key ee-pss-cert ca-pss-key ca-pss-cert \
-sha256 -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1
# Should not have been possible to produce, see issue #13968:
#./mkcert.sh genee "EE-PSS-wrong1.5" ee-key ee-pss-wrong1.5-cert ca-pss-key ca-pss-cert -sha256
OPENSSL_KEYALG=ec OPENSSL_KEYBITS=brainpoolP256r1 ./mkcert.sh genee \
"Server ECDSA brainpoolP256r1 cert" server-ecdsa-brainpoolP256r1-key \

View File

@ -27,7 +27,7 @@ sub verify {
run(app([@args]));
}
plan tests => 153;
plan tests => 155;
# Canonical success
ok(verify("ee-cert", "sslserver", ["root-cert"], ["ca-cert"]),
@ -380,6 +380,11 @@ ok(!verify("ee-pss-sha1-cert", "sslserver", ["root-cert"], ["ca-cert"], "-auth_l
ok(verify("ee-pss-sha256-cert", "sslserver", ["root-cert"], ["ca-cert"], "-auth_level", "2"),
"PSS signature using SHA256 and auth level 2");
ok(verify("ee-pss-cert", "sslserver", ["root-cert"], ["ca-pss-cert"], ),
"CA PSS signature");
ok(!verify("ee-pss-wrong1.5-cert", "sslserver", ["root-cert"], ["ca-pss-cert"], ),
"CA producing regular PKCS#1 v1.5 signature with PSA-PSS key");
ok(!verify("many-names1", "sslserver", ["many-constraints"], ["many-constraints"], ),
"Too many names and constraints to check (1)");
ok(!verify("many-names2", "sslserver", ["many-constraints"], ["many-constraints"], ),