diff options
author | Jack Lloyd <[email protected]> | 2021-05-08 12:18:13 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2021-05-08 12:24:40 -0400 |
commit | 2c59a60f878ebe8818f32d15652360987945d8d4 (patch) | |
tree | 67e56d3f7b35691583e6cfbc8c15e8dc5baacd4b | |
parent | ef372a35d7dbbfa574650b9a275e1d9e61cbfdc9 (diff) |
Fix name constraint application
A name constraint on an intermediate certificate should not constraint
the intermediate itself, but only the subordinate certificates.
Fixes GH #2737
-rw-r--r-- | src/lib/x509/x509_ext.cpp | 7 | ||||
-rw-r--r-- | src/tests/data/x509/misc/nc_skip_self/int.pem | 30 | ||||
-rw-r--r-- | src/tests/data/x509/misc/nc_skip_self/leaf.pem | 29 | ||||
-rw-r--r-- | src/tests/data/x509/misc/nc_skip_self/root.pem | 29 | ||||
-rw-r--r-- | src/tests/test_x509_path.cpp | 46 |
5 files changed, 135 insertions, 6 deletions
diff --git a/src/lib/x509/x509_ext.cpp b/src/lib/x509/x509_ext.cpp index 123f48d99..c811ba6c9 100644 --- a/src/lib/x509/x509_ext.cpp +++ b/src/lib/x509/x509_ext.cpp @@ -563,14 +563,9 @@ void Name_Constraints::validate(const X509_Certificate& subject, const X509_Cert const bool issuer_name_constraint_critical = issuer.is_critical("X509v3.NameConstraints"); - const bool at_self_signed_root = (pos == cert_path.size() - 1); - // Check that all subordinate certs pass the name constraint - for(size_t j = 0; j <= pos; ++j) + for(size_t j = 0; j < pos; ++j) { - if(pos == j && at_self_signed_root) - continue; - bool permitted = m_name_constraints.permitted().empty(); bool failed = false; diff --git a/src/tests/data/x509/misc/nc_skip_self/int.pem b/src/tests/data/x509/misc/nc_skip_self/int.pem new file mode 100644 index 000000000..209bda324 --- /dev/null +++ b/src/tests/data/x509/misc/nc_skip_self/int.pem @@ -0,0 +1,30 @@ +-----BEGIN CERTIFICATE----- +MIIFLjCCAxagAwIBAgIBATANBgkqhkiG9w0BAQsFADAzMQswCQYDVQQGEwJDWjEP +MA0GA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V68CEpxWj0OD9qfGknnroS4XSNkgll9exqjI7WBWCyOls +SDyN2NgFrOqRj5vh6x/UhuEjfrYoJBDgyZM0sA2ZLRd1Cnno2xlnodNHUZxeUvl4 +hm/wecmO8fN36LiZfc6PAsEJ9Z4uh/a7QHDKNpy+egenQcpM7LFjCU+bMGP8Xp/u +l09LXmb4kqeYp9ljpf6biMPPMmORlYEtn8+C3i4AR/uWWu2eEjcrB5ImcyTnCzBu +4Tm4qjCDo2wRbFGnm/nXyOx7C6+Ay0pNO/DWSB21qexK13mKkgB+D3G9hVH5pOIu +elu7Zw9pl2qsTnH5iM8SHK2vZPeWPYiI68uCqAKiVRCRkt3GWVn1XH1Jff3Hyyku +Z9KC/pSTZW3IyAxsk2wIhVHK8W95Uy0WRLvioxYvJrCGfuRG5vBE0Ix2/yRtUXGZ +ze4+tWFRCPc7qdVURPMpwkla3U7BQoSk77q6b0crsDqs2NLPEdAOle+TdTAhXlZY +9HNm8l/ZrXFFbJiYVT5GnMvKZxMx60u4+WKwiVa0MOrn1Cp0peMds9ab9gTtN9n+ +5CnpKYsf4OQY47PGS65Ef4q2D4h8nK0ufoDTMZyDz8BkSknztFfvSISAR942f0RD +5CZP6FCUJ10K02umvACjXlMhJntrwXXeofs+k4W2YLVxjw== +-----END CERTIFICATE----- diff --git a/src/tests/data/x509/misc/nc_skip_self/leaf.pem b/src/tests/data/x509/misc/nc_skip_self/leaf.pem new file mode 100644 index 000000000..dd1991acd --- /dev/null +++ b/src/tests/data/x509/misc/nc_skip_self/leaf.pem @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIE4DCCAsgCAQEwDQYJKoZIhvcNAQELBQAwOzELMAkGA1UEBhMCQ1oxDzANBgNV +BAcMBlByYWd1ZTEbMBkGA1UECgwSVGVzdEludGVybWVkaWF0ZUNBMB4XDTIxMDUw +NDEwNDY0MloXDTIyMDUwNDEwNDY0MlowMTELMAkGA1UEBhMCQ1oxDTALBgNVBAcM +BEJybm8xEzARBgNV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wVmwz6/klluKOb +8YV53T4HnwKYtLmD+UMPdWAVzj4TdOSDTuOxQhu+NwjPMYKvMF2phN4v1BpVgUuy +m4HfuEpfHmHKsNPFJWZ9E28bbUJ39+LtARf3pqUL66V3CAlNodi6tpWqz4b3nPo+ +JznOox/ujntISe1ziNL6lHdGUFn9QaLQiXyIYZLNqheJ2GX4cHnKfzZxp/KqRBRA +Z/kUtHSAyL/LSJ3fAHxRdGmSiBP37PmDw7i11w9kd4EPK2EkiqZtmiQtDrsOQfh1 +0SeP4DHf3n7VoyGBDfpiC1WFnSafbMG+tOl7QuRX4RCJrVQWjFT73q0MCciryK7Z +TsUM+yHjDZY33k/kvevptczjWk1dxQ5Napr4ayW4jWvdWV55/lLYmhC8JP6La+1h +j50djA== +-----END CERTIFICATE----- diff --git a/src/tests/data/x509/misc/nc_skip_self/root.pem b/src/tests/data/x509/misc/nc_skip_self/root.pem new file mode 100644 index 000000000..27f99ee35 --- /dev/null +++ b/src/tests/data/x509/misc/nc_skip_self/root.pem @@ -0,0 +1,29 @@ +-----BEGIN CERTIFICATE----- +MIIFBzCCAu+gAwIBAgIUF/jloc5zNYR3gyPGyMfuC4Qf5cEwDQYJKoZIhvcNAQEL +BQAwMzELMAkGA1UEBhMCQ1oxDzANBgNVBAcMBlByYWd1ZTETMBEGA1UECgwKVGVz +dFJvb3RDQTAeFw0yMTA1MDQxMDQ2MzhaFw0yMjA1MDQxMDQ2MzhaMDMxCzAJBgNV +BAYTAkNaMQ8wDQYDVQQHDAZQcmFndWUxEzARBgNVBAoMClRlc3RSb290Q0EwggIi +MA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDSmObXNfY3NDTfYwTykRtTaJs9 +tw4qqw6oXQc5FSK7Itwo90i7VjyTa+yVWulRGyqeSGanqvbZeSuF6ZB4tVmTi+gH +HlxBnT0zamYNdR4Yo5OzhXGyuaXuACTCj5N0OtMTjlOS0qsxTnsD8lgUHY0dUWpq +e2JsduiS+fXuE6tde0IAH3Rr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gMxzrVKcy3 +Z3thAcqBC6xDr8Ctx7uX7zqdNXZQfGnz2wVW/GSDFpvmmqWnwHiqABkEPMvzmNb/ +OCcmRc45PclyhLc/aMudJTsB36e9Tt/UCWe+iDorsizY4u4Fe+4ujlkyQWgYfvUl +txvJF3BvCIHwTlFAECgg6Je5qu6yWu4T+P4zPhWj1RaYA1i7cuXTXwKKKg== +-----END CERTIFICATE----- diff --git a/src/tests/test_x509_path.cpp b/src/tests/test_x509_path.cpp index ef6be2219..e777f85fe 100644 --- a/src/tests/test_x509_path.cpp +++ b/src/tests/test_x509_path.cpp @@ -689,6 +689,52 @@ std::vector<Test::Result> Validate_Name_Constraint_CaseInsensitive::run() BOTAN_REGISTER_TEST("x509", "x509_name_constraint_ci", Validate_Name_Constraint_CaseInsensitive); +class Validate_Name_Constraint_NoCheckSelf final : public Test + { + public: + std::vector<Test::Result> run() override; + }; + +std::vector<Test::Result> Validate_Name_Constraint_NoCheckSelf::run() + { + if(Botan::has_filesystem_impl() == false) + { + return {Test::Result::Note("Path validation", + "Skipping due to missing filesystem access")}; + } + + std::vector<Test::Result> results; + + const std::string root_crt = Test::data_file("/x509/misc/nc_skip_self/root.pem"); + const std::string int_crt = Test::data_file("/x509/misc/nc_skip_self/int.pem"); + const std::string ee_crt = Test::data_file("/x509/misc/nc_skip_self/leaf.pem"); + + auto validation_time = + Botan::calendar_point(2021, 5, 8, 1, 0, 0).to_std_timepoint(); + + Botan::X509_Certificate root(root_crt); + Botan::X509_Certificate intermediate(int_crt); + Botan::X509_Certificate ee_cert(ee_crt); + + Botan::Certificate_Store_In_Memory trusted; + trusted.add_certificate(root); + + std::vector<Botan::X509_Certificate> chain = { ee_cert, intermediate }; + + Botan::Path_Validation_Restrictions restrictions; + Botan::Path_Validation_Result validation_result = + Botan::x509_path_validate(chain, restrictions, trusted, "", + Botan::Usage_Type::UNSPECIFIED, validation_time); + + Test::Result result("Name constraints do not apply to the certificate which includes them"); + result.test_eq("Path validation succeeded", + validation_result.successful_validation(), true); + + return {result}; + } + +BOTAN_REGISTER_TEST("x509", "x509_name_constraint_no_check_self", Validate_Name_Constraint_NoCheckSelf); + class BSI_Path_Validation_Tests final : public Test { |