Skip to content

Commit ad3043f

Browse files
committed
X.509: Fix self-signed determination
There's a bug in the code determining whether a certificate is self-signed or not: if they have neither AKID nor SKID then we just assume that the cert is self-signed, which may not be true. Fix this by checking that the raw subject name matches the raw issuer name and that the public key algorithm for the key and signature are both the same in addition to requiring that the AKID bits match. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent 6c2dc5a commit ad3043f

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎crypto/asymmetric_keys/x509_public_key.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ int x509_check_for_self_signed(struct x509_certificate *cert)
230230

231231
pr_devel("==>%s()\n", __func__);
232232

233+
if (cert->raw_subject_size != cert->raw_issuer_size ||
234+
memcmp(cert->raw_subject, cert->raw_issuer,
235+
cert->raw_issuer_size) != 0)
236+
goto not_self_signed;
237+
233238
if (cert->sig->auth_ids[0] || cert->sig->auth_ids[1]) {
234239
/* If the AKID is present it may have one or two parts. If
235240
* both are supplied, both must match.
@@ -246,6 +251,10 @@ int x509_check_for_self_signed(struct x509_certificate *cert)
246251
goto out;
247252
}
248253

254+
ret = -EKEYREJECTED;
255+
if (cert->pub->pkey_algo != cert->sig->pkey_algo)
256+
goto out;
257+
249258
ret = public_key_verify_signature(cert->pub, cert->sig);
250259
if (ret < 0) {
251260
if (ret == -ENOPKG) {

0 commit comments

Comments
 (0)