-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#566] Switch to pyOpenSSL for validating certificate chain
- Loading branch information
1 parent
8ad73ec
commit 95dcccf
Showing
5 changed files
with
209 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
tests/plugins_tests/certificate_info/test_cert_chain_analyzer.py
This file was deleted.
Oops, something went wrong.
145 changes: 145 additions & 0 deletions
145
tests/plugins_tests/certificate_info/test_trust_store.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
from datetime import datetime | ||
|
||
from sslyze import TrustStore | ||
from sslyze.plugins.certificate_info.trust_stores.trust_store_repository import TrustStoresRepository | ||
|
||
|
||
GOOGLE_DOT_COM_CERT_CHAIN_ON_11_2022 = [ | ||
# www.google.com | ||
"""-----BEGIN CERTIFICATE----- | ||
MIIEhjCCA26gAwIBAgIRAIGnSAxq9cl3Enfafpo9aMEwDQYJKoZIhvcNAQELBQAw | ||
RjELMAkGA1UEBhMCVVMxIjAgBgNVBAoTGUdvb2dsZSBUcnVzdCBTZXJ2aWNlcyBM | ||
TEMxEzARBgNVBAMTCkdUUyBDQSAxQzMwHhcNMjIxMDE3MDgxODU3WhcNMjMwMTA5 | ||
MDgxODU2WjAZMRcwFQYDVQQDEw53d3cuZ29vZ2xlLmNvbTBZMBMGByqGSM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JmDbMR0PDXBrYRIrWGGiR99e+zbD | ||
beKwUoJbWfFJf4weWLEXLdKOcAGJT6nWT46Y2KRGfZ520W+AlqU3+QVshVTmSoub | ||
/k93A4QKLODRns2567ulr7tRgerFwf4GpODsPMz0Nsdh/EIWgQaeK1dLjE5D64WB | ||
tC1b0D2/JxFiD1BjXMCkYToe2/ltqCY1SHSCjGIBTFO1dLiG353k1jDRwxfXZOA4 | ||
I7Ei1SA5Jz3My5rX3vReT8mf4JHiFw35+YFPN/ppfQbhKRq4q1mOpnQUPn3fuX5i | ||
NRIMSi+Bf8U56Q== | ||
-----END CERTIFICATE-----""", | ||
# GTS CA 1C3 | ||
"""-----BEGIN CERTIFICATE----- | ||
MIIFljCCA36gAwIBAgINAgO8U1lrNMcY9QFQZjANBgkqhkiG9w0BAQsFADBHMQsw | ||
CQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZpY2VzIExMQzEU | ||
MBIGA1UEAxMLR1RTIFJvb3QgUjEwHhcNMjAwODEzMDAwMDQyWhcNMjcwOTMwMDAw | ||
MDQyWjBGMQswCQYDVQQGEwJVUzEiMCAGA1UEChMZR29vZ2xlIFRydXN0IFNlcnZp | ||
Y2VzIExMQzETMBEGA1UEAxMKR1RTIENBIDFDMzCCASIwDQYJKoZIhvcNAQEBBQAD | ||
ggEPADCCAQoCggEBAPWI3+dijB43+DdCkH9sh9D7ZYIl/ejLa6T/belaI+KZ9hzp | ||
kgOZE3wJCor6QtZeViSqejOEH9Hpabu5dOxXTGZok3c3VVP+ORBNtzS7XyV3NzsX | ||
lOo85Z3VvMO0Q+sup0fvsEQRY9i0QYXdQTBIkxu/t/bgRQIh4JZCF8/ZK2VWNAcm | ||
BA2o/X3KLu/qSHw3TT8An4Pf73WELnlXXPxXbhqW//yMmqaZviXZf5YsBvcRKgKA | ||
gOtjGDxQSYflispfGStZloEAoPtR28p3CwvJlk/vcEnHXG0g/Zm0tOLKLnf9LdwL | ||
tmsTDIwZKx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k+gB9lm+cZv9TSjO | ||
z23HFtz30dZGm6fKa+l3D/2gthsjgx0QGtkJAITgRNOidSOzNIb2ILCkXhAd4FJG | ||
AJ2xDx8hcFH1mt0G/FX0Kw4zd8NLQsLxdxP8c4CU6x+7Nz/OAipmsHMdMqUybDKw | ||
juDEI/9bfU1lcKwrmz3O2+BtjjKAvpafkmO8l7tdufThcV4q5O8DIrGKZTqPwJNl | ||
1IXNDw9bg1kWRxYtnCQ6yICmJhSFm/Y3m6xv+cXDBlHz4n/FsRC6UfTd | ||
-----END CERTIFICATE-----""", | ||
# GTS Root R1 | ||
"""-----BEGIN CERTIFICATE----- | ||
MIIFYjCCBEqgAwIBAgIQd70NbNs2+RrqIQ/E8FjTDTANBgkqhkiG9w0BAQsFADBX | ||
MQswCQYDVQQGEwJCRTEZMBcGA1UEChMQR2xvYmFsU2lnbiBudi1zYTEQMA4GA1UE | ||
CxMHUm9vdCBDQTEbMBkGA1UEAxMSR2xvYmFsU2lnbiBSb290IENBMB4XDTIwMDYx | ||
OTAwMDA0MloXDTI4MDEyODAwMDA0MlowRzELMAkGA1UEBhMCVVMxIjAgBgNVBAoT | ||
GUdvb2dsZSBUcnVzdCBTZXJ2aWNlcyBMTEMxFDASBgNVBAMTC0dUUyBSb290IFIx | ||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAthECix7joXebO9y/lD63 | ||
ladAPKH9gvl9MgaCcfb2jH/76Nu8ai6Xl6OMS/kr9rH5zoQdsfnFl97vufKj6bwS | ||
iV6nqlKr+CMny6SxnGPb15l+8Ape62im9MZaRw1NEDPjTrETo8gYbEvs/AmQ351k | ||
KSUjB6G00j0uYODP0gmHu81I8E3CwnqIiru6z1kZ1q+PsAewnjHxgsHA3y6mbWwZ | ||
DrXYfiYaRQM9sHmklCitD38m5agI/pboPGiUU+6DOogrFZYJsuB6jC511pzrp1Zk | ||
j5ZPaK49l8KEj8C8QMALXL32h7M1bKwYUH+E4EzNktMg6TO8UpmvMrU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QJVj2fhMtfTJr9w4z30Z209fOU0iOMy | ||
+qduBmpvvYuR7hZL6Dupszfnw0Skfths18dG9ZKb59UhvmaSGZRVbNQpsg3BZlvi | ||
d0lIKO2d1xozclOzgjXPYovJJIultzkMu34qQb9Sz/yilrbCgj8= | ||
-----END CERTIFICATE-----""" | ||
] | ||
|
||
|
||
def _create_trust_store() -> TrustStore: | ||
return TrustStore( | ||
path=TrustStoresRepository._DEFAULT_TRUST_STORES_PATH / "mozilla_nss.pem", | ||
name="Mozilla", | ||
version="123", | ||
ev_oids=[] | ||
) | ||
|
||
|
||
class TestTrustStore: | ||
|
||
def test_verify_certificate_chain(self): | ||
# Given a trust store and a certificate chain to verify | ||
trust_store = _create_trust_store() | ||
certificate_chain_as_pem = GOOGLE_DOT_COM_CERT_CHAIN_ON_11_2022 | ||
|
||
# And at the time of the verification, the certificate chain is expected to be valid | ||
trust_store._x509_store.set_time(datetime(year=2022, month=11, day=6)) | ||
|
||
# When running the verification, it succeeds | ||
result = trust_store.verify_certificate_chain(certificate_chain_as_pem) | ||
|
||
# And the certificate chain was reported as being valid | ||
assert result.was_validation_successful | ||
assert result.verified_certificate_chain | ||
assert result.openssl_error_string is None | ||
|
||
def test_verify_certificate_chain_but_verification_fails(self): | ||
# Given a trust store and a certificate chain to verify | ||
trust_store = _create_trust_store() | ||
certificate_chain_as_pem = GOOGLE_DOT_COM_CERT_CHAIN_ON_11_2022 | ||
|
||
# And at the time of the verification, the certificate chain is expected to be INVALID | ||
trust_store._x509_store.set_time(datetime(year=2030, month=1, day=1)) | ||
|
||
# When running the verification, it succeeds | ||
result = trust_store.verify_certificate_chain(certificate_chain_as_pem) | ||
|
||
# And the certificate chain was reported as being INVALID | ||
assert not result.was_validation_successful | ||
assert not result.verified_certificate_chain | ||
assert result.openssl_error_string |