Guard against DoS in name constraints handling.
authorDavid Benjamin <davidben@google.com>
Mon, 18 Sep 2017 20:51:56 +0000 (16:51 -0400)
committerAndy Polyakov <appro@openssl.org>
Sat, 30 Sep 2017 20:17:36 +0000 (22:17 +0200)
commit329a004f784e554ee7fbe2135e6617e784566c28
tree6e5edbf7e598169f9ecbabd0ff760f4abe04e1f0
parent15ab3217799db508dec4c78cbfd185129f8fdfec
Guard against DoS in name constraints handling.

This guards against the name constraints check consuming large amounts
of CPU time when certificates in the presented chain contain an
excessive number of names (specifically subject email names or subject
alternative DNS names) and/or name constraints.

Name constraints checking compares the names presented in a certificate
against the name constraints included in a certificate higher up in the
chain using two nested for loops.

Move the name constraints check so that it happens after signature
verification so peers cannot exploit this using a chain with invalid
signatures. Also impose a hard limit on the number of name constraints
check loop iterations to further mitigate the issue.

Thanks to NCC for finding this issue. Fix written by Martin Kreichgauer.

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4411)

(cherry picked from commit 8545051c3652bce7bb962afcb6879c4a6288bc67)

Resolved conflicts:
crypto/x509v3/v3_ncons.c
test/recipes/25-test_verify.t
crypto/x509/x509_vfy.c
crypto/x509v3/v3_ncons.c
test/certs/many-constraints.pem [new file with mode: 0644]
test/certs/many-names1.pem [new file with mode: 0644]
test/certs/many-names2.pem [new file with mode: 0644]
test/certs/many-names3.pem [new file with mode: 0644]
test/certs/some-names1.pem [new file with mode: 0644]
test/certs/some-names2.pem [new file with mode: 0644]
test/certs/some-names3.pem [new file with mode: 0644]
test/recipes/25-test_verify.t