| 1 |
# Copyright (c) Jean-Paul Calderone |
| 2 |
# See LICENSE file for details. |
| 3 |
|
| 4 |
""" |
| 5 |
Unit tests for :py:mod:`OpenSSL.crypto`. |
| 6 |
""" |
| 7 |
|
| 8 |
from __future__ import annotations |
| 9 |
|
| 10 |
import base64 |
| 11 |
import pathlib |
| 12 |
import sys |
| 13 |
import typing |
| 14 |
from datetime import datetime, timedelta, timezone |
| 15 |
from subprocess import PIPE, Popen |
| 16 |
|
| 17 |
import pytest |
| 18 |
from cryptography import x509 |
| 19 |
from cryptography.hazmat.primitives import hashes, serialization |
| 20 |
from cryptography.hazmat.primitives.asymmetric import ( |
| 21 |
dsa, |
| 22 |
ec, |
| 23 |
ed448, |
| 24 |
ed25519, |
| 25 |
rsa, |
| 26 |
) |
| 27 |
|
| 28 |
from OpenSSL._util import ffi as _ffi |
| 29 |
from OpenSSL._util import lib as _lib |
| 30 |
from OpenSSL.crypto import ( |
| 31 |
FILETYPE_ASN1, |
| 32 |
FILETYPE_PEM, |
| 33 |
FILETYPE_TEXT, |
| 34 |
TYPE_DSA, |
| 35 |
TYPE_RSA, |
| 36 |
X509, |
| 37 |
Error, |
| 38 |
PKey, |
| 39 |
X509Name, |
| 40 |
X509Store, |
| 41 |
X509StoreContext, |
| 42 |
X509StoreContextError, |
| 43 |
X509StoreFlags, |
| 44 |
_EllipticCurve, |
| 45 |
_Key, |
| 46 |
_PrivateKey, |
| 47 |
dump_certificate, |
| 48 |
dump_privatekey, |
| 49 |
dump_publickey, |
| 50 |
get_elliptic_curve, |
| 51 |
get_elliptic_curves, |
| 52 |
load_certificate, |
| 53 |
load_privatekey, |
| 54 |
load_publickey, |
| 55 |
) |
| 56 |
|
| 57 |
from . import conftest |
| 58 |
from .util import ( |
| 59 |
NON_ASCII, |
| 60 |
) |
| 61 |
|
| 62 |
|
| 63 |
def normalize_privatekey_pem(pem: bytes) -> bytes: |
| 64 |
return dump_privatekey(FILETYPE_PEM, load_privatekey(FILETYPE_PEM, pem)) |
| 65 |
|
| 66 |
|
| 67 |
def utcnow() -> datetime: |
| 68 |
return datetime.now(timezone.utc).replace(tzinfo=None) |
| 69 |
|
| 70 |
|
| 71 |
GOOD_CIPHER = "aes-256-cbc" |
| 72 |
BAD_CIPHER = "zippers" |
| 73 |
|
| 74 |
GOOD_DIGEST = "SHA256" |
| 75 |
BAD_DIGEST = "monkeys" |
| 76 |
|
| 77 |
old_root_cert_pem = b"""-----BEGIN CERTIFICATE----- |
| 78 |
MIIC7TCCAlagAwIBAgIIPQzE4MbeufQwDQYJKoZIhvcNAQEFBQAwWDELMAkGA1UE |
| 79 |
BhMCVVMxCzAJBgNVBAgTAklMMRAwDgYDVQQHEwdDaGljYWdvMRAwDgYDVQQKEwdU |
| 80 |
ZXN0aW5nMRgwFgYDVQQDEw9UZXN0aW5nIFJvb3QgQ0EwIhgPMjAwOTAzMjUxMjM2 |
| 81 |
NThaGA8yMDE3MDYxMTEyMzY1OFowWDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAklM |
| 82 |
MRAwDgYDVQQHEwdDaGljYWdvMRAwDgYDVQQKEwdUZXN0aW5nMRgwFgYDVQQDEw9U |
| 83 |
ZXN0aW5nIFJvb3QgQ0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAPmaQumL |
| 84 |
urpE527uSEHdL1pqcDRmWzu+98Y6YHzT/J7KWEamyMCNZ6fRW1JCR782UQ8a07fy |
| 85 |
2xXsKy4WdKaxyG8CcatwmXvpvRQ44dSANMihHELpANTdyVp6DCysED6wkQFurHlF |
| 86 |
1dshEaJw8b/ypDhmbVIo6Ci1xvCJqivbLFnbAgMBAAGjgbswgbgwHQYDVR0OBBYE |
| 87 |
FINVdy1eIfFJDAkk51QJEo3IfgSuMIGIBgNVHSMEgYAwfoAUg1V3LV4h8UkMCSTn |
| 88 |
VAkSjch+BK6hXKRaMFgxCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJJTDEQMA4GA1UE |
| 89 |
BxMHQ2hpY2FnbzEQMA4GA1UEChMHVGVzdGluZzEYMBYGA1UEAxMPVGVzdGluZyBS |
| 90 |
b290IENBggg9DMTgxt659DAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GB |
| 91 |
AGGCDazMJGoWNBpc03u6+smc95dEead2KlZXBATOdFT1VesY3+nUOqZhEhTGlDMi |
| 92 |
hkgaZnzoIq/Uamidegk4hirsCT/R+6vsKAAxNTcBjUeZjlykCJWy5ojShGftXIKY |
| 93 |
w/njVbKMXrvc83qmTdGl3TAM0fxQIpqgcglFLveEBgzn |
| 94 |
-----END CERTIFICATE----- |
| 95 |
""" |
| 96 |
|
| 97 |
root_cert_pem = b"""-----BEGIN CERTIFICATE----- |
| 98 |
MIIE7jCCA1agAwIBAgIIPQzE4MbeufQwDQYJKoZIhvcNAQELBQAwWDELMAkGA1UE |
| 99 |
BhMCVVMxCzAJBgNVBAgTAklMMRAwDgYDVQQHEwdDaGljYWdvMRAwDgYDVQQKEwdU |
| 100 |
ZXN0aW5nMRgwFgYDVQQDEw9UZXN0aW5nIFJvb3QgQ0EwHhcNMjAwODAyMTcxMTE5 |
| 101 |
WhcNNDcxMjIwMTcxMTE5WjBYMQswCQYDVQQGEwJVUzELMAkGA1UECBMCSUwxEDAO |
| 102 |
BgNVBAcTB0NoaWNhZ28xEDAOBgNVBAoTB1Rlc3RpbmcxGDAWBgNVBAMTD1Rlc3Rp |
| 103 |
bmcgUm9vdCBDQTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALpY5jb+ |
| 104 |
S7AUbx9gzN06wkqUeb+eNLTjCOKofiMTn8Y0TqCA2ZyY3XMcNBMaIS7hdFTgmmqt |
| 105 |
fFntYobxLAl/twfbz9AnRaVDh2HyUvHvMBxKn1HSDLALLtqdF0pcXIjP04S7NKPQ |
| 106 |
Umgkv2H0KwcUpYlgjTFtXRiP+7wDSiQeP1YVSriEoE0TXK14F8np6ZKK0oQ+u16d |
| 107 |
Wn3MGQwFzS+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qK25x3AuIWf4JOL |
| 122 |
3cTNjJ/3zmGSORRJvcGyvVnL30R+vwpaxvyuqMjz3kBjkK2Z2pvElZMJiZhbGG7k |
| 123 |
MHZQ5A26v0/iQVno6FRv3cQb9EeAZtNHcIEgsNhPZ53XVnwZ58ByvATMLKNN8dWF |
| 124 |
Q+8Bbr7QFxeWvQfHYX2yaQZ/ |
| 125 |
-----END CERTIFICATE----- |
| 126 |
""" |
| 127 |
|
| 128 |
root_key_pem = b"""-----BEGIN RSA PRIVATE KEY----- |
| 129 |
MIIG5AIBAAKCAYEAuljmNv5LsBRvH2DM3TrCSpR5v540tOMI4qh+IxOfxjROoIDZ |
| 130 |
nJjdcxw0ExohLuF0VOCaaq18We1ihvEsCX+3B9vP0CdFpUOHYfJS8e8wHEqfUdIM |
| 131 |
sAsu2p0XSlxciM/ThLs0o9BSaCS/YfQrBxSliWCNMW1dGI/7vANKJB4/VhVKuISg |
| 132 |
TRNcrXgXyenpkorShD67Xp1afcwZDAXNL4imCjPSNuLkPYrOYrZ3Md3FjwzYOS2T |
| 133 |
P9bcNR9TBpOiFh53YMbf0s81QU7F6SBd0hne9BsN+wRC3btNTM7O1uj8GortiREv |
| 134 |
PM5AXP50oDEfofLoG72int4NZL1N8P/5SYPGvch6gsymZQErGbNMLiql6P5bVS4I |
| 135 |
TXZ0yjguhp2WQb7+XWgAGp1Rx/jlaBoWTfGnIS4acPGOzqupg+gRqkiJyHE3Z+A3 |
| 136 |
6OSAf153jivTI6hV4bambANgUILHOSaK7MsAOV8zUtTOpQ0pUVw5qQPeK6McRqWc |
| 137 |
Mgmxz/OdiyppG8KRAgMBAAECggGAGi6Tafagu8SjOE1pe0veMIxb7shTr3aWsQHr |
| 138 |
dxIyyK5gvbxc1tvDgYDc8DIjp2qV5bcI+yQU7K2lwj/waAVBuiDwOdbKukWap/Bc |
| 139 |
JxHsOI1jhSN2FOX9V0nrE8+WUMKifWuwIbQLYAaJvUGJKh2EhKDENcWf5uuT+v6b |
| 140 |
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P2WDIRvgd |
| 155 |
0NIskMESgJPDAI7sCgwrTlqMNe4VRHqeQ8vqYUWBVbtWKqhQ8LCBmTzT2nJ2ZhiZ |
| 156 |
cObqXofDGVJeZodc+rSnDbP7TDLpoh9G+txxT6R0jafCG86MrjWebJN0U3yCxrpe |
| 157 |
8QabO/DzbDq110YIyg3OHirwfDBBUkHB3sD9/4MQ7LECgcEAs2UFhxVIn4aO5ott |
| 158 |
+0G5lkYIQ6cwx9x64i3ugDvz2uruiunUJU0luTOXML2AUDRrzEmXokr0nBQnWlk4 |
| 159 |
2qOmuA3PfTx85iJLUab0vX69gyaDhnLLvMrBe8W62yELKXx076ouuI27yPNs3xFL |
| 160 |
vWzIkSzx+N0870i8LjPrjTgsZ8g8bfG1nTNhafaLDw/MPutReN7oLouKQs2w9MMr |
| 161 |
yPAR2qxBqIJe2uY4pdVy3bMPJWOG7MR74hs6By6HmKfKVuqVAoHBAMRSefX1QtfS |
| 162 |
3wWpQhkE7Sooco4LI8kfNncZ2gzNDbYf6aOkgzv0/SWJh+CdcKep9xk12O02Lpsm |
| 163 |
SsPYeYlPDCCvyJYGpR19QocYp6JCaemb7uMd6FuPHSHUgyoR4GS8PUuIbiRnpPxN |
| 164 |
4ta7VzmIZOCFu5e+vOq1NwTd0hR6sy5uNsTHV5ezOOqz2SB+yTRMDPr7cW0dMSJ8 |
| 165 |
jsvxvqVnkIhWeuP9GIb6XUhq74huGZ0Hpaxe6xG34QYiBpr/O3O/ew== |
| 166 |
-----END RSA PRIVATE KEY----- |
| 167 |
""" |
| 168 |
|
| 169 |
root_key_der = base64.b64decode( |
| 170 |
""" |
| 171 |
MIIG5AIBAAKCAYEAuljmNv5LsBRvH2DM3TrCSpR5v540tOMI4qh+IxOfxjROoIDZ |
| 172 |
nJjdcxw0ExohLuF0VOCaaq18We1ihvEsCX+3B9vP0CdFpUOHYfJS8e8wHEqfUdIM |
| 173 |
sAsu2p0XSlxciM/ThLs0o9BSaCS/YfQrBxSliWCNMW1dGI/7vANKJB4/VhVKuISg |
| 174 |
TRNcrXgXyenpkorShD67Xp1afcwZDAXNL4imCjPSNuLkPYrOYrZ3Md3FjwzYOS2T |
| 175 |
P9bcNR9TBpOiFh53YMbf0s81QU7F6SBd0hne9BsN+wRC3btNTM7O1uj8GortiREv |
| 176 |
PM5AXP50oDEfofLoG72int4NZL1N8P/5SYPGvch6gsymZQErGbNMLiql6P5bVS4I |
| 177 |
TXZ0yjguhp2WQb7+XWgAGp1Rx/jlaBoWTfGnIS4acPGOzqupg+gRqkiJyHE3Z+A3 |
| 178 |
6OSAf153jivTI6hV4bambANgUILHOSaK7MsAOV8zUtTOpQ0pUVw5qQPeK6McRqWc |
| 179 |
Mgmxz/OdiyppG8KRAgMBAAECggGAGi6Tafagu8SjOE1pe0veMIxb7shTr3aWsQHr |
| 180 |
dxIyyK5gvbxc1tvDgYDc8DIjp2qV5bcI+yQU7K2lwj/waAVBuiDwOdbKukWap/Bc |
| 181 |
JxHsOI1jhSN2FOX9V0nrE8+WUMKifWuwIbQLYAaJvUGJKh2EhKDENcWf5uuT+v6b |
| 182 |
VCfLzlR/gx1fSHUH+Hd/ICd1YdmPanVF7i09oZ8jhcTq51rTuWs+heerGdp+1O++ |
| 183 |
H4uBTnAHkUEOB1Iw7mXQTIRBqcntzob/TJrDKycdbFHEeRR0L1hALGEVftq7zI6F |
| 184 |
BA9caO1W7HkcVmeT6HATIEIGG5H7QAwSfZflJ/82ZXtDemqhBRVwQ2Fx/99wW3r9 |
| 185 |
puUvJyLbba7NCwL1+P9w8ebr00kFyYoy6rE1JjqlE+9ZHwakZUWTA1lMOGWNEkRS |
| 186 |
bKZNHgrngs2zk5qCYRllmsBZ3obdufnP/wyag+BFVniAIN3a08y46SYmgYTeLdBX |
| 187 |
/DHSZIKWI9rBiNg6Qw49N+06XwiBAoHBAOMZQbRT8hEffRFbxcsRdJ4dUCM1RAXV |
| 188 |
/IMLeVQgKEWETX3pCydpQ2v65fJPACfLLwwRMq4BX4YpJVHCk6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HmKfKVuqVAoHBAMRSefX1QtfS |
| 204 |
3wWpQhkE7Sooco4LI8kfNncZ2gzNDbYf6aOkgzv0/SWJh+CdcKep9xk12O02Lpsm |
| 205 |
SsPYeYlPDCCvyJYGpR19QocYp6JCaemb7uMd6FuPHSHUgyoR4GS8PUuIbiRnpPxN |
| 206 |
4ta7VzmIZOCFu5e+vOq1NwTd0hR6sy5uNsTHV5ezOOqz2SB+yTRMDPr7cW0dMSJ8 |
| 207 |
jsvxvqVnkIhWeuP9GIb6XUhq74huGZ0Hpaxe6xG34QYiBpr/O3O/ew==' |
| 208 |
""" |
| 209 |
) |
| 210 |
|
| 211 |
normalized_root_key_pem = normalize_privatekey_pem(root_key_pem) |
| 212 |
|
| 213 |
intermediate_cert_pem = b"""-----BEGIN CERTIFICATE----- |
| 214 |
MIIEXDCCAsSgAwIBAgIRAMPzhm6//0Y/g2pmnHR2C4cwDQYJKoZIhvcNAQELBQAw |
| 215 |
WDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAklMMRAwDgYDVQQHEwdDaGljYWdvMRAw |
| 216 |
DgYDVQQKEwdUZXN0aW5nMRgwFgYDVQQDEw9UZXN0aW5nIFJvb3QgQ0EwHhcNMjAw |
| 217 |
ODAyMTcxMTIwWhcNNDcxMjIwMTcxMTIwWjBmMRUwEwYDVQQDEwxpbnRlcm1lZGlh |
| 218 |
dGUxDDAKBgNVBAoTA29yZzERMA8GA1UECxMIb3JnLXVuaXQxCzAJBgNVBAYTAlVT |
| 219 |
MQswCQYDVQQIEwJDQTESMBAGA1UEBxMJU2FuIERpZWdvMIIBojANBgkqhkiG9w0B |
| 220 |
AQEFAAOCAY8AMIIBigKCAYEAo3rOxOVrdLdRsR1o0+JG7MRpCtMoafA63TM/DczL |
| 221 |
Q4jURv5MzyTE7FFdXq4xNJRYgD16vUavZluQGj30+5Lkt07CuO/BK3itl8UW+dsH |
| 222 |
p95gzBvgnj5AVZGkNOQ0Y4CbXO087Ywep7tpBfZ5fzURLeH+OH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 |
-----END CERTIFICATE----- |
| 239 |
""" |
| 240 |
|
| 241 |
intermediate_key_pem = b"""-----BEGIN RSA PRIVATE KEY----- |
| 242 |
MIIG4gIBAAKCAYEAo3rOxOVrdLdRsR1o0+JG7MRpCtMoafA63TM/DczLQ4jURv5M |
| 243 |
zyTE7FFdXq4xNJRYgD16vUavZluQGj30+5Lkt07CuO/BK3itl8UW+dsHp95gzBvg |
| 244 |
nj5AVZGkNOQ0Y4CbXO087Ywep7tpBfZ5fzURLeH+OHQGseEFZ5e0w8AzAarWu+Ez |
| 245 |
5RGpkaZ61iiJa53mAgkrjw+o83UrpDT2nrXiyR6Fx4K4eb1rarodWqGvjSkdT5MA |
| 246 |
4i0gDhsIBnTarPB+0KM8M7od8DkLsTHBt4rYYCHgCX1bWavzGlqPEw9hksK+LAbQ |
| 247 |
KD9J2AxYDkL0PAeUuvWMhxEmN6hXePiw63sJzukRunAvut5A2+42JMkWguDyqIvA |
| 248 |
jlCYcIyBvUbphP3qSFqww/hpZ2wh5UZOc1mzYJKR9MgI8/UhRJEJ7NyYpF24EJbi |
| 249 |
sjNE30ot8aM2/5cI5KevclcuPJWH8PjT/i1VnNpM4S8MqoPw6F+d75d/CtfI+LLf |
| 250 |
ns4k3G9I+Qgxmpa5AgMBAAECggGAc0i/V4qR5JUCPuyGaCVB7uXzTXbrIQoP+L2S |
| 251 |
0aCCFvX+/LGIaOt9E0mtln8wo+uZHZY9YAzg1EXtsRPQFzjXoY0hNFme15EamdSb |
| 252 |
B0e2dmMTz9w44l7z72PtcH8dkq224ilKthoB5Db9MP9HXrWFj9228QihT/9nWE5b |
| 253 |
Y0++qIZZN9TwS7HQ6q2EIlIj1ohbE0R0O0bH1ifixsGyyOlrLHkhzjgY74Dspy7o |
| 254 |
VGmA6wL7cIoyLU21NT1Kw4LUUvCk3MTd62gIg43qLsoLJ1AVZg9AmLmhZn4HiGZa |
| 255 |
tiE1+Iz70E+qxIXDQTip/EY4qe9HHYM2VccjlMQsLLCw5Y2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ctepEr9jX8KECgcAE2nk86XVkjUk3TNJX |
| 271 |
vWIjgEEYYGSgFfVnEGRaNpqtmPmFJsOZDU4EnFfx4iMidKq31hdmYPHsytIt12+2 |
| 272 |
WgsZuRWRCCeV5b9agUeWfsehEnMBOigUU7JA6OsCmrlDJm8Kd2xEIv5e1KSXEH0U |
| 273 |
1V6+x6t8u2+Bo3yIKOSqP/m3DnaSmc5H1AQEF3Zp1vN6ZKIeT5B3l2OTfYu8ZaR0 |
| 274 |
s+C/fuZYQGPRfuypJOkEKKgPSOJ9m/7wLNRGrWPUP3Th1IsCgcBb2O9ROv793a3x |
| 275 |
PtW4qzkqF69KKc2O/vT819NBQjGopQetOcsY3VHp0eJMv85ut4cCeqScAfdtFIiC |
| 276 |
ScnrBO4JtdE6FkTY1k8el1DrctrUR3PZ2rt3m5k2XfPDGEypH3BReD3dHUe2M99D |
| 277 |
+dceH46rKyMXQ2lLA3iyzGE6NyWUTZ6co35/Qm2n8lV9IG1CuX5HVAVrr2osLG93 |
| 278 |
zZvFSeTrN2MZvmelhS6aUJCV/PxiQPHlou8vLU6zzfPMSERTjOI= |
| 279 |
-----END RSA PRIVATE KEY----- |
| 280 |
""" |
| 281 |
|
| 282 |
server_cert_pem = b"""-----BEGIN CERTIFICATE----- |
| 283 |
MIIEKTCCApGgAwIBAgIJAJn/HpR21r/8MA0GCSqGSIb3DQEBCwUAMFgxCzAJBgNV |
| 284 |
BAYTAlVTMQswCQYDVQQIDAJJTDEQMA4GA1UEBwwHQ2hpY2FnbzEQMA4GA1UECgwH |
| 285 |
VGVzdGluZzEYMBYGA1UEAwwPVGVzdGluZyBSb290IENBMB4XDTIwMDgwMjE3MTEy |
| 286 |
MFoXDTQ3MTIyMDE3MTEyMFowGDEWMBQGA1UEAwwNbG92ZWx5IHNlcnZlcjCCAaIw |
| 287 |
DQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBAKU9txhKg6Nc0dVK9Vv4MYuYP6Hs |
| 288 |
oR483+wC53V8axk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ewN0XnI6lm+zPAVUAE8dZfgJmJR5ifZHYCuv96EX0RpYsddeik8UmjkZ2/ch |
| 304 |
vRzvRSNNxVC6Zoe6vKNUb89XMtJZqY80WxfWG3Z2Hwf9KvS+2KAH/6MiSMj0RI5F |
| 305 |
SCB2PMQm6DYXwM1EyA== |
| 306 |
-----END CERTIFICATE----- |
| 307 |
""" |
| 308 |
|
| 309 |
server_key_pem = normalize_privatekey_pem( |
| 310 |
b"""-----BEGIN RSA PRIVATE KEY----- |
| 311 |
MIIG5AIBAAKCAYEApT23GEqDo1zR1Ur1W/gxi5g/oeyhHjzf7ALndXxrGR/LZPKe |
| 312 |
sFK6Dwdql5IVbmPB3ByyNoPAQgC6Bl9GjPQ3W9H9DpM4UBifaFHCUCBRdWTc1ekM |
| 313 |
1X9BGWIa/GEsBWm+7VrgTF9Vmg5DI9rymiAOCtR0Hd61iaYUc1rT0u/WfIxlaLq3 |
| 314 |
vMfbB6rr8PGmbQFZ/5McVy6e/1M18CqYNXmpvG9pQ+G69Gk35fY3e16MHxYq35Sb |
| 315 |
MBdSLc/c6BiKZZfCrxGaitzWuTmP6SyXqpjBm+LutFWDVkAftsaFcL14RT/Vn2rb |
| 316 |
o6EA91PIkPSlz4b28zPpWKMtFdyAcFQ/T2VJ6rGc3FylahfqdF0afo+QOF7AczTm |
| 317 |
KoATdkedzyRIFxFfzlKhbl0Y6G+9ROzh49U1Oje8d1C9+1MMP4jetsWdhMpQDMdM |
| 318 |
9JYYTstUSJYn3hEpIANeC97SqryjfvtQydjtbdTKBJih3JRnb0HkR9nzwSkiz+Hk |
| 319 |
2iYO/lVxASgJY3WjAgMBAAECggGAJST2X5OAe9yFnri25vGn0YVr6G5U2YM9osQU |
| 320 |
W6iYOpGXGx4e5evyvyYfo+rGvoXWMjCRLwf2099t8bjBFzZeq1lM1VXqtraSPtUC |
| 321 |
JRjettDxg3Rb2jI85APVpR4C00SuEpT3DrPvfi3ukcTJ/DNwdKbFY2GI1WRr/HJS |
| 322 |
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| 337 |
Nzpd1zlEBbKHtsi+4tz4u0pPGOzAeoh/RXFJqDQD1VcwQzaeM8NbIxocrRx8F5EV |
| 338 |
p53nLQuEU1QZIsQiym1uy0rQhicYr+HE+V67Jx7JjuV+uw99mnrYVrUhxJ8axUF8 |
| 339 |
4hGXMQt2Y+NeGoWMAEyPuOWGbeQQZXjfpISrsrdhfa0CgcEAxqbdRBUpA3Tpu5Jl |
| 340 |
t00M1z5p9M2SFuE1ao61i5z3xrvsdGVbtefH+gRqcD85eYi+fpKrpc7oBGtmqnKF |
| 341 |
4f76YgAcZQeOnlekxLbxocWHRDnuv4wfvYO9uHwZ/fojg3ylbSwXXABSbZsi8o/O |
| 342 |
u7P5n9k0/Pfu4igBs6oxlMU0BaM4DnbwmCe8m+VYKykpud440kjaeJ+XfyanU0hC |
| 343 |
jhw+Iueoehr/KLYn6wJmaxJGP0c3DHh/3gOxcgdYn6VkawPBAoHBAMJ7jfxZJfBO |
| 344 |
i0gDsD9Kz3EkGI8HbBpgC2Cd9DGQR9qTZy1/l/ObM2jwNumJjoHsN8fkha1d6/3n |
| 345 |
01hA4LwLB/SLQHx+7k1749sH7m1FaczWa9eUxNkwFiVTBYIyvbekNfJogLX9pVow |
| 346 |
vEuNe+J8vxLt3gQJ1DUz+2Air8v//OIqQ+akDnPkwiqHDqynNNWO+jq708aUunVT |
| 347 |
TTvknsoT3qT8H/N1FwbCZ14eKV+bXHcv1lVrLdW/DnjDZRpMFa3LSg== |
| 348 |
-----END RSA PRIVATE KEY----- |
| 349 |
""" |
| 350 |
) |
| 351 |
|
| 352 |
intermediate_server_cert_pem = b"""-----BEGIN CERTIFICATE----- |
| 353 |
MIIEXTCCAsWgAwIBAgIRAPQFY9jfskSihdiNSNdt6GswDQYJKoZIhvcNAQELBQAw |
| 354 |
ZjEVMBMGA1UEAxMMaW50ZXJtZWRpYXRlMQwwCgYDVQQKEwNvcmcxETAPBgNVBAsT |
| 355 |
CG9yZy11bml0MQswCQYDVQQGEwJVUzELM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Hk8T145SH/fPao8oznf5ae4a6rK9PyZqT7Ix1 |
| 371 |
nnKGffbJs0dY+jlxmx/BPlbsGfTwPL6LexghjvbpbXWUdVLP3gAW6DPCtRd6lhWj |
| 372 |
JvgCkF2SnbQ7GgnPEYi8h09j0c6/sK6jLoNAatJyIlRGE1cdGYZVUlVW/xP6lYM0 |
| 373 |
Mi1KKl0ZXOne4vPTtnTBBqrpjdLydH3WM1IxdwSRbmF15OD6BWzzKV4IYUJ21GDh |
| 374 |
YrVrcIeN49pUoKVTTn0Sql8f8mXxJhJ54wo9TKdIGZeuwTZrfWjcjWghXgghXGoP |
| 375 |
RI/I5fk/OMu0Oc06/+xdwCBHCSge0/vxK6fhTu7PxmJhQcZF0sDZyb6LXm2feVkG |
| 376 |
6FsxnsvstVNO3oJdpa8daLs= |
| 377 |
-----END CERTIFICATE----- |
| 378 |
""" |
| 379 |
|
| 380 |
intermediate_server_key_pem = b"""-----BEGIN RSA PRIVATE KEY----- |
| 381 |
MIIG5AIBAAKCAYEAvdRxPHAKwxmogT7uWiWby3qVPQhhmQTgvu7aojrib0K/O252 |
| 382 |
qophlyumtmhtnGo+Gpzwg7cIVHadXPBlbGscJybqcDMmNVdQWtzhMuxVhgkvVC8p |
| 383 |
fGv3tUiLJJTvHrFatBCyoO2WtvSMfn0RgVszZ4yTZ8FPZfiHpgxeWrKsONkXpqkK |
| 384 |
Ve2R3EYkapHk8JOzhy+thbtOkiZy4mrRL4xEGC5mmuIz7A4rtxeup9E8VHNm09ey |
| 385 |
SlA9IAwMMA4YqXw5l+hUVjMbwoaiY5rSFwe2BhfYYIOzWDWZpjodrD1uCzTjUGgC |
| 386 |
kf1pDF6HLl19Tf0NwWgpITd0KNEVpHqvIID5/wvUXfFVoey9fjjcJgXT+GiV+ym1 |
| 387 |
OM13VPXPxZHmHWO1jSAn8RGBwllSANETeUSRMsTFL+e4ZV93CeWTGfL2Nu1inZhy |
| 388 |
NiNSQKEu1ODPiiaZ4h0F0O9K7wzBYcy1A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A0GCSqGSIb3 |
| 436 |
DQEBCwUAA4IBgQAhAEACc1j6EYoSfVJD8N/FlYfHRizdfVJyrmMnC8ID1vtfrU2z |
| 437 |
S2q+49ja2NyM4Sq+Cf+i+sFfzFG92LayZt9Mc1BnHZMdNzQL7Ynr2nDLxHsHzuYa |
| 438 |
N21/ucTpHEFGLmvQ/eWBMxQQ9TbiNXn+tnnqg46dRzN3vHJp+g5+ijtMcuh007z2 |
| 439 |
niiO8F07wlb960XviejWejMC8hBLWlA7i3EjAkDO8RFQnG2Py5cQX9GgmWH1sDy3 |
| 440 |
rIsWlU+e46ysSWK/bnudnAlzZMB9KJATVZu5+xmCumH2hLJv5vz+jnKcgU9MBZMO |
| 441 |
cKgNdFUbtRlU/gfTaohmLIuSquunCCrXLsLD8ygbKKXfSPGVo2XkvX3oxqUo6dmA |
| 442 |
LvU4N4sCQGiSzW+a13HBtk3TBZFsJSWUGSW/H7TVFiAonumJKRqRxMOkkB9JxX+V |
| 443 |
9LZBYuBLpOeK4wZ8BUSNlHKnGpDzl0DzdYrGlzWz0jXlLGZ8KMfXAn9h0mOZ+IyK |
| 444 |
eUlgMBYyAspCQzM= |
| 445 |
-----END CERTIFICATE----- |
| 446 |
""" |
| 447 |
|
| 448 |
client_key_pem = normalize_privatekey_pem( |
| 449 |
b"""-----BEGIN RSA PRIVATE KEY----- |
| 450 |
MIIG5AIBAAKCAYEAxgoXTjGNeuBUnCan4ieSxLY2DihIOJ5jADBrhyE/MGWRH82m |
| 451 |
h4QW8qcyqtnDz9arch4L7VDDOijhRI+MvQKJ6s83ZVcWzIuvgL2C1pT6Aea/xtRn |
| 452 |
bJVL123OxdNgf+rAf/ohV5nHYzowEHC1sVYFC/tQqHqGNWsDWJs0Lniv0/Nmv+gG |
| 453 |
E3a8e10V+MH8Y2G9aN2550Q/4xkmpCMpV3lBhbIkjZAbP3STJFDjcYswHQBNrVuj |
| 454 |
YT7hNjtFIqc1IXYBZx+lj3ydCdUu42d3kE1Ky5BaVkqf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jvL3KwH1LUaXVWwFMOM2n6zTk18XEXrNvp+E5QtPwpO5c4VlPr0cAC |
| 485 |
tTPAmbu6kVPlQ6mKiqlPAsfh0BD2mRVo2cTjZgDotKshb5uCHD8/PnCfOjCXFxOf |
| 486 |
DWjBuR73/r5Bj+ktRoD4V2SFdO6loJwH6B8rsBjD0NbAGs9otKvy+Q== |
| 487 |
-----END RSA PRIVATE KEY----- |
| 488 |
""" |
| 489 |
) |
| 490 |
|
| 491 |
encryptedPrivateKeyPEM = b"""-----BEGIN RSA PRIVATE KEY----- |
| 492 |
Proc-Type: 4,ENCRYPTED |
| 493 |
DEK-Info: DES-EDE3-CBC,9573604A18579E9E |
| 494 |
|
| 495 |
SHOho56WxDkT0ht10UTeKc0F5u8cqIa01kzFAmETw0MAs8ezYtK15NPdCXUm3X/2 |
| 496 |
a17G7LSF5bkxOgZ7vpXyMzun/owrj7CzvLxyncyEFZWvtvzaAhPhvTJtTIB3kf8B |
| 497 |
8+qRcpTGK7NgXEgYBW5bj1y4qZkD4zCL9o9NQzsKI3Ie8i0239jsDOWR38AxjXBH |
| 498 |
mGwAQ4Z6ZN5dnmM4fhMIWsmFf19sNyAML4gHenQCHhmXbjXeVq47aC2ProInJbrm |
| 499 |
+00TcisbAQ40V9aehVbcDKtS4ZbMVDwncAjpXpcncC54G76N6j7F7wL7L/FuXa3A |
| 500 |
fvSVy9n2VfF/pJ3kYSflLHH2G/DFxjF7dl0GxhKPxJjp3IJi9VtuvmN9R2jZWLQF |
| 501 |
tfC8dXgy/P9CfFQhlinqBTEwgH0oZ/d4k4NVFDSdEMaSdmBAjlHpc+Vfdty3HVnV |
| 502 |
rKXj//wslsFNm9kIwJGIgKUa/n2jsOiydrsk1mgH7SmNCb3YHgZhbbnq0qLat/HC |
| 503 |
gHDt3FHpNQ31QzzL3yrenFB2L9osIsnRsDTPFNi4RX4SpDgNroxOQmyzCCV6H+d4 |
| 504 |
o1mcnNiZSdxLZxVKccq0AfRpHqpPAFnJcQHP6xyT9MZp6fBa0XkxDnt9kNU8H3Qw |
| 505 |
7SJWZ69VXjBUzMlQViLuaWMgTnL+ZVyFZf9hTF7U/ef4HMLMAVNdiaGG+G+AjCV/ |
| 506 |
MbzjS007Oe4qqBnCWaFPSnJX6uLApeTbqAxAeyCql56ULW5x6vDMNC3dwjvS/CEh |
| 507 |
11n8RkgFIQA0AhuKSIg3CbuartRsJnWOLwgLTzsrKYL4yRog1RJrtw== |
| 508 |
-----END RSA PRIVATE KEY----- |
| 509 |
""" |
| 510 |
|
| 511 |
encryptedPrivateKeyPEMPassphrase = b"foobar" |
| 512 |
|
| 513 |
cleartextPrivateKeyPEM = """-----BEGIN PRIVATE KEY----- |
| 514 |
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMcRMugJ4kvkOEuT |
| 515 |
AvMFr9+3A6+HAB6nKYcXXZz93ube8rJpBZQEfWn73H10dQiQR/a+rhxYEeLy8dPc |
| 516 |
UkFcGR9miVkukJ59zex7iySJY76bdBD8gyx1LTKrkCstP2XHKEYqgbj+tm7VzJnY |
| 517 |
sQLqoaa5NeyWJnUC3MJympkAS7p3AgMBAAECgYAoBAcNqd75jnjaiETRgVUnTWzK |
| 518 |
PgMCJmwsob/JrSa/lhWHU6Exbe2f/mcGOQDFpesxaIcrX3DJBDkkc2d9h/vsfo5v |
| 519 |
JLk/rbHoItWxwuY5n5raAPeQPToKpTDxDrL6Ejhgcxd19wNht7/XSrYZ+dq3iU6G |
| 520 |
mOEvU2hrnfIW3kwVYQJBAP62G6R0gucNfaKGtHzfR3TN9G/DnCItchF+TxGTtpdh |
| 521 |
Cz32MG+7pirT/0xunekmUIp15QHdRy496sVxWTCooLkCQQDIEwXTAwhLNRGFEs5S |
| 522 |
jSkxNfTVeNiOzlG8jPBJJDAdlLt1gUqjZWnk9yU+itMSGi/6eeuH2n04FFk+SV/T |
| 523 |
7ryvAkB0y0ZDk5VOozX/p2rtc2iNm77A3N4kIdiTQuq4sZXhNgN0pwWwxke8jbcb |
| 524 |
8gEAnqwBwWt//locTxHu9TmjgT8pAkEAlbF16B0atXptM02QxT8MlN8z4gxaqu4/ |
| 525 |
RX2FwpOq1FcVsqMbvwj/o+ouGY8wwRiK0TMrQCf/DFhdNTcc1aqHzQJBAKWtq4LI |
| 526 |
uVZjCAuyrqEnt7R1bOiLrar+/ezJPY2z+f2rb1TGr31ztPeFvO3edLw+QdhzwJGp |
| 527 |
QKImYzqMe+zkIOQ= |
| 528 |
-----END PRIVATE KEY----- |
| 529 |
""" |
| 530 |
|
| 531 |
cleartextPublicKeyPEM = b"""-----BEGIN PUBLIC KEY----- |
| 532 |
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxszlc+b71LvlLS0ypt/l |
| 533 |
gT/JzSVJtnEqw9WUNGeiChywX2mmQLHEt7KP0JikqUFZOtPclNY823Q4pErMTSWC |
| 534 |
90qlUxI47vNJbXGRfmO2q6Zfw6SE+E9iUb74xezbOJLjBuUIkQzEKEFV+8taiRV+ |
| 535 |
ceg1v01yCT2+OjhQW3cxG42zxyRFmqesbQAUWgS3uhPrUQqYQUEiTmVhh4FBUKZ5 |
| 536 |
XIneGUpX1S7mXRxTLH6YzRoGFqRoc9A0BBNcoXHTWnxV215k4TeHMFYE5RG0KYAS |
| 537 |
8Xk5iKICEXwnZreIt3jyygqoOKsKZMK/Zl2VhMGhJR6HXRpQCyASzEG7bgtROLhL |
| 538 |
ywIDAQAB |
| 539 |
-----END PUBLIC KEY----- |
| 540 |
""" |
| 541 |
|
| 542 |
# A broken RSA private key which can be used to test the error path through |
| 543 |
# PKey.check. |
| 544 |
inconsistentPrivateKeyPEM = b"""-----BEGIN RSA PRIVATE KEY----- |
| 545 |
MIIBPAIBAAJBAKy+e3dulvXzV7zoTZWc5TzgApr8DmeQHTYC8ydfzH7EECe4R1Xh |
| 546 |
5kwIzOuuFfn178FBiS84gngaNcrFi0Z5fAkCAwEaAQJBAIqm/bz4NA1H++Vx5Ewx |
| 547 |
OcKp3w19QSaZAwlGRtsUxrP7436QjnREM3Bm8ygU11BjkPVmtrKm6AayQfCHqJoT |
| 548 |
zIECIQDW0BoMoL0HOYM/mrTLhaykYAVqgIeJsPjvkEhTFXWBuQIhAM3deFAvWNu4 |
| 549 |
nklUQ37XsCT2c9tmNt1LAT+slG2JOTTRAiAuXDtC/m3NYVwyHfFm+zKHRzHkClk2 |
| 550 |
HjubeEgjpj32AQIhAJqMGTaZVOwevTXvvHwNeH+vRWsAYU/gbx+OQB+7VOcBAiEA |
| 551 |
oolb6NMg/R3enNPvS1O4UU1H8wpaF77L4yiSWlE0p4w= |
| 552 |
-----END RSA PRIVATE KEY----- |
| 553 |
""" |
| 554 |
|
| 555 |
# certificate with NULL bytes in subjectAltName and common name |
| 556 |
|
| 557 |
nulbyteSubjectAltNamePEM = b"""-----BEGIN CERTIFICATE----- |
| 558 |
MIIE2DCCA8CgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBxTELMAkGA1UEBhMCVVMx |
| 559 |
DzANBgNVBAgMBk9yZWdvbjESMBAGA1UEBwwJQmVhdmVydG9uMSMwIQYDVQQKDBpQ |
| 560 |
eXRob24gU29mdHdhcmUgRm91bmRhdGlvbjEgMB4GA1UECwwXUHl0aG9uIENvcmUg |
| 561 |
RGV2ZWxvcG1lbnQxJDAiBgNVBAMMG251bGwucHl0aG9uLm9yZwBleGFtcGxlLm9y |
| 562 |
ZzEkMCIGCSqGSIb3DQEJARYVcHl0aG9uLWRldkBweXRob24ub3JnMB4XDTEzMDgw |
| 563 |
NzEzMTE1MloXDTEzMDgwNzEzMTI1MlowgcUxCzAJBgNVBAYTAlVTMQ8wDQYDVQQI |
| 564 |
DAZPcmVnb24xEjAQBgNVBAcMCUJlYXZlcnRvbjEjMCEGA1UECgwaUHl0aG9uIFNv |
| 565 |
ZnR3YXJlIEZvdW5kYXRpb24xIDAeBgNVBAsMF1B5dGhvbiBDb3JlIERldmVsb3Bt |
| 566 |
ZW50MSQwIgYDVQ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eimk |
| 581 |
kX4LxlEx5RAvpGB2zZVRGr6LobD9rVK91xuHYNIxxxfEGE8tCCWjp0+3ksri9SXx |
| 582 |
VHWBnbM9YaL32u3hxm8sYB/Yb8WSBavJCWJJqRStVRHM1koZlJmXNx2BX4vPo6iW |
| 583 |
RFEIPQsFZRLrtnCAiEhyT8bC2s/Njlu6ly9gtJZWSV46Q3ZjBL4q9sHKqZQ= |
| 584 |
-----END CERTIFICATE-----""" |
| 585 |
|
| 586 |
large_key_pem = b"""-----BEGIN RSA PRIVATE KEY----- |
| 587 |
MIIJYgIBAAKCAg4AtRua8eIeevRfsj+fkcHr1vmse7Kgb+oX1ssJAvCb1R7JQMnH |
| 588 |
hNDjDP6b3vEkZuPUzlDHymP+cNkXvvi4wJ4miVbO3+SeU4Sh+jmsHeHzGIXat9xW |
| 589 |
9PFtuPM5FQq8zvkY8aDeRYmYwN9JKu4/neMBCBqostYlTEWg+bSytO/qWnyHTHKh |
| 590 |
g0GfaDdqUQPsGQw+J0MgaYIjQOCVASHAPlzbDQLCtuOb587rwTLkZA2GwoHB/LyJ |
| 591 |
BwT0HHgBaiObE12Vs6wi2en0Uu11CiwEuK1KIBcZ2XbE6eApaZa6VH9ysEmUxPt7 |
| 592 |
TqyZ4E2oMIYaLPNRxuvozdwTlj1svI1k1FrkaXGc5MTjbgigPMKjIb0T7b/4GNzt |
| 593 |
DhP1LvAeUMnrEi3hJJrcJPXHPqS8/RiytR9xQQW6Sdh4LaA3f9MQm3WSevWage3G |
| 594 |
P8YcCLssOVKsArDjuA52NF5LmYuAeUzXprm4ITDi2oO+0iFBpFW6VPEK4A9vO0Yk |
| 595 |
M/6Wt6tG8zyWhaSH1zFUTwfQ9Yvjyt5w1lrUaAJuoTpwbMVZaDJaEhjOaXU0dyPQ |
| 596 |
jOsePDOQcU6dkeTWsQ3LsHPEEug/X6819TLG5mb3V7bvV9nPFBfTJSCEG794kr90 |
| 597 |
XgZfIN71FrdByxLerlbuJI21pPs/nZi9SXi9jAWeiS45/azUxMsyYgJArui+gjq7 |
| 598 |
sV1pWiBm6/orAgMBAAECggINQp5L6Yu+oIXBqcSjgq8tfF9M5hd30pLuf/EheHZf |
| 599 |
LA7uAqn2fVGFI2OInIJhXIOT5OxsAXO0xXfltzawZxIFpOFMqajj4F7aYjvSpw9V |
| 600 |
J4EdSiJ/zgv8y1qUdbwEZbHVThRZjoSlrtSzilonBoHZAE0mHtqMz7iRFSk1zz6t |
| 601 |
GunRrvo/lROPentf3TsvHquVNUYI5yaapyO1S7xJhecMIIYSb8nbsHI54FBDGNas |
| 602 |
6mFmpPwI/47/6HTwOEWupnn3NicsjrHzUInOUpaMig4cRR+aP5bjqg/ty8xI8AoN |
| 603 |
evEmCytiWTc+Rvbp1ieN+1jpjN18PjUk80/W7qioHUDt4ieLic8uxWH2VD9SCEnX |
| 604 |
Mpi9tA/FqoZ+2A/3m1OfrY6jiZVE2g+asi9lCK7QVWL39eK82H4rPvtp0/dyo1/i |
| 605 |
ZZz68TXg+m8IgEZcp88hngbkuoTTzpGE73QuPKhGA1uMIimDdqPPB5WP76q+03Oi |
| 606 |
IRR5DfZnqPERed49by0enJ7tKa/gFPZizOV8ALKr0Dp+vfAkxGDLPLBLd2A3//tw |
| 607 |
xg0Q/wltihHSBujv4nYlDXdc5oYyMYZ+Lhc/VuOghHfBq3tgEQ1ECM/ofqXEIdy7 |
| 608 |
nVcpZn3Eeq8Jl5CrqxE1ee3NxlzsJHn99yGQpr7mOhW/psJF3XNz80Meg3L4m1T8 |
| 609 |
sMBK0GbaassuJhdzb5whAoIBBw48sx1b1WR4XxQc5O/HjHva+l16i2pjUnOUTcDF |
| 610 |
RWmSbIhBm2QQ2rVhO8+fak0tkl6ZnMWW4i0U/X5LOEBbC7+IS8bO3j3Revi+Vw5x |
| 611 |
j96LMlIe9XEub5i/saEWgiz7maCvfzLFU08e1OpT4qPDpP293V400ubA6R7WQTCv |
| 612 |
pBkskGwHeu0l/TuKkVqBFFUTu7KEbps8Gjg7MkJa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ZLaPPNEQDJ5lOxD6uMziWGl2rg8tj+1xNMWfxiPz |
| 628 |
aTCjoe4EoBUMoTq2gwzRcM2usEQNikXVhnj9Wzaivsaeb4bJ3GRPW5DkrO6JSEtT |
| 629 |
w+gvyMqQM2Hy5k7E7BT46sXVwaj/jZxuqGnebRixXtnp0WixdRIqYWUr1UqLf6hQ |
| 630 |
G7WP2BgoxCMaCmNW8+HMD/xuxucEotoIhZ+GgJKBFoNnjl3BX+qxYdSe9RbL/5Tr |
| 631 |
4It6Jxtj8uETJXEbv9Cg6v1agWPS9YY8RLTBAoIBBwrU2AsAUts6h1LgGLKK3UWZ |
| 632 |
oLH5E+4o+7HqSGRcRodVeN9NBXIYdHHOLeEG6YNGJiJ3bFP5ZQEu9iDsyoFVKJ9O |
| 633 |
Mw/y6dKZuxOCZ+X8FopSROg3yWfdOpAm6cnQZp3WqLNX4n/Q6WvKojfyEiPphjwT |
| 634 |
0ymrUJELXLWJmjUyPoAk6HgC0Gs28ZnEXbyhx7CSbZNFyCU/PNUDZwto3GisIPD3 |
| 635 |
le7YjqHugezmjMGlA0sDw5aCXjfbl74vowRFYMO6e3ItApfSRgNV86CDoX74WI/5 |
| 636 |
AYU/QVM4wGt8XGT2KwDFJaxYGKsGDMWmXY04dS+WPuetCbouWUusyFwRb9SzFave |
| 637 |
vYeU7Ab/ |
| 638 |
-----END RSA PRIVATE KEY-----""" |
| 639 |
|
| 640 |
ec_private_key_pem = b"""-----BEGIN PRIVATE KEY----- |
| 641 |
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgYirTZSx+5O8Y6tlG |
| 642 |
cka6W6btJiocdrdolfcukSoTEk+hRANCAAQkvPNu7Pa1GcsWU4v7ptNfqCJVq8Cx |
| 643 |
zo0MUVPQgwJ3aJtNM1QMOQUayCrRwfklg+D/rFSUwEUqtZh7fJDiFqz3 |
| 644 |
-----END PRIVATE KEY----- |
| 645 |
""" |
| 646 |
ec_public_key_pem = b"""-----BEGIN PUBLIC KEY----- |
| 647 |
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJLzzbuz2tRnLFlOL+6bTX6giVavA |
| 648 |
sc6NDFFT0IMCd2ibTTNUDDkFGsgq0cH5JYPg/6xUlMBFKrWYe3yQ4has9w== |
| 649 |
-----END PUBLIC KEY----- |
| 650 |
""" |
| 651 |
|
| 652 |
ec_root_key_pem = b"""-----BEGIN EC PRIVATE KEY----- |
| 653 |
MIGlAgEBBDEAz/HOBFPYLB0jLWeTpJn4Yc4m/C4mdWymVHBjOmnwiPHKT326iYN/ |
| 654 |
ZhmSs+RM94RsoAcGBSuBBAAioWQDYgAEwE5vDdla/nLpWAPAQ0yFGqwLuw4BcN2r |
| 655 |
U+sKab5EAEHzLeceRa8ffncYdCXNoVsBcdob1y66CFZMEWLetPTmGapyWkBAs6/L |
| 656 |
8kUlkU9OsE+7IVo4QQJkgV5gM+Dim1XE |
| 657 |
-----END EC PRIVATE KEY----- |
| 658 |
""" |
| 659 |
|
| 660 |
ec_root_cert_pem = b"""-----BEGIN CERTIFICATE----- |
| 661 |
MIICLTCCAbKgAwIBAgIMWW/hwTl6ufz6/WkCMAoGCCqGSM49BAMDMFgxGDAWBgNV |
| 662 |
BAMTD1Rlc3RpbmcgUm9vdCBDQTEQMA4GA1UEChMHVGVzdGluZzEQMA4GA1UEBxMH |
| 663 |
Q2hpY2FnbzELMAkGA1UECBMCSUwxCzAJBgNVBAYTAlVTMCAXDTE3MDcxOTIyNDgz |
| 664 |
M1oYDzk5OTkxMjMxMjM1OTU5WjBYMRgwFgYDVQQDEw9UZXN0aW5nIFJvb3QgQ0Ex |
| 665 |
EDAOBgNVBAoTB1Rlc3RpbmcxEDAOBgNVBAcTB0NoaWNhZ28xCzAJBgNVBAgTAklM |
| 666 |
MQswCQYDVQQGEwJVUzB2MBAGByqGSM49AgEGBSuBBAAiA2IABMBObw3ZWv5y6VgD |
| 667 |
wENMhRqsC7sOAXDdq1PrCmm+RABB8y3nHkWvH353GHQlzaFbAXHaG9cuughWTBFi |
| 668 |
3rT05hmqclpAQLOvy/JFJZFPTrBPuyFaOEECZIFeYDPg4ptVxKNDMEEwDwYDVR0T |
| 669 |
AQH/BAUwAwEB/zAPBgNVHQ8BAf8EBQMDBwQAMB0GA1UdDgQWBBSoTrF0H2m8RDzB |
| 670 |
MnY2KReEPfz7ZjAKBggqhkjOPQQDAwNpADBmAjEA3+G1oVCxGjYX4iUN93QYcNHe |
| 671 |
e3fJQJwX9+KsHRut6qNZDUbvRbtO1YIAwB4UJZjwAjEAtXCPURS5A4McZHnSwgTi |
| 672 |
Td8GMrwKz0557OxxtKN6uVVy4ACFMqEw0zN/KJI1vxc9 |
| 673 |
-----END CERTIFICATE-----""" |
| 674 |
|
| 675 |
rsa_p_not_prime_pem = """ |
| 676 |
-----BEGIN RSA PRIVATE KEY----- |
| 677 |
MBsCAQACAS0CAQcCAQACAQ8CAQMCAQACAQACAQA= |
| 678 |
-----END RSA PRIVATE KEY----- |
| 679 |
""" |
| 680 |
|
| 681 |
dsa_private_key_pem = b"""-----BEGIN PRIVATE KEY----- |
| 682 |
MIICZAIBADCCAjkGByqGSM44BAEwggIsAoIBAQD7UzdlshSCIIuntch43VmfCX1+ |
| 683 |
WQDTvGw83sRZcN+B7nwFn4dm2PU8cby17oCjX7buBvalVqofnUokrSIDA6Rozm/f |
| 684 |
2wpGR9oVpd0xh9cI50pw1G3RZ4lcNWTP8C8O20eIzJoCH1KElcWLCHLAa3XoGOMv |
| 685 |
p4XnbVgMdc9/ydt4qttzIVPV4cZoVObzixoKCgwHyVPDxe0JaCe2cIwxyQY0IwAI |
| 686 |
PfaUWEAo+bf7pOosdnatJYm9MkKe8bEgKGQcUl9S8FXLhRejMo+oobcRjuBHTAmY |
| 687 |
fuV1iGlLrkFNrc2O6M1CRZhOoddoy53IeHcSjfzKET1biE3tCOUdHjUnABqfAiEA |
| 688 |
1llvauVKMLvFCDatVKRY+zNGJaa5dwff4qDtodz6sa8CggEAd+btod0di21mqFaf |
| 689 |
vc1ddmLK74PddMseT8DmoN/YduJaGLAOOVJ61rdG+KPXIar+8X5yqXfzP0MiYGkE |
| 690 |
A+xpNIImC3rzHElYNa8imA7ud8f+oC5jQijp0GhzVIS4UW83rZwakX7LITNE9Oj9 |
| 691 |
FkETH1ZskHpp5BNlNoaSIW2+T7n/a+lq+tN60gP3f6FPBv5obB0pjqh+OAzEil/4 |
| 692 |
Ys0dtCB0022cCUCqThMhWewlE2W2JioDLV5QkD91NMQNQwljDONNcs94AaWeVONK |
| 693 |
RaBQXlFsJPHzS8uKpsFeusFTrHIeEJW/8GQp/tfXP1ajEdg5EGxOhXFkem4ZMIus |
| 694 |
YFTbWwQiAiBFtgi8aNV0Jz2o8T+cxjVqVEgGdYNQqmpzqqBsM5AEOw== |
| 695 |
-----END PRIVATE KEY----- |
| 696 |
""" |
| 697 |
dsa_public_key_pem = b"""-----BEGIN PUBLIC KEY----- |
| 698 |
MIIDRjCCAjkGByqGSM44BAEwggIsAoIBAQD7UzdlshSCIIuntch43VmfCX1+WQDT |
| 699 |
vGw83sRZcN+B7nwFn4dm2PU8cby17oCjX7buBvalVqofnUokrSIDA6Rozm/f2wpG |
| 700 |
R9oVpd0xh9cI50pw1G3RZ4lcNWTP8C8O20eIzJoCH1KElcWLCHLAa3XoGOMvp4Xn |
| 701 |
bVgMdc9/ydt4qttzIVPV4cZoVObzixoKCgwHyVPDxe0JaCe2cIwxyQY0IwAIPfaU |
| 702 |
WEAo+bf7pOosdnatJYm9MkKe8bEgKGQcUl9S8FXLhRejMo+oobcRjuBHTAmYfuV1 |
| 703 |
iGlLrkFNrc2O6M1CRZhOoddoy53IeHcSjfzKET1biE3tCOUdHjUnABqfAiEA1llv |
| 704 |
auVKMLvFCDatVKRY+zNGJaa5dwff4qDtodz6sa8CggEAd+btod0di21mqFafvc1d |
| 705 |
dmLK74PddMseT8DmoN/YduJaGLAOOVJ61rdG+KPXIar+8X5yqXfzP0MiYGkEA+xp |
| 706 |
NIImC3rzHElYNa8imA7ud8f+oC5jQijp0GhzVIS4UW83rZwakX7LITNE9Oj9FkET |
| 707 |
H1ZskHpp5BNlNoaSIW2+T7n/a+lq+tN60gP3f6FPBv5obB0pjqh+OAzEil/4Ys0d |
| 708 |
tCB0022cCUCqThMhWewlE2W2JioDLV5QkD91NMQNQwljDONNcs94AaWeVONKRaBQ |
| 709 |
XlFsJPHzS8uKpsFeusFTrHIeEJW/8GQp/tfXP1ajEdg5EGxOhXFkem4ZMIusYFTb |
| 710 |
WwOCAQUAAoIBAEe6z5ud1k4EDD9mLP7UYALWrgc1NXUlDynoYkjr+T/NVf1eaMdq |
| 711 |
0vFbGcEmz05UPUNXOhDH0szUDxQam3IE9C27ZO4SOquc0/rIhPY6i75SJW13P+cg |
| 712 |
gdXhDMTW5JOlyV6CPUoCWKOtn1ds3pTDuuWlZ89UzOWQUbC1si6vvz43zDyhfu6U |
| 713 |
owgIusPxowErm2sH66+MPa8fYxVX7ZJL0mEfubejrloAbo5unYI/bUYIhx4mtpP/ |
| 714 |
h/isFRifEAwG3yX6F9X/ZOYL53Z93EFPLJGRGMmQbkmXRA6lyvHdsC+OC/OCvPjW |
| 715 |
WfTXW9NHtUqpEks+OXBkyV971Hk5NvdLLr8= |
| 716 |
-----END PUBLIC KEY----- |
| 717 |
""" |
| 718 |
|
| 719 |
ed25519_private_key_pem = b"""-----BEGIN PRIVATE KEY----- |
| 720 |
MC4CAQAwBQYDK2VwBCIEIKlxBbhVsSURoLTmsu9uTqYH6oF7zpxmp1ZQCAPhDmI2 |
| 721 |
-----END PRIVATE KEY----- |
| 722 |
""" |
| 723 |
ed25519_public_key_pem = b"""-----BEGIN PUBLIC KEY----- |
| 724 |
MCowBQYDK2VwAyEAq+FrpdwI1oTPytx8kGzuLVc+78zJE7hjYG4E9hwXoKI= |
| 725 |
-----END PUBLIC KEY----- |
| 726 |
""" |
| 727 |
|
| 728 |
ed448_private_key_pem = b"""-----BEGIN PRIVATE KEY----- |
| 729 |
MEcCAQAwBQYDK2VxBDsEOcqZ7a3k6JwrJbYO8CNTPT/d7dlWCo5vCf0EYDj79ZvA\nhD8u9EPHlYJw5Y8ZQdH4WmVEfpKA23xkdQ== |
| 730 |
-----END PRIVATE KEY----- |
| 731 |
""" |
| 732 |
ed448_public_key_pem = b"""-----BEGIN PUBLIC KEY----- |
| 733 |
MEMwBQYDK2VxAzoAKFfWGCuqIaxgR9GmEXLRciYDyEjTnF56kr0sOVfwHEj+bHSU\neMJTZJR8qFSg8hNsHY1iZh9PIXcA |
| 734 |
-----END PUBLIC KEY----- |
| 735 |
""" |
| 736 |
|
| 737 |
rsa_private_key_pem = b"""-----BEGIN PRIVATE KEY----- |
| 738 |
MIIEuwIBADANBgkqhkiG9w0BAQEFAASCBKUwggShAgEAAoIBAQDZ5FaSaXKn/RTF |
| 739 |
xyNr+GRvYnMvLz5XxSDD4JzVRKXxKGFzKKXMJAeXJkvPlho7Ta/HgMNXhMPAe8TT |
| 740 |
wcIRnHJqAfmSOnka1ks3Kl6EGQBTevKzyJy8MaUhzZsL4FUUgWUETFQQT8Dwcghf |
| 741 |
JobV0k+bWT4mrKHzIquw5y+NTsaZl4jSB1labhImsU16Vj66fHp7w9+c501tOxQO |
| 742 |
M4CQNWioGm8tgPT/43QUs9e+L2HFBI+cDQbEC68l+7VM8YY8NZ/fGypoML2QMVnU |
| 743 |
Y6zneoOLJTMUulOubrL+J6DkuuhxBsIOcyxMnqwgKm4pUGlPxfPSS7+Mo3JC969k |
| 744 |
wgUHerXZAgMBAAECgf9qAzz/VMCQwnV1UxkhxH/8zgYgYL+fERFuPC/ZWv7wOicv |
| 745 |
xAjm9KC8zVb44fLE586CCc7IN+zNK9y0gB9eAGr/04RhEvWgbmoqF6wdtdNyynuE |
| 746 |
Ut4oQKn7AUc1uPAeCfM4slw0Pie98YSS/9ZhwH/eh3C10iwWA1aiLWeDrnryPuJN |
| 747 |
mNB0d/ZsaL+arhR/nU2sJixx5LDI6AG0GJrw3DBHEKb4vZPIU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roqon1nMq4C0aqr696ra0cgCfbK3 |
| 763 |
5yscAByxKd+64JZziDkZ |
| 764 |
-----END PRIVATE KEY----- |
| 765 |
""" |
| 766 |
rsa_public_key_pem = b"""-----BEGIN PUBLIC KEY----- |
| 767 |
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2eRWkmlyp/0Uxccja/hk |
| 768 |
b2JzLy8+V8Ugw+Cc1USl8ShhcyilzCQHlyZLz5YaO02vx4DDV4TDwHvE08HCEZxy |
| 769 |
agH5kjp5GtZLNypehBkAU3rys8icvDGlIc2bC+BVFIFlBExUEE/A8HIIXyaG1dJP |
| 770 |
m1k+Jqyh8yKrsOcvjU7GmZeI0gdZWm4SJrFNelY+unx6e8PfnOdNbTsUDjOAkDVo |
| 771 |
qBpvLYD0/+N0FLPXvi9hxQSPnA0GxAuvJfu1TPGGPDWf3xsqaDC9kDFZ1GOs53qD |
| 772 |
iyUzFLpTrm6y/ieg5LrocQbCDnMsTJ6sICpuKVBpT8Xz0ku/jKNyQvevZMIFB3q1 |
| 773 |
2QIDAQAB |
| 774 |
-----END PUBLIC KEY----- |
| 775 |
""" |
| 776 |
|
| 777 |
x25519_private_key_pem = b"""-----BEGIN PRIVATE KEY----- |
| 778 |
MC4CAQAwBQYDK2VuBCIEIPAjVfPNTm25VxtBRg+JjjFx9tA3M8aaBdVhjb92iBts |
| 779 |
-----END PRIVATE KEY----- |
| 780 |
""" |
| 781 |
|
| 782 |
|
| 783 |
@pytest.fixture |
| 784 |
def x509_data() -> tuple[PKey, X509]: |
| 785 |
""" |
| 786 |
Create a new private key and start a certificate request (for a test |
| 787 |
to finish in one way or another). |
| 788 |
""" |
| 789 |
# Basic setup stuff to generate a certificate |
| 790 |
pkey = PKey() |
| 791 |
pkey.generate_key(TYPE_RSA, 2048) |
| 792 |
x509 = X509() |
| 793 |
subject = x509.get_subject() |
| 794 |
# Authority good you have. |
| 795 |
subject.commonName = "Yoda root CA" |
| 796 |
x509.set_issuer(subject) |
| 797 |
x509.set_pubkey(pkey) |
| 798 |
now = datetime.now() |
| 799 |
expire = datetime.now() + timedelta(days=100) |
| 800 |
x509.set_notBefore(now.strftime("%Y%m%d%H%M%SZ").encode()) |
| 801 |
x509.set_notAfter(expire.strftime("%Y%m%d%H%M%SZ").encode()) |
| 802 |
return pkey, x509 |
| 803 |
|
| 804 |
|
| 805 |
class TestPKey: |
| 806 |
""" |
| 807 |
Tests for `OpenSSL.crypto.PKey`. |
| 808 |
""" |
| 809 |
|
| 810 |
@pytest.mark.parametrize( |
| 811 |
("key_string", "key_type"), |
| 812 |
[ |
| 813 |
(dsa_private_key_pem, dsa.DSAPrivateKey), |
| 814 |
(ec_private_key_pem, ec.EllipticCurvePrivateKey), |
| 815 |
pytest.param( |
| 816 |
ed25519_private_key_pem, |
| 817 |
ed25519.Ed25519PrivateKey, |
| 818 |
marks=pytest.mark.skipif( |
| 819 |
conftest.is_awslc, |
| 820 |
reason="aws-lc doesn't support Ed25519 serialization", |
| 821 |
), |
| 822 |
), |
| 823 |
pytest.param( |
| 824 |
ed448_private_key_pem, |
| 825 |
ed448.Ed448PrivateKey, |
| 826 |
marks=pytest.mark.skipif( |
| 827 |
conftest.is_awslc, |
| 828 |
reason="aws-lc doesn't support Ed448", |
| 829 |
), |
| 830 |
), |
| 831 |
(rsa_private_key_pem, rsa.RSAPrivateKey), |
| 832 |
], |
| 833 |
) |
| 834 |
def test_convert_roundtrip_cryptography_private_key( |
| 835 |
self, key_string: bytes, key_type: type[_Key] |
| 836 |
) -> None: |
| 837 |
""" |
| 838 |
PKey.from_cryptography_key creates a proper private PKey. |
| 839 |
PKey.to_cryptography_key creates a proper cryptography private key. |
| 840 |
""" |
| 841 |
key = serialization.load_pem_private_key(key_string, None) |
| 842 |
assert isinstance(key, key_type) |
| 843 |
assert isinstance( |
| 844 |
key, |
| 845 |
( |
| 846 |
dsa.DSAPrivateKey, |
| 847 |
ec.EllipticCurvePrivateKey, |
| 848 |
ed25519.Ed25519PrivateKey, |
| 849 |
ed448.Ed448PrivateKey, |
| 850 |
rsa.RSAPrivateKey, |
| 851 |
), |
| 852 |
) |
| 853 |
pkey = PKey.from_cryptography_key(key) |
| 854 |
|
| 855 |
assert isinstance(pkey, PKey) |
| 856 |
parsed_key = pkey.to_cryptography_key() |
| 857 |
assert isinstance(parsed_key, key_type) |
| 858 |
assert isinstance( |
| 859 |
parsed_key, |
| 860 |
( |
| 861 |
dsa.DSAPrivateKey, |
| 862 |
ec.EllipticCurvePrivateKey, |
| 863 |
ed25519.Ed25519PrivateKey, |
| 864 |
ed448.Ed448PrivateKey, |
| 865 |
rsa.RSAPrivateKey, |
| 866 |
), |
| 867 |
) |
| 868 |
assert parsed_key.public_key().public_bytes( |
| 869 |
serialization.Encoding.PEM, |
| 870 |
serialization.PublicFormat.SubjectPublicKeyInfo, |
| 871 |
) == key.public_key().public_bytes( |
| 872 |
serialization.Encoding.PEM, |
| 873 |
serialization.PublicFormat.SubjectPublicKeyInfo, |
| 874 |
) |
| 875 |
assert pkey._only_public is False |
| 876 |
assert pkey._initialized is True |
| 877 |
|
| 878 |
@pytest.mark.parametrize( |
| 879 |
("key_string", "key_type"), |
| 880 |
[ |
| 881 |
(dsa_public_key_pem, dsa.DSAPublicKey), |
| 882 |
(ec_public_key_pem, ec.EllipticCurvePublicKey), |
| 883 |
pytest.param( |
| 884 |
ed25519_public_key_pem, |
| 885 |
ed25519.Ed25519PublicKey, |
| 886 |
marks=pytest.mark.skipif( |
| 887 |
conftest.is_awslc, |
| 888 |
reason="aws-lc doesn't support Ed25519 serialization", |
| 889 |
), |
| 890 |
), |
| 891 |
pytest.param( |
| 892 |
ed448_public_key_pem, |
| 893 |
ed448.Ed448PublicKey, |
| 894 |
marks=pytest.mark.skipif( |
| 895 |
conftest.is_awslc, |
| 896 |
reason="aws-lc doesn't support Ed448", |
| 897 |
), |
| 898 |
), |
| 899 |
(rsa_public_key_pem, rsa.RSAPublicKey), |
| 900 |
], |
| 901 |
) |
| 902 |
def test_convert_roundtrip_cryptography_public_key( |
| 903 |
self, key_string: bytes, key_type: type[_Key] |
| 904 |
) -> None: |
| 905 |
""" |
| 906 |
PKey.from_cryptography_key creates a proper public PKey. |
| 907 |
PKey.to_cryptography_key creates a proper cryptography public key. |
| 908 |
""" |
| 909 |
key = serialization.load_pem_public_key(key_string, None) |
| 910 |
assert isinstance(key, key_type) |
| 911 |
assert isinstance( |
| 912 |
key, |
| 913 |
( |
| 914 |
dsa.DSAPublicKey, |
| 915 |
ec.EllipticCurvePublicKey, |
| 916 |
ed25519.Ed25519PublicKey, |
| 917 |
ed448.Ed448PublicKey, |
| 918 |
rsa.RSAPublicKey, |
| 919 |
), |
| 920 |
) |
| 921 |
pkey = PKey.from_cryptography_key(key) |
| 922 |
|
| 923 |
assert isinstance(pkey, PKey) |
| 924 |
parsed_key = pkey.to_cryptography_key() |
| 925 |
assert isinstance(parsed_key, key_type) |
| 926 |
assert isinstance( |
| 927 |
parsed_key, |
| 928 |
( |
| 929 |
dsa.DSAPublicKey, |
| 930 |
ec.EllipticCurvePublicKey, |
| 931 |
ed25519.Ed25519PublicKey, |
| 932 |
ed448.Ed448PublicKey, |
| 933 |
rsa.RSAPublicKey, |
| 934 |
), |
| 935 |
) |
| 936 |
assert parsed_key.public_bytes( |
| 937 |
serialization.Encoding.PEM, |
| 938 |
serialization.PublicFormat.SubjectPublicKeyInfo, |
| 939 |
) == key.public_bytes( |
| 940 |
serialization.Encoding.PEM, |
| 941 |
serialization.PublicFormat.SubjectPublicKeyInfo, |
| 942 |
) |
| 943 |
assert pkey._only_public is True |
| 944 |
assert pkey._initialized is True |
| 945 |
|
| 946 |
def test_convert_from_cryptography_public_key(self) -> None: |
| 947 |
""" |
| 948 |
PKey.from_cryptography_key creates a proper public PKey. |
| 949 |
""" |
| 950 |
key = serialization.load_pem_public_key(cleartextPublicKeyPEM) |
| 951 |
assert isinstance(key, rsa.RSAPublicKey) |
| 952 |
pkey = PKey.from_cryptography_key(key) |
| 953 |
|
| 954 |
assert isinstance(pkey, PKey) |
| 955 |
assert pkey.bits() == key.key_size |
| 956 |
assert pkey._only_public is True |
| 957 |
assert pkey._initialized is True |
| 958 |
|
| 959 |
def test_convert_from_cryptography_unsupported_type(self) -> None: |
| 960 |
""" |
| 961 |
PKey.from_cryptography_key raises TypeError with an unsupported type. |
| 962 |
""" |
| 963 |
key = serialization.load_pem_private_key(x25519_private_key_pem, None) |
| 964 |
with pytest.raises(TypeError): |
| 965 |
PKey.from_cryptography_key(key) # type: ignore[arg-type] |
| 966 |
|
| 967 |
def test_convert_public_pkey_to_cryptography_key(self) -> None: |
| 968 |
""" |
| 969 |
PKey.to_cryptography_key creates a proper cryptography public key. |
| 970 |
""" |
| 971 |
pkey = load_publickey(FILETYPE_PEM, cleartextPublicKeyPEM) |
| 972 |
key = pkey.to_cryptography_key() |
| 973 |
|
| 974 |
assert isinstance(key, rsa.RSAPublicKey) |
| 975 |
assert pkey.bits() == key.key_size |
| 976 |
|
| 977 |
def test_construction(self) -> None: |
| 978 |
""" |
| 979 |
`PKey` takes no arguments and returns a new `PKey` instance. |
| 980 |
""" |
| 981 |
key = PKey() |
| 982 |
assert isinstance(key, PKey) |
| 983 |
|
| 984 |
def test_pregeneration(self) -> None: |
| 985 |
""" |
| 986 |
`PKey.bits` and `PKey.type` return `0` before the key is generated. |
| 987 |
`PKey.check` raises `TypeError` before the key is generated. |
| 988 |
""" |
| 989 |
key = PKey() |
| 990 |
assert key.type() == 0 |
| 991 |
assert key.bits() == 0 |
| 992 |
with pytest.raises(TypeError): |
| 993 |
key.check() |
| 994 |
|
| 995 |
def test_failed_generation(self) -> None: |
| 996 |
""" |
| 997 |
`PKey.generate_key` takes two arguments, the first giving the key type |
| 998 |
as one of `TYPE_RSA` or `TYPE_DSA` and the second giving the number of |
| 999 |
bits to generate. If an invalid type is specified or generation fails, |
| 1000 |
`Error` is raised. If an invalid number of bits is specified, |
| 1001 |
`ValueError` or `Error` is raised. |
| 1002 |
""" |
| 1003 |
key = PKey() |
| 1004 |
with pytest.raises(TypeError): |
| 1005 |
key.generate_key("foo", "bar") # type: ignore[arg-type] |
| 1006 |
with pytest.raises(Error): |
| 1007 |
key.generate_key(-1, 0) |
| 1008 |
|
| 1009 |
with pytest.raises(ValueError): |
| 1010 |
key.generate_key(TYPE_RSA, -1) |
| 1011 |
with pytest.raises(ValueError): |
| 1012 |
key.generate_key(TYPE_RSA, 0) |
| 1013 |
|
| 1014 |
with pytest.raises(TypeError): |
| 1015 |
key.generate_key(TYPE_RSA, object()) # type: ignore[arg-type] |
| 1016 |
|
| 1017 |
def test_rsa_generation(self) -> None: |
| 1018 |
""" |
| 1019 |
`PKey.generate_key` generates an RSA key when passed `TYPE_RSA` as a |
| 1020 |
type and a reasonable number of bits. |
| 1021 |
""" |
| 1022 |
bits = 2048 |
| 1023 |
key = PKey() |
| 1024 |
key.generate_key(TYPE_RSA, bits) |
| 1025 |
assert key.type() == TYPE_RSA |
| 1026 |
assert key.bits() == bits |
| 1027 |
assert key.check() |
| 1028 |
|
| 1029 |
def test_dsa_generation(self) -> None: |
| 1030 |
""" |
| 1031 |
`PKey.generate_key` generates a DSA key when passed `TYPE_DSA` as a |
| 1032 |
type and a reasonable number of bits. |
| 1033 |
""" |
| 1034 |
# 512 is a magic number. The DSS (Digital Signature Standard) |
| 1035 |
# allows a minimum of 512 bits for DSA. DSA_generate_parameters |
| 1036 |
# will silently promote any value below 512 to 512. |
| 1037 |
bits = 512 |
| 1038 |
key = PKey() |
| 1039 |
key.generate_key(TYPE_DSA, bits) |
| 1040 |
assert key.type() == TYPE_DSA |
| 1041 |
assert key.bits() == bits |
| 1042 |
with pytest.raises(TypeError): |
| 1043 |
key.check() |
| 1044 |
|
| 1045 |
def test_regeneration(self) -> None: |
| 1046 |
""" |
| 1047 |
`PKey.generate_key` can be called multiple times on the same key to |
| 1048 |
generate new keys. |
| 1049 |
""" |
| 1050 |
key = PKey() |
| 1051 |
for type, bits in [(TYPE_RSA, 2048), (TYPE_DSA, 576)]: |
| 1052 |
key.generate_key(type, bits) |
| 1053 |
assert key.type() == type |
| 1054 |
assert key.bits() == bits |
| 1055 |
|
| 1056 |
def test_inconsistent_key(self) -> None: |
| 1057 |
""" |
| 1058 |
Either `load_privatekey` or `PKey.check` returns `Error` if the key is |
| 1059 |
not consistent. |
| 1060 |
""" |
| 1061 |
with pytest.raises(Error): |
| 1062 |
key = load_privatekey(FILETYPE_PEM, inconsistentPrivateKeyPEM) |
| 1063 |
key.check() |
| 1064 |
|
| 1065 |
def test_check_public_key(self) -> None: |
| 1066 |
""" |
| 1067 |
`PKey.check` raises `TypeError` if only the public part of the key |
| 1068 |
is available. |
| 1069 |
""" |
| 1070 |
# A trick to get a public-only key |
| 1071 |
key = PKey() |
| 1072 |
key.generate_key(TYPE_RSA, 2048) |
| 1073 |
cert = X509() |
| 1074 |
cert.set_pubkey(key) |
| 1075 |
pub = cert.get_pubkey() |
| 1076 |
with pytest.raises(TypeError): |
| 1077 |
pub.check() |
| 1078 |
|
| 1079 |
def test_check_pr_897(self) -> None: |
| 1080 |
""" |
| 1081 |
Either `load_privatekey` or `PKey.check` raises `OpenSSL.crypto.Error` |
| 1082 |
if provided with broken key |
| 1083 |
""" |
| 1084 |
with pytest.raises(Error): |
| 1085 |
pkey = load_privatekey(FILETYPE_PEM, rsa_p_not_prime_pem) |
| 1086 |
pkey.check() |
| 1087 |
|
| 1088 |
|
| 1089 |
def x509_name(**attrs: str) -> X509Name: |
| 1090 |
""" |
| 1091 |
Return a new X509Name with the given attributes. |
| 1092 |
""" |
| 1093 |
# XXX There's no other way to get a new X509Name yet. |
| 1094 |
name = X509().get_subject() |
| 1095 |
|
| 1096 |
# Make the order stable - order matters! |
| 1097 |
def key(attr: tuple[str, str]) -> str: |
| 1098 |
return attr[1] |
| 1099 |
|
| 1100 |
for k, v in sorted(attrs.items(), key=key): |
| 1101 |
setattr(name, k, v) |
| 1102 |
return name |
| 1103 |
|
| 1104 |
|
| 1105 |
class TestX509Name: |
| 1106 |
""" |
| 1107 |
Unit tests for `OpenSSL.crypto.X509Name`. |
| 1108 |
""" |
| 1109 |
|
| 1110 |
def test_type(self) -> None: |
| 1111 |
""" |
| 1112 |
The type of X509Name objects is `X509Name`. |
| 1113 |
""" |
| 1114 |
name = x509_name() |
| 1115 |
assert isinstance(name, X509Name) |
| 1116 |
|
| 1117 |
def test_only_string_attributes(self) -> None: |
| 1118 |
""" |
| 1119 |
Attempting to set a non-`str` attribute name on an `X509Name` instance |
| 1120 |
causes `TypeError` to be raised. |
| 1121 |
""" |
| 1122 |
name = x509_name() |
| 1123 |
# Beyond these cases, you may also think that unicode should be |
| 1124 |
# rejected. Sorry, you're wrong. unicode is automatically converted |
| 1125 |
# to str outside of the control of X509Name, so there's no way to |
| 1126 |
# reject it. |
| 1127 |
|
| 1128 |
# Also, this used to test str subclasses, but that test is less |
| 1129 |
# relevant now that the implementation is in Python instead of C. Also |
| 1130 |
# PyPy automatically converts str subclasses to str when they are |
| 1131 |
# passed to setattr, so we can't test it on PyPy. Apparently CPython |
| 1132 |
# does this sometimes as well. |
| 1133 |
with pytest.raises(TypeError): |
| 1134 |
setattr(name, None, "hello") # type: ignore[arg-type] |
| 1135 |
with pytest.raises(TypeError): |
| 1136 |
setattr(name, 30, "hello") # type: ignore[arg-type] |
| 1137 |
|
| 1138 |
def test_set_invalid_attribute(self) -> None: |
| 1139 |
""" |
| 1140 |
Attempting to set any attribute name on an `X509Name` instance for |
| 1141 |
which no corresponding NID is defined causes `AttributeError` to be |
| 1142 |
raised. |
| 1143 |
""" |
| 1144 |
name = x509_name() |
| 1145 |
with pytest.raises(AttributeError): |
| 1146 |
setattr(name, "no such thing", None) |
| 1147 |
|
| 1148 |
def test_attributes(self) -> None: |
| 1149 |
""" |
| 1150 |
`X509Name` instances have attributes for each standard (?) |
| 1151 |
X509Name field. |
| 1152 |
""" |
| 1153 |
name = x509_name() |
| 1154 |
name.commonName = "foo" |
| 1155 |
assert name.commonName == "foo" |
| 1156 |
assert name.CN == "foo" |
| 1157 |
|
| 1158 |
name.CN = "baz" |
| 1159 |
assert name.commonName == "baz" |
| 1160 |
assert name.CN == "baz" |
| 1161 |
|
| 1162 |
name.commonName = "bar" |
| 1163 |
assert name.commonName == "bar" |
| 1164 |
assert name.CN == "bar" |
| 1165 |
|
| 1166 |
name.CN = "quux" |
| 1167 |
assert name.commonName == "quux" |
| 1168 |
assert name.CN == "quux" |
| 1169 |
|
| 1170 |
assert name.OU is None |
| 1171 |
|
| 1172 |
with pytest.raises(AttributeError): |
| 1173 |
name.foobar |
| 1174 |
|
| 1175 |
def test_copy(self) -> None: |
| 1176 |
""" |
| 1177 |
`X509Name` creates a new `X509Name` instance with all the same |
| 1178 |
attributes as an existing `X509Name` instance when called with one. |
| 1179 |
""" |
| 1180 |
name = x509_name(commonName="foo", emailAddress="[email protected]") |
| 1181 |
|
| 1182 |
copy = X509Name(name) |
| 1183 |
assert copy.commonName == "foo" |
| 1184 |
assert copy.emailAddress == "[email protected]" |
| 1185 |
|
| 1186 |
# Mutate the copy and ensure the original is unmodified. |
| 1187 |
copy.commonName = "baz" |
| 1188 |
assert name.commonName == "foo" |
| 1189 |
|
| 1190 |
# Mutate the original and ensure the copy is unmodified. |
| 1191 |
name.emailAddress = "[email protected]" |
| 1192 |
assert copy.emailAddress == "[email protected]" |
| 1193 |
|
| 1194 |
def test_null_bytes_preserved(self) -> None: |
| 1195 |
""" |
| 1196 |
Null bytes in X509Name field values are round-tripped correctly. |
| 1197 |
""" |
| 1198 |
name = x509_name() |
| 1199 |
name.CN = "a\x00b" |
| 1200 |
assert name.CN == "a\x00b" |
| 1201 |
|
| 1202 |
def test_repr(self) -> None: |
| 1203 |
""" |
| 1204 |
`repr` passed an `X509Name` instance should return a string containing |
| 1205 |
a description of the type and the NIDs which have been set on it. |
| 1206 |
""" |
| 1207 |
name = x509_name(commonName="foo", emailAddress="bar") |
| 1208 |
assert repr(name) == "<X509Name object '/emailAddress=bar/CN=foo'>" |
| 1209 |
|
| 1210 |
def test_comparison(self) -> None: |
| 1211 |
""" |
| 1212 |
`X509Name` instances should compare based on their NIDs. |
| 1213 |
""" |
| 1214 |
|
| 1215 |
def _equality( |
| 1216 |
a: X509Name, |
| 1217 |
b: object, |
| 1218 |
assert_true: typing.Callable[[bool], None], |
| 1219 |
assert_false: typing.Callable[[bool], None], |
| 1220 |
) -> None: |
| 1221 |
assert_true(a == b) |
| 1222 |
assert_false(a != b) |
| 1223 |
assert_true(b == a) |
| 1224 |
assert_false(b != a) |
| 1225 |
|
| 1226 |
def assert_true(x: bool) -> None: |
| 1227 |
assert x |
| 1228 |
|
| 1229 |
def assert_false(x: bool) -> None: |
| 1230 |
assert not x |
| 1231 |
|
| 1232 |
def assert_equal(a: X509Name, b: object) -> None: |
| 1233 |
_equality(a, b, assert_true, assert_false) |
| 1234 |
|
| 1235 |
# Instances compare equal to themselves. |
| 1236 |
name = x509_name() |
| 1237 |
assert_equal(name, name) |
| 1238 |
|
| 1239 |
# Empty instances should compare equal to each other. |
| 1240 |
assert_equal(x509_name(), x509_name()) |
| 1241 |
|
| 1242 |
# Instances with equal NIDs should compare equal to each other. |
| 1243 |
assert_equal(x509_name(commonName="foo"), x509_name(commonName="foo")) |
| 1244 |
|
| 1245 |
# Instance with equal NIDs set using different aliases should compare |
| 1246 |
# equal to each other. |
| 1247 |
assert_equal(x509_name(commonName="foo"), x509_name(CN="foo")) |
| 1248 |
|
| 1249 |
# Instances with more than one NID with the same values should compare |
| 1250 |
# equal to each other. |
| 1251 |
assert_equal( |
| 1252 |
x509_name(CN="foo", organizationalUnitName="bar"), |
| 1253 |
x509_name(commonName="foo", OU="bar"), |
| 1254 |
) |
| 1255 |
|
| 1256 |
def assert_not_equal(a: X509Name, b: object) -> None: |
| 1257 |
_equality(a, b, assert_false, assert_true) |
| 1258 |
|
| 1259 |
# Instances with different values for the same NID should not compare |
| 1260 |
# equal to each other. |
| 1261 |
assert_not_equal(x509_name(CN="foo"), x509_name(CN="bar")) |
| 1262 |
|
| 1263 |
# Instances with different NIDs should not compare equal to each other. |
| 1264 |
assert_not_equal(x509_name(CN="foo"), x509_name(OU="foo")) |
| 1265 |
|
| 1266 |
assert_not_equal(x509_name(), object()) |
| 1267 |
|
| 1268 |
def _inequality( |
| 1269 |
a: X509Name, |
| 1270 |
b: X509Name, |
| 1271 |
assert_true: typing.Callable[[bool], None], |
| 1272 |
assert_false: typing.Callable[[bool], None], |
| 1273 |
) -> None: |
| 1274 |
assert_true(a < b) |
| 1275 |
assert_true(a <= b) |
| 1276 |
assert_true(b > a) |
| 1277 |
assert_true(b >= a) |
| 1278 |
assert_false(a > b) |
| 1279 |
assert_false(a >= b) |
| 1280 |
assert_false(b < a) |
| 1281 |
assert_false(b <= a) |
| 1282 |
|
| 1283 |
def assert_less_than(a: X509Name, b: X509Name) -> None: |
| 1284 |
_inequality(a, b, assert_true, assert_false) |
| 1285 |
|
| 1286 |
# An X509Name with a NID with a value which sorts less than the value |
| 1287 |
# of the same NID on another X509Name compares less than the other |
| 1288 |
# X509Name. |
| 1289 |
assert_less_than(x509_name(CN="abc"), x509_name(CN="def")) |
| 1290 |
|
| 1291 |
def assert_greater_than(a: X509Name, b: X509Name) -> None: |
| 1292 |
_inequality(a, b, assert_false, assert_true) |
| 1293 |
|
| 1294 |
# An X509Name with a NID with a value which sorts greater than the |
| 1295 |
# value of the same NID on another X509Name compares greater than the |
| 1296 |
# other X509Name. |
| 1297 |
assert_greater_than(x509_name(CN="def"), x509_name(CN="abc")) |
| 1298 |
|
| 1299 |
def assert_raises(a: X509Name, b: object) -> None: |
| 1300 |
with pytest.raises(TypeError): |
| 1301 |
a < b |
| 1302 |
with pytest.raises(TypeError): |
| 1303 |
a <= b |
| 1304 |
with pytest.raises(TypeError): |
| 1305 |
a > b |
| 1306 |
with pytest.raises(TypeError): |
| 1307 |
a >= b |
| 1308 |
|
| 1309 |
# Only X509Name objects can be compared with lesser than / greater than |
| 1310 |
assert_raises(x509_name(), object()) |
| 1311 |
|
| 1312 |
def test_hash(self) -> None: |
| 1313 |
""" |
| 1314 |
`X509Name.hash` returns an integer hash based on the value of the name. |
| 1315 |
""" |
| 1316 |
a = x509_name(CN="foo") |
| 1317 |
b = x509_name(CN="foo") |
| 1318 |
assert a.hash() == b.hash() |
| 1319 |
a.CN = "bar" |
| 1320 |
assert a.hash() != b.hash() |
| 1321 |
|
| 1322 |
def test_der(self) -> None: |
| 1323 |
""" |
| 1324 |
`X509Name.der` returns the DER encoded form of the name. |
| 1325 |
""" |
| 1326 |
a = x509_name(CN="foo", C="US") |
| 1327 |
assert ( |
| 1328 |
a.der() == b"0\x1b1\x0b0\t\x06\x03U\x04\x06\x13\x02US" |
| 1329 |
b"1\x0c0\n\x06\x03U\x04\x03\x0c\x03foo" |
| 1330 |
) |
| 1331 |
|
| 1332 |
def test_get_components(self) -> None: |
| 1333 |
""" |
| 1334 |
`X509Name.get_components` returns a `list` of two-tuples of `str` |
| 1335 |
giving the NIDs and associated values which make up the name. |
| 1336 |
""" |
| 1337 |
a = x509_name() |
| 1338 |
assert a.get_components() == [] |
| 1339 |
a.CN = "foo" |
| 1340 |
assert a.get_components() == [(b"CN", b"foo")] |
| 1341 |
a.organizationalUnitName = "bar" |
| 1342 |
assert a.get_components() == [(b"CN", b"foo"), (b"OU", b"bar")] |
| 1343 |
|
| 1344 |
def test_load_nul_byte_attribute(self) -> None: |
| 1345 |
""" |
| 1346 |
An `X509Name` from an `X509` instance loaded from a file can have a |
| 1347 |
NUL byte in the value of one of its attributes. |
| 1348 |
""" |
| 1349 |
cert = load_certificate(FILETYPE_PEM, nulbyteSubjectAltNamePEM) |
| 1350 |
subject = cert.get_subject() |
| 1351 |
assert "null.python.org\x00example.org" == subject.commonName |
| 1352 |
|
| 1353 |
def test_load_nul_byte_components(self) -> None: |
| 1354 |
""" |
| 1355 |
An `X509Name` from an `X509` instance loaded from a file can have a |
| 1356 |
NUL byte in the value of its components |
| 1357 |
""" |
| 1358 |
cert = load_certificate(FILETYPE_PEM, nulbyteSubjectAltNamePEM) |
| 1359 |
subject = cert.get_subject() |
| 1360 |
components = subject.get_components() |
| 1361 |
ccn = [value for name, value in components if name == b"CN"] |
| 1362 |
assert ccn[0] == b"null.python.org\x00example.org" |
| 1363 |
|
| 1364 |
def test_set_attribute_failure(self) -> None: |
| 1365 |
""" |
| 1366 |
If the value of an attribute cannot be set for some reason then |
| 1367 |
`Error` is raised. |
| 1368 |
""" |
| 1369 |
name = x509_name() |
| 1370 |
# This value is too long |
| 1371 |
with pytest.raises(Error): |
| 1372 |
setattr(name, "O", b"x" * 512) |
| 1373 |
|
| 1374 |
|
| 1375 |
class TestX509: |
| 1376 |
""" |
| 1377 |
Tests for `OpenSSL.crypto.X509`. |
| 1378 |
""" |
| 1379 |
|
| 1380 |
pemData = root_cert_pem + root_key_pem |
| 1381 |
|
| 1382 |
def test_sign_with_ungenerated(self) -> None: |
| 1383 |
""" |
| 1384 |
`X509.sign` raises `ValueError` when passed a `PKey` with no parts. |
| 1385 |
""" |
| 1386 |
cert = X509() |
| 1387 |
key = PKey() |
| 1388 |
with pytest.raises(ValueError): |
| 1389 |
cert.sign(key, GOOD_DIGEST) |
| 1390 |
|
| 1391 |
def test_sign_with_public_key(self) -> None: |
| 1392 |
""" |
| 1393 |
`X509.sign` raises `ValueError` when passed a `PKey` with no private |
| 1394 |
part as the signing key. |
| 1395 |
""" |
| 1396 |
cert = X509() |
| 1397 |
key = PKey() |
| 1398 |
key.generate_key(TYPE_RSA, 2048) |
| 1399 |
cert.set_pubkey(key) |
| 1400 |
pub = cert.get_pubkey() |
| 1401 |
with pytest.raises(ValueError): |
| 1402 |
cert.sign(pub, GOOD_DIGEST) |
| 1403 |
|
| 1404 |
def test_sign_with_unknown_digest(self) -> None: |
| 1405 |
""" |
| 1406 |
`X509.sign` raises `ValueError` when passed a digest name which is |
| 1407 |
not known. |
| 1408 |
""" |
| 1409 |
cert = X509() |
| 1410 |
key = PKey() |
| 1411 |
key.generate_key(TYPE_RSA, 2048) |
| 1412 |
with pytest.raises(ValueError): |
| 1413 |
cert.sign(key, BAD_DIGEST) |
| 1414 |
|
| 1415 |
def test_sign(self) -> None: |
| 1416 |
""" |
| 1417 |
`X509.sign` succeeds when passed a private key object and a |
| 1418 |
valid digest function. |
| 1419 |
""" |
| 1420 |
cert = X509() |
| 1421 |
key = PKey() |
| 1422 |
key.generate_key(TYPE_RSA, 2048) |
| 1423 |
cert.set_pubkey(key) |
| 1424 |
cert.gmtime_adj_notBefore(0) |
| 1425 |
cert.gmtime_adj_notAfter(24 * 60 * 60) |
| 1426 |
cert.sign(key, GOOD_DIGEST) |
| 1427 |
|
| 1428 |
def test_construction(self) -> None: |
| 1429 |
""" |
| 1430 |
`X509` takes no arguments and returns an instance of `X509`. |
| 1431 |
""" |
| 1432 |
certificate = X509() |
| 1433 |
assert isinstance(certificate, X509) |
| 1434 |
assert type(certificate).__name__ == "X509" |
| 1435 |
assert type(certificate) is X509 |
| 1436 |
|
| 1437 |
def test_set_version_wrong_args(self) -> None: |
| 1438 |
""" |
| 1439 |
`X509.set_version` raises `TypeError` if invoked with an argument |
| 1440 |
not of type `int`. |
| 1441 |
""" |
| 1442 |
cert = X509() |
| 1443 |
with pytest.raises(TypeError): |
| 1444 |
cert.set_version(None) # type: ignore[arg-type] |
| 1445 |
|
| 1446 |
def test_version(self) -> None: |
| 1447 |
""" |
| 1448 |
`X509.set_version` sets the certificate version number. |
| 1449 |
`X509.get_version` retrieves it. |
| 1450 |
""" |
| 1451 |
cert = X509() |
| 1452 |
cert.set_version(2) |
| 1453 |
assert cert.get_version() == 2 |
| 1454 |
|
| 1455 |
def test_serial_number(self) -> None: |
| 1456 |
""" |
| 1457 |
The serial number of an `X509` can be retrieved and |
| 1458 |
modified with `X509.get_serial_number` and |
| 1459 |
`X509.set_serial_number`. |
| 1460 |
""" |
| 1461 |
certificate = X509() |
| 1462 |
with pytest.raises(TypeError): |
| 1463 |
certificate.set_serial_number("1") # type: ignore[arg-type] |
| 1464 |
assert certificate.get_serial_number() == 0 |
| 1465 |
certificate.set_serial_number(1) |
| 1466 |
assert certificate.get_serial_number() == 1 |
| 1467 |
certificate.set_serial_number(2**32 + 1) |
| 1468 |
assert certificate.get_serial_number() == 2**32 + 1 |
| 1469 |
certificate.set_serial_number(2**64 + 1) |
| 1470 |
assert certificate.get_serial_number() == 2**64 + 1 |
| 1471 |
certificate.set_serial_number(2**128 + 1) |
| 1472 |
assert certificate.get_serial_number() == 2**128 + 1 |
| 1473 |
|
| 1474 |
def _setBoundTest( |
| 1475 |
self, |
| 1476 |
get: typing.Callable[[X509], bytes | None], |
| 1477 |
set: typing.Callable[[X509, bytes], None], |
| 1478 |
) -> None: |
| 1479 |
""" |
| 1480 |
`X509.set_notBefore` takes a string in the format of an |
| 1481 |
ASN1 GENERALIZEDTIME and sets the beginning of the certificate's |
| 1482 |
validity period to it. |
| 1483 |
""" |
| 1484 |
certificate = X509() |
| 1485 |
|
| 1486 |
# Starts with no value. |
| 1487 |
assert get(certificate) is None |
| 1488 |
|
| 1489 |
# GMT (Or is it UTC?) -exarkun |
| 1490 |
when = b"20040203040506Z" |
| 1491 |
set(certificate, when) |
| 1492 |
assert get(certificate) == when |
| 1493 |
|
| 1494 |
if not conftest.is_awslc: |
| 1495 |
# A plus two hours and thirty minutes offset |
| 1496 |
when = b"20040203040506+0530" |
| 1497 |
set(certificate, when) |
| 1498 |
assert get(certificate) == when |
| 1499 |
|
| 1500 |
# A minus one hour fifteen minutes offset |
| 1501 |
when = b"20040203040506-0115" |
| 1502 |
set(certificate, when) |
| 1503 |
assert ( |
| 1504 |
get( |
| 1505 |
certificate, |
| 1506 |
) |
| 1507 |
== when |
| 1508 |
) |
| 1509 |
|
| 1510 |
# An invalid string results in a ValueError |
| 1511 |
with pytest.raises(ValueError): |
| 1512 |
set(certificate, b"foo bar") |
| 1513 |
|
| 1514 |
def test_set_notBefore(self) -> None: |
| 1515 |
""" |
| 1516 |
`X509.set_notBefore` takes a string in the format of an |
| 1517 |
ASN1 GENERALIZEDTIME and sets the beginning of the certificate's |
| 1518 |
validity period to it. |
| 1519 |
""" |
| 1520 |
self._setBoundTest( |
| 1521 |
lambda c: c.get_notBefore(), lambda c, v: c.set_notBefore(v) |
| 1522 |
) |
| 1523 |
|
| 1524 |
def test_set_notAfter(self) -> None: |
| 1525 |
""" |
| 1526 |
`X509.set_notAfter` takes a string in the format of an ASN1 |
| 1527 |
GENERALIZEDTIME and sets the end of the certificate's validity period |
| 1528 |
to it. |
| 1529 |
""" |
| 1530 |
self._setBoundTest( |
| 1531 |
lambda c: c.get_notAfter(), lambda c, v: c.set_notAfter(v) |
| 1532 |
) |
| 1533 |
|
| 1534 |
def test_get_notBefore(self) -> None: |
| 1535 |
""" |
| 1536 |
`X509.get_notBefore` returns a string in the format of an |
| 1537 |
ASN1 GENERALIZEDTIME even for certificates which store it as UTCTIME |
| 1538 |
internally. |
| 1539 |
""" |
| 1540 |
cert = load_certificate(FILETYPE_PEM, old_root_cert_pem) |
| 1541 |
assert cert.get_notBefore() == b"20090325123658Z" |
| 1542 |
|
| 1543 |
def test_get_notAfter(self) -> None: |
| 1544 |
""" |
| 1545 |
`X509.get_notAfter` returns a string in the format of an |
| 1546 |
ASN1 GENERALIZEDTIME even for certificates which store it as UTCTIME |
| 1547 |
internally. |
| 1548 |
""" |
| 1549 |
cert = load_certificate(FILETYPE_PEM, old_root_cert_pem) |
| 1550 |
assert cert.get_notAfter() == b"20170611123658Z" |
| 1551 |
|
| 1552 |
def test_gmtime_adj_notBefore_wrong_args(self) -> None: |
| 1553 |
""" |
| 1554 |
`X509.gmtime_adj_notBefore` raises `TypeError` if called with a |
| 1555 |
non-`int` argument. |
| 1556 |
""" |
| 1557 |
cert = X509() |
| 1558 |
with pytest.raises(TypeError): |
| 1559 |
cert.gmtime_adj_notBefore(None) # type: ignore[arg-type] |
| 1560 |
|
| 1561 |
@pytest.mark.flaky(reruns=2) |
| 1562 |
def test_gmtime_adj_notBefore(self) -> None: |
| 1563 |
""" |
| 1564 |
`X509.gmtime_adj_notBefore` changes the not-before timestamp to be the |
| 1565 |
current time plus the number of seconds passed in. |
| 1566 |
""" |
| 1567 |
cert = load_certificate(FILETYPE_PEM, self.pemData) |
| 1568 |
utc_now = utcnow().replace(microsecond=0) |
| 1569 |
# -1 second tolerance for clock adjustments |
| 1570 |
not_before_min = utc_now + timedelta(seconds=99) |
| 1571 |
cert.gmtime_adj_notBefore(100) |
| 1572 |
not_before_str = cert.get_notBefore() |
| 1573 |
assert not_before_str is not None |
| 1574 |
not_before = datetime.strptime( |
| 1575 |
not_before_str.decode(), "%Y%m%d%H%M%SZ" |
| 1576 |
) |
| 1577 |
# +1 second tolerance for clock adjustments |
| 1578 |
not_before_max = utc_now + timedelta(seconds=101) |
| 1579 |
assert not_before_min <= not_before <= not_before_max |
| 1580 |
|
| 1581 |
def test_gmtime_adj_notAfter_wrong_args(self) -> None: |
| 1582 |
""" |
| 1583 |
`X509.gmtime_adj_notAfter` raises `TypeError` if called with a |
| 1584 |
non-`int` argument. |
| 1585 |
""" |
| 1586 |
cert = X509() |
| 1587 |
with pytest.raises(TypeError): |
| 1588 |
cert.gmtime_adj_notAfter(None) # type: ignore[arg-type] |
| 1589 |
|
| 1590 |
@pytest.mark.flaky(reruns=2) |
| 1591 |
def test_gmtime_adj_notAfter(self) -> None: |
| 1592 |
""" |
| 1593 |
`X509.gmtime_adj_notAfter` changes the not-after timestamp |
| 1594 |
to be the current time plus the number of seconds passed in. |
| 1595 |
""" |
| 1596 |
cert = load_certificate(FILETYPE_PEM, self.pemData) |
| 1597 |
utc_now = utcnow().replace(microsecond=0) |
| 1598 |
# -1 second tolerance for clock adjustments |
| 1599 |
not_after_min = utc_now + timedelta(seconds=99) |
| 1600 |
cert.gmtime_adj_notAfter(100) |
| 1601 |
not_after_str = cert.get_notAfter() |
| 1602 |
assert not_after_str is not None |
| 1603 |
not_after = datetime.strptime(not_after_str.decode(), "%Y%m%d%H%M%SZ") |
| 1604 |
# +1 second tolerance for clock adjustments |
| 1605 |
not_after_max = utc_now + timedelta(seconds=101) |
| 1606 |
assert not_after_min <= not_after <= not_after_max |
| 1607 |
|
| 1608 |
def test_has_expired(self) -> None: |
| 1609 |
""" |
| 1610 |
`X509.has_expired` returns `True` if the certificate's not-after time |
| 1611 |
is in the past. |
| 1612 |
""" |
| 1613 |
cert = X509() |
| 1614 |
cert.gmtime_adj_notAfter(-1) |
| 1615 |
assert cert.has_expired() |
| 1616 |
|
| 1617 |
def test_has_not_expired(self) -> None: |
| 1618 |
""" |
| 1619 |
`X509.has_expired` returns `False` if the certificate's not-after time |
| 1620 |
is in the future. |
| 1621 |
""" |
| 1622 |
cert = X509() |
| 1623 |
cert.gmtime_adj_notAfter(2) |
| 1624 |
assert not cert.has_expired() |
| 1625 |
|
| 1626 |
def test_has_expired_exception(self) -> None: |
| 1627 |
""" |
| 1628 |
`X509.has_expired` throws ValueError if not-after time is not set |
| 1629 |
""" |
| 1630 |
cert = X509() |
| 1631 |
with pytest.raises(ValueError): |
| 1632 |
cert.has_expired() |
| 1633 |
|
| 1634 |
def test_root_has_not_expired(self) -> None: |
| 1635 |
""" |
| 1636 |
`X509.has_expired` returns `False` if the certificate's not-after time |
| 1637 |
is in the future. |
| 1638 |
""" |
| 1639 |
cert = load_certificate(FILETYPE_PEM, root_cert_pem) |
| 1640 |
assert not cert.has_expired() |
| 1641 |
|
| 1642 |
def test_digest(self) -> None: |
| 1643 |
""" |
| 1644 |
`X509.digest` returns a string giving ":"-separated hex-encoded |
| 1645 |
words of the digest of the certificate. |
| 1646 |
""" |
| 1647 |
cert = load_certificate(FILETYPE_PEM, old_root_cert_pem) |
| 1648 |
assert ( |
| 1649 |
# Digest verified with the command: |
| 1650 |
# openssl x509 -in root_cert.pem -noout -fingerprint -sha256 |
| 1651 |
cert.digest("SHA256") |
| 1652 |
== ( |
| 1653 |
b"3E:0F:16:39:6B:B1:3E:4F:08:85:C6:5F:10:0D:CB:2C:" |
| 1654 |
b"25:C2:91:4E:D0:4A:C2:29:06:BD:55:E3:A7:B3:B7:06" |
| 1655 |
) |
| 1656 |
) |
| 1657 |
|
| 1658 |
def _extcert( |
| 1659 |
self, key: _PrivateKey, extensions: list[x509.ExtensionType] |
| 1660 |
) -> X509: |
| 1661 |
subject = x509.Name( |
| 1662 |
[x509.NameAttribute(x509.NameOID.COMMON_NAME, "Unit Tests")] |
| 1663 |
) |
| 1664 |
when = datetime.now() |
| 1665 |
builder = ( |
| 1666 |
x509.CertificateBuilder() |
| 1667 |
.public_key(key.public_key()) |
| 1668 |
.subject_name(subject) |
| 1669 |
.issuer_name(subject) |
| 1670 |
.not_valid_before(when) |
| 1671 |
.not_valid_after(when) |
| 1672 |
.serial_number(1) |
| 1673 |
) |
| 1674 |
for i, ext in enumerate(extensions): |
| 1675 |
builder = builder.add_extension(ext, critical=i % 2 == 0) |
| 1676 |
|
| 1677 |
return X509.from_cryptography(builder.sign(key, hashes.SHA256())) |
| 1678 |
|
| 1679 |
def test_extension_count(self) -> None: |
| 1680 |
""" |
| 1681 |
`X509.get_extension_count` returns the number of extensions |
| 1682 |
that are present in the certificate. |
| 1683 |
""" |
| 1684 |
pkey = load_privatekey( |
| 1685 |
FILETYPE_PEM, client_key_pem |
| 1686 |
).to_cryptography_key() |
| 1687 |
assert isinstance(pkey, rsa.RSAPrivateKey) |
| 1688 |
ca = x509.BasicConstraints(ca=False, path_length=None) |
| 1689 |
key = x509.KeyUsage( |
| 1690 |
digital_signature=True, |
| 1691 |
content_commitment=False, |
| 1692 |
key_encipherment=False, |
| 1693 |
data_encipherment=False, |
| 1694 |
key_agreement=False, |
| 1695 |
key_cert_sign=False, |
| 1696 |
crl_sign=False, |
| 1697 |
encipher_only=False, |
| 1698 |
decipher_only=False, |
| 1699 |
) |
| 1700 |
san = x509.SubjectAlternativeName([x509.DNSName("example.com")]) |
| 1701 |
|
| 1702 |
# Try a certificate with no extensions at all. |
| 1703 |
c = self._extcert(pkey, []) |
| 1704 |
assert c.get_extension_count() == 0 |
| 1705 |
|
| 1706 |
# And a certificate with one |
| 1707 |
c = self._extcert(pkey, [ca]) |
| 1708 |
assert c.get_extension_count() == 1 |
| 1709 |
|
| 1710 |
# And a certificate with several |
| 1711 |
c = self._extcert(pkey, [ca, key, san]) |
| 1712 |
assert c.get_extension_count() == 3 |
| 1713 |
|
| 1714 |
def test_invalid_digest_algorithm(self) -> None: |
| 1715 |
""" |
| 1716 |
`X509.digest` raises `ValueError` if called with an unrecognized hash |
| 1717 |
algorithm. |
| 1718 |
""" |
| 1719 |
cert = X509() |
| 1720 |
with pytest.raises(ValueError): |
| 1721 |
cert.digest(BAD_DIGEST) |
| 1722 |
|
| 1723 |
def test_get_subject(self) -> None: |
| 1724 |
""" |
| 1725 |
`X509.get_subject` returns an `X509Name` instance. |
| 1726 |
""" |
| 1727 |
cert = load_certificate(FILETYPE_PEM, self.pemData) |
| 1728 |
subj = cert.get_subject() |
| 1729 |
assert isinstance(subj, X509Name) |
| 1730 |
assert subj.get_components() == [ |
| 1731 |
(b"C", b"US"), |
| 1732 |
(b"ST", b"IL"), |
| 1733 |
(b"L", b"Chicago"), |
| 1734 |
(b"O", b"Testing"), |
| 1735 |
(b"CN", b"Testing Root CA"), |
| 1736 |
] |
| 1737 |
|
| 1738 |
def test_set_subject_wrong_args(self) -> None: |
| 1739 |
""" |
| 1740 |
`X509.set_subject` raises a `TypeError` if called with an argument not |
| 1741 |
of type `X509Name`. |
| 1742 |
""" |
| 1743 |
cert = X509() |
| 1744 |
with pytest.raises(TypeError): |
| 1745 |
cert.set_subject(None) # type: ignore[arg-type] |
| 1746 |
|
| 1747 |
def test_set_subject(self) -> None: |
| 1748 |
""" |
| 1749 |
`X509.set_subject` changes the subject of the certificate to the one |
| 1750 |
passed in. |
| 1751 |
""" |
| 1752 |
cert = X509() |
| 1753 |
name = cert.get_subject() |
| 1754 |
name.C = "AU" |
| 1755 |
name.OU = "Unit Tests" |
| 1756 |
cert.set_subject(name) |
| 1757 |
assert cert.get_subject().get_components() == [ |
| 1758 |
(b"C", b"AU"), |
| 1759 |
(b"OU", b"Unit Tests"), |
| 1760 |
] |
| 1761 |
|
| 1762 |
def test_get_issuer(self) -> None: |
| 1763 |
""" |
| 1764 |
`X509.get_issuer` returns an `X509Name` instance. |
| 1765 |
""" |
| 1766 |
cert = load_certificate(FILETYPE_PEM, self.pemData) |
| 1767 |
subj = cert.get_issuer() |
| 1768 |
assert isinstance(subj, X509Name) |
| 1769 |
comp = subj.get_components() |
| 1770 |
assert comp == [ |
| 1771 |
(b"C", b"US"), |
| 1772 |
(b"ST", b"IL"), |
| 1773 |
(b"L", b"Chicago"), |
| 1774 |
(b"O", b"Testing"), |
| 1775 |
(b"CN", b"Testing Root CA"), |
| 1776 |
] |
| 1777 |
|
| 1778 |
def test_set_issuer_wrong_args(self) -> None: |
| 1779 |
""" |
| 1780 |
`X509.set_issuer` raises a `TypeError` if called with an argument not |
| 1781 |
of type `X509Name`. |
| 1782 |
""" |
| 1783 |
cert = X509() |
| 1784 |
with pytest.raises(TypeError): |
| 1785 |
cert.set_issuer(None) # type: ignore[arg-type] |
| 1786 |
|
| 1787 |
def test_set_issuer(self) -> None: |
| 1788 |
""" |
| 1789 |
`X509.set_issuer` changes the issuer of the certificate to the |
| 1790 |
one passed in. |
| 1791 |
""" |
| 1792 |
cert = X509() |
| 1793 |
name = cert.get_issuer() |
| 1794 |
name.C = "AU" |
| 1795 |
name.OU = "Unit Tests" |
| 1796 |
cert.set_issuer(name) |
| 1797 |
assert cert.get_issuer().get_components() == [ |
| 1798 |
(b"C", b"AU"), |
| 1799 |
(b"OU", b"Unit Tests"), |
| 1800 |
] |
| 1801 |
|
| 1802 |
def test_get_pubkey_uninitialized(self) -> None: |
| 1803 |
""" |
| 1804 |
When called on a certificate with no public key, `X509.get_pubkey` |
| 1805 |
raises `OpenSSL.crypto.Error`. |
| 1806 |
""" |
| 1807 |
cert = X509() |
| 1808 |
with pytest.raises(Error): |
| 1809 |
cert.get_pubkey() |
| 1810 |
|
| 1811 |
def test_set_pubkey_wrong_type(self) -> None: |
| 1812 |
""" |
| 1813 |
`X509.set_pubkey` raises `TypeError` when given an object of the |
| 1814 |
wrong type. |
| 1815 |
""" |
| 1816 |
cert = X509() |
| 1817 |
with pytest.raises(TypeError): |
| 1818 |
cert.set_pubkey(object()) # type: ignore[arg-type] |
| 1819 |
|
| 1820 |
def test_subject_name_hash(self) -> None: |
| 1821 |
""" |
| 1822 |
`X509.subject_name_hash` returns the hash of the certificate's |
| 1823 |
subject name. |
| 1824 |
""" |
| 1825 |
cert = load_certificate(FILETYPE_PEM, self.pemData) |
| 1826 |
# SHA1 |
| 1827 |
assert cert.subject_name_hash() == 3278919224 |
| 1828 |
|
| 1829 |
def test_get_signature_algorithm(self) -> None: |
| 1830 |
""" |
| 1831 |
`X509.get_signature_algorithm` returns a string which means |
| 1832 |
the algorithm used to sign the certificate. |
| 1833 |
""" |
| 1834 |
cert = load_certificate(FILETYPE_PEM, self.pemData) |
| 1835 |
assert b"sha256WithRSAEncryption" == cert.get_signature_algorithm() |
| 1836 |
|
| 1837 |
def test_get_undefined_signature_algorithm(self) -> None: |
| 1838 |
""" |
| 1839 |
`X509.get_signature_algorithm` raises `ValueError` if the signature |
| 1840 |
algorithm is undefined or unknown. |
| 1841 |
""" |
| 1842 |
# This certificate has been modified to indicate a bogus OID in the |
| 1843 |
# signature algorithm field so that OpenSSL does not recognize it. |
| 1844 |
certPEM = b"""\ |
| 1845 |
-----BEGIN CERTIFICATE----- |
| 1846 |
MIIC/zCCAmigAwIBAgIBATAGBgJ8BQUAMHsxCzAJBgNVBAYTAlNHMREwDwYDVQQK |
| 1847 |
EwhNMkNyeXB0bzEUMBIGA1UECxMLTTJDcnlwdG8gQ0ExJDAiBgNVBAMTG00yQ3J5 |
| 1848 |
cHRvIENlcnRpZmljYXRlIE1hc3RlcjEdMBsGCSqGSIb3DQEJARYObmdwc0Bwb3N0 |
| 1849 |
MS5jb20wHhcNMDAwOTEwMDk1MTMwWhcNMDIwOTEwMDk1MTMwWjBTMQswCQYDVQQG |
| 1850 |
EwJTRzERMA8GA1UEChMITTJDcnlwdG8xEjAQBgNVBAMTCWxvY2FsaG9zdDEdMBsG |
| 1851 |
CSqGSIb3DQEJARYObmdwc0Bwb3N0MS5jb20wXDANBgkqhkiG9w0BAQEFAANLADBI |
| 1852 |
AkEArL57d26W9fNXvOhNlZzlPOACmvwOZ5AdNgLzJ1/MfsQQJ7hHVeHmTAjM664V |
| 1853 |
+fXvwUGJLziCeBo1ysWLRnl8CQIDAQABo4IBBDCCAQAwCQYDVR0TBAIwADAsBglg |
| 1854 |
hkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYDVR0O |
| 1855 |
BBYEFM+EgpK+eyZiwFU1aOPSbczbPSpVMIGlBgNVHSMEgZ0wgZqAFPuHI2nrnDqT |
| 1856 |
FeXFvylRT/7tKDgBoX+kfTB7MQswCQYDVQQGEwJTRzERMA8GA1UEChMITTJDcnlw |
| 1857 |
dG8xFDASBgNVBAsTC00yQ3J5cHRvIENBMSQwIgYDVQQDExtNMkNyeXB0byBDZXJ0 |
| 1858 |
aWZpY2F0ZSBNYXN0ZXIxHTAbBgkqhkiG9w0BCQEWDm5ncHNAcG9zdDEuY29tggEA |
| 1859 |
MA0GCSqGSIb3DQEBBAUAA4GBADv8KpPo+gfJxN2ERK1Y1l17sz/ZhzoGgm5XCdbx |
| 1860 |
jEY7xKfpQngV599k1xhl11IMqizDwu0855agrckg2MCTmOI9DZzDD77tAYb+Dk0O |
| 1861 |
PEVk0Mk/V0aIsDE9bolfCi/i/QWZ3N8s5nTWMNyBBBmoSliWCm4jkkRZRD0ejgTN |
| 1862 |
tgI5 |
| 1863 |
-----END CERTIFICATE----- |
| 1864 |
""" |
| 1865 |
cert = load_certificate(FILETYPE_PEM, certPEM) |
| 1866 |
with pytest.raises(ValueError): |
| 1867 |
cert.get_signature_algorithm() |
| 1868 |
|
| 1869 |
def test_sign_bad_pubkey_type(self) -> None: |
| 1870 |
""" |
| 1871 |
`X509.sign` raises `TypeError` when called with the wrong type. |
| 1872 |
""" |
| 1873 |
cert = X509() |
| 1874 |
with pytest.raises(TypeError): |
| 1875 |
cert.sign(object(), b"sha256") # type: ignore[arg-type] |
| 1876 |
|
| 1877 |
def test_convert_from_cryptography(self) -> None: |
| 1878 |
crypto_cert = x509.load_pem_x509_certificate(intermediate_cert_pem) |
| 1879 |
cert = X509.from_cryptography(crypto_cert) |
| 1880 |
|
| 1881 |
assert isinstance(cert, X509) |
| 1882 |
assert cert.get_version() == crypto_cert.version.value |
| 1883 |
|
| 1884 |
def test_convert_from_cryptography_unsupported_type(self) -> None: |
| 1885 |
with pytest.raises(TypeError): |
| 1886 |
X509.from_cryptography(object()) # type: ignore[arg-type] |
| 1887 |
|
| 1888 |
def test_convert_to_cryptography_key(self) -> None: |
| 1889 |
cert = load_certificate(FILETYPE_PEM, intermediate_cert_pem) |
| 1890 |
crypto_cert = cert.to_cryptography() |
| 1891 |
|
| 1892 |
assert isinstance(crypto_cert, x509.Certificate) |
| 1893 |
assert crypto_cert.version.value == cert.get_version() |
| 1894 |
|
| 1895 |
|
| 1896 |
class TestX509Store: |
| 1897 |
""" |
| 1898 |
Test for `OpenSSL.crypto.X509Store`. |
| 1899 |
""" |
| 1900 |
|
| 1901 |
def test_add_cert(self) -> None: |
| 1902 |
""" |
| 1903 |
`X509Store.add_cert` adds a `X509` instance to the certificate store. |
| 1904 |
""" |
| 1905 |
cert = load_certificate(FILETYPE_PEM, root_cert_pem) |
| 1906 |
store = X509Store() |
| 1907 |
store.add_cert(cert) |
| 1908 |
|
| 1909 |
@pytest.mark.parametrize("cert", [None, 1.0, "cert", object()]) |
| 1910 |
def test_add_cert_wrong_args(self, cert: object) -> None: |
| 1911 |
""" |
| 1912 |
`X509Store.add_cert` raises `TypeError` if passed a non-X509 object |
| 1913 |
as its first argument. |
| 1914 |
""" |
| 1915 |
store = X509Store() |
| 1916 |
with pytest.raises(TypeError): |
| 1917 |
store.add_cert(cert) # type: ignore[arg-type] |
| 1918 |
|
| 1919 |
def test_add_cert_accepts_duplicate(self) -> None: |
| 1920 |
""" |
| 1921 |
`X509Store.add_cert` doesn't raise `OpenSSL.crypto.Error` if an attempt |
| 1922 |
is made to add the same certificate to the store more than once. |
| 1923 |
""" |
| 1924 |
cert = load_certificate(FILETYPE_PEM, root_cert_pem) |
| 1925 |
store = X509Store() |
| 1926 |
store.add_cert(cert) |
| 1927 |
store.add_cert(cert) |
| 1928 |
|
| 1929 |
@pytest.mark.parametrize( |
| 1930 |
"cafile, capath, call_cafile, call_capath", |
| 1931 |
[ |
| 1932 |
( |
| 1933 |
"/cafile" + NON_ASCII, |
| 1934 |
None, |
| 1935 |
b"/cafile" + NON_ASCII.encode(sys.getfilesystemencoding()), |
| 1936 |
_ffi.NULL, |
| 1937 |
), |
| 1938 |
( |
| 1939 |
b"/cafile" + NON_ASCII.encode("utf-8"), |
| 1940 |
None, |
| 1941 |
b"/cafile" + NON_ASCII.encode("utf-8"), |
| 1942 |
_ffi.NULL, |
| 1943 |
), |
| 1944 |
( |
| 1945 |
None, |
| 1946 |
"/capath" + NON_ASCII, |
| 1947 |
_ffi.NULL, |
| 1948 |
b"/capath" + NON_ASCII.encode(sys.getfilesystemencoding()), |
| 1949 |
), |
| 1950 |
( |
| 1951 |
None, |
| 1952 |
b"/capath" + NON_ASCII.encode("utf-8"), |
| 1953 |
_ffi.NULL, |
| 1954 |
b"/capath" + NON_ASCII.encode("utf-8"), |
| 1955 |
), |
| 1956 |
], |
| 1957 |
) |
| 1958 |
def test_load_locations_parameters( |
| 1959 |
self, |
| 1960 |
cafile: str | bytes | None, |
| 1961 |
capath: str | bytes | None, |
| 1962 |
call_cafile: object, |
| 1963 |
call_capath: object, |
| 1964 |
monkeypatch: pytest.MonkeyPatch, |
| 1965 |
) -> None: |
| 1966 |
class LibMock: |
| 1967 |
def load_locations( |
| 1968 |
self, store: object, cafile: object, capath: object |
| 1969 |
) -> int: |
| 1970 |
self.cafile = cafile |
| 1971 |
self.capath = capath |
| 1972 |
return 1 |
| 1973 |
|
| 1974 |
lib_mock = LibMock() |
| 1975 |
monkeypatch.setattr( |
| 1976 |
_lib, "X509_STORE_load_locations", lib_mock.load_locations |
| 1977 |
) |
| 1978 |
|
| 1979 |
store = X509Store() |
| 1980 |
store.load_locations(cafile=cafile, capath=capath) |
| 1981 |
|
| 1982 |
assert call_cafile == lib_mock.cafile |
| 1983 |
assert call_capath == lib_mock.capath |
| 1984 |
|
| 1985 |
def test_load_locations_fails_when_all_args_are_none(self) -> None: |
| 1986 |
store = X509Store() |
| 1987 |
with pytest.raises(Error): |
| 1988 |
store.load_locations(None, None) |
| 1989 |
|
| 1990 |
def test_load_locations_raises_error_on_failure( |
| 1991 |
self, tmp_path: pathlib.Path |
| 1992 |
) -> None: |
| 1993 |
invalid_ca_file = tmp_path / "invalid.pem" |
| 1994 |
invalid_ca_file.write_text("This is not a certificate") |
| 1995 |
|
| 1996 |
store = X509Store() |
| 1997 |
with pytest.raises(Error): |
| 1998 |
store.load_locations(cafile=str(invalid_ca_file)) |
| 1999 |
|
| 2000 |
|
| 2001 |
def _runopenssl(pem: bytes, *args: bytes) -> bytes: |
| 2002 |
""" |
| 2003 |
Run the command line openssl tool with the given arguments and write |
| 2004 |
the given PEM to its stdin. Not safe for quotes. |
| 2005 |
""" |
| 2006 |
proc = Popen([b"openssl", *list(args)], stdin=PIPE, stdout=PIPE) |
| 2007 |
output, _ = proc.communicate(pem) |
| 2008 |
return output |
| 2009 |
|
| 2010 |
|
| 2011 |
class TestLoadPublicKey: |
| 2012 |
""" |
| 2013 |
Tests for :func:`load_publickey`. |
| 2014 |
""" |
| 2015 |
|
| 2016 |
def test_loading_works(self) -> None: |
| 2017 |
""" |
| 2018 |
load_publickey loads public keys and sets correct attributes. |
| 2019 |
""" |
| 2020 |
key = load_publickey(FILETYPE_PEM, cleartextPublicKeyPEM) |
| 2021 |
|
| 2022 |
assert True is key._only_public |
| 2023 |
assert 2048 == key.bits() |
| 2024 |
assert TYPE_RSA == key.type() |
| 2025 |
|
| 2026 |
def test_invalid_type(self) -> None: |
| 2027 |
""" |
| 2028 |
load_publickey doesn't support FILETYPE_TEXT. |
| 2029 |
""" |
| 2030 |
with pytest.raises(ValueError): |
| 2031 |
load_publickey(FILETYPE_TEXT, cleartextPublicKeyPEM) |
| 2032 |
|
| 2033 |
def test_invalid_key_format(self) -> None: |
| 2034 |
""" |
| 2035 |
load_publickey explodes on incorrect keys. |
| 2036 |
""" |
| 2037 |
with pytest.raises(Error): |
| 2038 |
load_publickey(FILETYPE_ASN1, cleartextPublicKeyPEM) |
| 2039 |
|
| 2040 |
def test_tolerates_unicode_strings(self) -> None: |
| 2041 |
""" |
| 2042 |
load_publickey works with text strings, not just bytes. |
| 2043 |
""" |
| 2044 |
serialized = cleartextPublicKeyPEM.decode("ascii") |
| 2045 |
key = load_publickey(FILETYPE_PEM, serialized) |
| 2046 |
dumped_pem = dump_publickey(FILETYPE_PEM, key) |
| 2047 |
|
| 2048 |
assert dumped_pem == cleartextPublicKeyPEM |
| 2049 |
|
| 2050 |
|
| 2051 |
class TestFunction: |
| 2052 |
""" |
| 2053 |
Tests for free-functions in the `OpenSSL.crypto` module. |
| 2054 |
""" |
| 2055 |
|
| 2056 |
def test_load_privatekey_invalid_format(self) -> None: |
| 2057 |
""" |
| 2058 |
`load_privatekey` raises `ValueError` if passed an unknown filetype. |
| 2059 |
""" |
| 2060 |
with pytest.raises(ValueError): |
| 2061 |
load_privatekey(100, root_key_pem) |
| 2062 |
|
| 2063 |
def test_load_privatekey_invalid_passphrase_type(self) -> None: |
| 2064 |
""" |
| 2065 |
`load_privatekey` raises `TypeError` if passed a passphrase that is |
| 2066 |
neither a `str` nor a callable. |
| 2067 |
""" |
| 2068 |
with pytest.raises(TypeError): |
| 2069 |
load_privatekey( |
| 2070 |
FILETYPE_PEM, |
| 2071 |
encryptedPrivateKeyPEMPassphrase, |
| 2072 |
object(), # type: ignore[arg-type] |
| 2073 |
) |
| 2074 |
|
| 2075 |
def test_load_privatekey_wrongPassphrase(self) -> None: |
| 2076 |
""" |
| 2077 |
`load_privatekey` raises `OpenSSL.crypto.Error` when it is passed an |
| 2078 |
encrypted PEM and an incorrect passphrase. |
| 2079 |
""" |
| 2080 |
with pytest.raises(Error) as err: |
| 2081 |
load_privatekey(FILETYPE_PEM, encryptedPrivateKeyPEM, b"quack") |
| 2082 |
assert err.value.args[0] != [] |
| 2083 |
|
| 2084 |
def test_load_privatekey_passphraseWrongType(self) -> None: |
| 2085 |
""" |
| 2086 |
`load_privatekey` raises `ValueError` when it is passed a passphrase |
| 2087 |
with a private key encoded in a format, that doesn't support |
| 2088 |
encryption. |
| 2089 |
""" |
| 2090 |
key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2091 |
blob = dump_privatekey(FILETYPE_ASN1, key) |
| 2092 |
with pytest.raises(ValueError): |
| 2093 |
load_privatekey(FILETYPE_ASN1, blob, b"secret") |
| 2094 |
|
| 2095 |
def test_load_privatekey_passphrase(self) -> None: |
| 2096 |
""" |
| 2097 |
`load_privatekey` can create a `PKey` object from an encrypted PEM |
| 2098 |
string if given the passphrase. |
| 2099 |
""" |
| 2100 |
key = load_privatekey( |
| 2101 |
FILETYPE_PEM, |
| 2102 |
encryptedPrivateKeyPEM, |
| 2103 |
encryptedPrivateKeyPEMPassphrase, |
| 2104 |
) |
| 2105 |
assert isinstance(key, PKey) |
| 2106 |
|
| 2107 |
def test_load_privatekey_passphrase_exception(self) -> None: |
| 2108 |
""" |
| 2109 |
If the passphrase callback raises an exception, that exception is |
| 2110 |
raised by `load_privatekey`. |
| 2111 |
""" |
| 2112 |
|
| 2113 |
def cb(ignored: object) -> bytes: |
| 2114 |
raise ArithmeticError |
| 2115 |
|
| 2116 |
with pytest.raises(ArithmeticError): |
| 2117 |
load_privatekey(FILETYPE_PEM, encryptedPrivateKeyPEM, cb) |
| 2118 |
|
| 2119 |
def test_load_privatekey_wrongPassphraseCallback(self) -> None: |
| 2120 |
""" |
| 2121 |
`load_privatekey` raises `OpenSSL.crypto.Error` when it |
| 2122 |
is passed an encrypted PEM and a passphrase callback which returns an |
| 2123 |
incorrect passphrase. |
| 2124 |
""" |
| 2125 |
called = False |
| 2126 |
|
| 2127 |
def cb(*a: object) -> bytes: |
| 2128 |
nonlocal called |
| 2129 |
called = True |
| 2130 |
return b"quack" |
| 2131 |
|
| 2132 |
with pytest.raises(Error) as err: |
| 2133 |
load_privatekey(FILETYPE_PEM, encryptedPrivateKeyPEM, cb) |
| 2134 |
assert called |
| 2135 |
assert err.value.args[0] != [] |
| 2136 |
|
| 2137 |
def test_load_privatekey_passphraseCallback(self) -> None: |
| 2138 |
""" |
| 2139 |
`load_privatekey` can create a `PKey` object from an encrypted PEM |
| 2140 |
string if given a passphrase callback which returns the correct |
| 2141 |
password. |
| 2142 |
""" |
| 2143 |
called = [] |
| 2144 |
|
| 2145 |
def cb(writing: bool) -> bytes: |
| 2146 |
called.append(writing) |
| 2147 |
return encryptedPrivateKeyPEMPassphrase |
| 2148 |
|
| 2149 |
key = load_privatekey(FILETYPE_PEM, encryptedPrivateKeyPEM, cb) |
| 2150 |
assert isinstance(key, PKey) |
| 2151 |
assert called == [False] |
| 2152 |
|
| 2153 |
def test_load_privatekey_passphrase_wrong_return_type(self) -> None: |
| 2154 |
""" |
| 2155 |
`load_privatekey` raises `ValueError` if the passphrase callback |
| 2156 |
returns something other than a byte string. |
| 2157 |
""" |
| 2158 |
with pytest.raises(ValueError): |
| 2159 |
load_privatekey( |
| 2160 |
FILETYPE_PEM, |
| 2161 |
encryptedPrivateKeyPEM, |
| 2162 |
lambda *args: 3, # type: ignore[arg-type] |
| 2163 |
) |
| 2164 |
|
| 2165 |
def test_dump_privatekey_wrong_args(self) -> None: |
| 2166 |
""" |
| 2167 |
`dump_privatekey` raises `TypeError` if called with a `cipher` |
| 2168 |
argument but no `passphrase` argument. |
| 2169 |
""" |
| 2170 |
key = PKey() |
| 2171 |
key.generate_key(TYPE_RSA, 2048) |
| 2172 |
with pytest.raises(TypeError): |
| 2173 |
dump_privatekey(FILETYPE_PEM, key, cipher=GOOD_CIPHER) |
| 2174 |
|
| 2175 |
def test_dump_privatekey_not_rsa_key(self) -> None: |
| 2176 |
""" |
| 2177 |
`dump_privatekey` raises `TypeError` if called with a key that is |
| 2178 |
not RSA. |
| 2179 |
""" |
| 2180 |
key = PKey() |
| 2181 |
key.generate_key(TYPE_DSA, 512) |
| 2182 |
with pytest.raises(TypeError): |
| 2183 |
dump_privatekey(FILETYPE_TEXT, key) |
| 2184 |
|
| 2185 |
def test_dump_privatekey_invalid_pkey(self) -> None: |
| 2186 |
with pytest.raises(TypeError): |
| 2187 |
dump_privatekey(FILETYPE_TEXT, object()) # type: ignore[arg-type] |
| 2188 |
|
| 2189 |
def test_dump_privatekey_unknown_cipher(self) -> None: |
| 2190 |
""" |
| 2191 |
`dump_privatekey` raises `ValueError` if called with an unrecognized |
| 2192 |
cipher name. |
| 2193 |
""" |
| 2194 |
key = PKey() |
| 2195 |
key.generate_key(TYPE_RSA, 2048) |
| 2196 |
with pytest.raises(ValueError): |
| 2197 |
dump_privatekey(FILETYPE_PEM, key, BAD_CIPHER, b"passphrase") |
| 2198 |
|
| 2199 |
def test_dump_privatekey_invalid_passphrase_type(self) -> None: |
| 2200 |
""" |
| 2201 |
`dump_privatekey` raises `TypeError` if called with a passphrase which |
| 2202 |
is neither a `str` nor a callable. |
| 2203 |
""" |
| 2204 |
key = PKey() |
| 2205 |
key.generate_key(TYPE_RSA, 2048) |
| 2206 |
with pytest.raises(TypeError): |
| 2207 |
dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, object()) # type: ignore[arg-type] |
| 2208 |
|
| 2209 |
def test_dump_privatekey_invalid_filetype(self) -> None: |
| 2210 |
""" |
| 2211 |
`dump_privatekey` raises `ValueError` if called with an unrecognized |
| 2212 |
filetype. |
| 2213 |
""" |
| 2214 |
key = PKey() |
| 2215 |
key.generate_key(TYPE_RSA, 2048) |
| 2216 |
with pytest.raises(ValueError): |
| 2217 |
dump_privatekey(100, key) |
| 2218 |
|
| 2219 |
def test_load_privatekey_passphrase_callback_length(self) -> None: |
| 2220 |
""" |
| 2221 |
`crypto.load_privatekey` should raise an error when the passphrase |
| 2222 |
provided by the callback is too long, not silently truncate it. |
| 2223 |
""" |
| 2224 |
|
| 2225 |
def cb(ignored: object) -> bytes: |
| 2226 |
return b"a" * 1025 |
| 2227 |
|
| 2228 |
with pytest.raises(ValueError): |
| 2229 |
load_privatekey(FILETYPE_PEM, encryptedPrivateKeyPEM, cb) |
| 2230 |
|
| 2231 |
def test_dump_privatekey_passphrase(self) -> None: |
| 2232 |
""" |
| 2233 |
`dump_privatekey` writes an encrypted PEM when given a passphrase. |
| 2234 |
""" |
| 2235 |
passphrase = b"foo" |
| 2236 |
key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2237 |
pem = dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, passphrase) |
| 2238 |
assert isinstance(pem, bytes) |
| 2239 |
loadedKey = load_privatekey(FILETYPE_PEM, pem, passphrase) |
| 2240 |
assert isinstance(loadedKey, PKey) |
| 2241 |
assert loadedKey.type() == key.type() |
| 2242 |
assert loadedKey.bits() == key.bits() |
| 2243 |
|
| 2244 |
def test_dump_privatekey_passphrase_wrong_type(self) -> None: |
| 2245 |
""" |
| 2246 |
`dump_privatekey` raises `ValueError` when it is passed a passphrase |
| 2247 |
with a private key encoded in a format, that doesn't support |
| 2248 |
encryption. |
| 2249 |
""" |
| 2250 |
key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2251 |
with pytest.raises(ValueError): |
| 2252 |
dump_privatekey(FILETYPE_ASN1, key, GOOD_CIPHER, b"secret") |
| 2253 |
|
| 2254 |
def test_dump_certificate(self) -> None: |
| 2255 |
""" |
| 2256 |
`dump_certificate` writes PEM, DER, and text. |
| 2257 |
""" |
| 2258 |
pemData = root_cert_pem + root_key_pem |
| 2259 |
cert = load_certificate(FILETYPE_PEM, pemData) |
| 2260 |
dumped_pem = dump_certificate(FILETYPE_PEM, cert) |
| 2261 |
assert dumped_pem == root_cert_pem |
| 2262 |
dumped_der = dump_certificate(FILETYPE_ASN1, cert) |
| 2263 |
good_der = _runopenssl(dumped_pem, b"x509", b"-outform", b"DER") |
| 2264 |
assert dumped_der == good_der |
| 2265 |
cert2 = load_certificate(FILETYPE_ASN1, dumped_der) |
| 2266 |
dumped_pem2 = dump_certificate(FILETYPE_PEM, cert2) |
| 2267 |
assert dumped_pem2 == root_cert_pem |
| 2268 |
dumped_text = dump_certificate(FILETYPE_TEXT, cert) |
| 2269 |
assert len(dumped_text) > 500 |
| 2270 |
|
| 2271 |
def test_dump_certificate_bad_type(self) -> None: |
| 2272 |
""" |
| 2273 |
`dump_certificate` raises a `ValueError` if it's called with |
| 2274 |
a bad type. |
| 2275 |
""" |
| 2276 |
cert = load_certificate(FILETYPE_PEM, root_cert_pem) |
| 2277 |
with pytest.raises(ValueError): |
| 2278 |
dump_certificate(object(), cert) # type: ignore[arg-type] |
| 2279 |
|
| 2280 |
def test_dump_privatekey_pem(self) -> None: |
| 2281 |
""" |
| 2282 |
`dump_privatekey` writes a PEM |
| 2283 |
""" |
| 2284 |
key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2285 |
assert key.check() |
| 2286 |
dumped_pem = dump_privatekey(FILETYPE_PEM, key) |
| 2287 |
assert dumped_pem == normalized_root_key_pem |
| 2288 |
|
| 2289 |
def test_dump_privatekey_asn1(self) -> None: |
| 2290 |
""" |
| 2291 |
`dump_privatekey` writes a DER |
| 2292 |
""" |
| 2293 |
key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2294 |
|
| 2295 |
dumped_der = dump_privatekey(FILETYPE_ASN1, key) |
| 2296 |
assert dumped_der == root_key_der |
| 2297 |
|
| 2298 |
def test_load_privatekey_asn1(self) -> None: |
| 2299 |
""" |
| 2300 |
`dump_privatekey` writes a DER |
| 2301 |
""" |
| 2302 |
key = load_privatekey(FILETYPE_ASN1, root_key_der) |
| 2303 |
assert key.bits() == 3072 |
| 2304 |
assert key.type() == TYPE_RSA |
| 2305 |
|
| 2306 |
def test_dump_privatekey_text(self) -> None: |
| 2307 |
""" |
| 2308 |
`dump_privatekey` writes a text |
| 2309 |
""" |
| 2310 |
key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2311 |
dumped_text = dump_privatekey(FILETYPE_TEXT, key) |
| 2312 |
assert len(dumped_text) > 500 |
| 2313 |
|
| 2314 |
def test_dump_publickey_pem(self) -> None: |
| 2315 |
""" |
| 2316 |
dump_publickey writes a PEM. |
| 2317 |
""" |
| 2318 |
key = load_publickey(FILETYPE_PEM, cleartextPublicKeyPEM) |
| 2319 |
dumped_pem = dump_publickey(FILETYPE_PEM, key) |
| 2320 |
assert dumped_pem == cleartextPublicKeyPEM |
| 2321 |
|
| 2322 |
def test_dump_publickey_asn1(self) -> None: |
| 2323 |
""" |
| 2324 |
dump_publickey writes a DER. |
| 2325 |
""" |
| 2326 |
key = load_publickey(FILETYPE_PEM, cleartextPublicKeyPEM) |
| 2327 |
dumped_der = dump_publickey(FILETYPE_ASN1, key) |
| 2328 |
key2 = load_publickey(FILETYPE_ASN1, dumped_der) |
| 2329 |
dumped_pem2 = dump_publickey(FILETYPE_PEM, key2) |
| 2330 |
assert dumped_pem2 == cleartextPublicKeyPEM |
| 2331 |
|
| 2332 |
def test_dump_publickey_invalid_type(self) -> None: |
| 2333 |
""" |
| 2334 |
dump_publickey doesn't support FILETYPE_TEXT. |
| 2335 |
""" |
| 2336 |
key = load_publickey(FILETYPE_PEM, cleartextPublicKeyPEM) |
| 2337 |
|
| 2338 |
with pytest.raises(ValueError): |
| 2339 |
dump_publickey(FILETYPE_TEXT, key) |
| 2340 |
|
| 2341 |
def test_dump_privatekey_passphrase_callback(self) -> None: |
| 2342 |
""" |
| 2343 |
`dump_privatekey` writes an encrypted PEM when given a callback |
| 2344 |
which returns the correct passphrase. |
| 2345 |
""" |
| 2346 |
passphrase = b"foo" |
| 2347 |
called = [] |
| 2348 |
|
| 2349 |
def cb(writing: bool) -> bytes: |
| 2350 |
called.append(writing) |
| 2351 |
return passphrase |
| 2352 |
|
| 2353 |
key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2354 |
pem = dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, cb) |
| 2355 |
assert isinstance(pem, bytes) |
| 2356 |
assert called == [True] |
| 2357 |
loadedKey = load_privatekey(FILETYPE_PEM, pem, passphrase) |
| 2358 |
assert isinstance(loadedKey, PKey) |
| 2359 |
assert loadedKey.type() == key.type() |
| 2360 |
assert loadedKey.bits() == key.bits() |
| 2361 |
|
| 2362 |
def test_dump_privatekey_passphrase_exception(self) -> None: |
| 2363 |
""" |
| 2364 |
`dump_privatekey` should not overwrite the exception raised |
| 2365 |
by the passphrase callback. |
| 2366 |
""" |
| 2367 |
|
| 2368 |
def cb(ignored: object) -> bytes: |
| 2369 |
raise ArithmeticError |
| 2370 |
|
| 2371 |
key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2372 |
with pytest.raises(ArithmeticError): |
| 2373 |
dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, cb) |
| 2374 |
|
| 2375 |
def test_dump_privatekey_passphraseCallbackLength(self) -> None: |
| 2376 |
""" |
| 2377 |
`crypto.dump_privatekey` should raise an error when the passphrase |
| 2378 |
provided by the callback is too long, not silently truncate it. |
| 2379 |
""" |
| 2380 |
|
| 2381 |
def cb(ignored: object) -> bytes: |
| 2382 |
return b"a" * 1025 |
| 2383 |
|
| 2384 |
key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2385 |
with pytest.raises(ValueError): |
| 2386 |
dump_privatekey(FILETYPE_PEM, key, GOOD_CIPHER, cb) |
| 2387 |
|
| 2388 |
def test_dump_privatekey_truncated(self) -> None: |
| 2389 |
""" |
| 2390 |
`crypto.dump_privatekey` should not truncate a passphrase that contains |
| 2391 |
a null byte. |
| 2392 |
""" |
| 2393 |
key = load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM) |
| 2394 |
passphrase = b"foo\x00bar" |
| 2395 |
truncated_passphrase = passphrase.split(b"\x00", 1)[0] |
| 2396 |
|
| 2397 |
# By dumping with the full passphrase load should raise an error if we |
| 2398 |
# try to load using the truncated passphrase. If dump truncated the |
| 2399 |
# passphrase, then we WILL load the privatekey and the test fails |
| 2400 |
encrypted_key_pem = dump_privatekey( |
| 2401 |
FILETYPE_PEM, key, "AES-256-CBC", passphrase |
| 2402 |
) |
| 2403 |
with pytest.raises(Error): |
| 2404 |
load_privatekey( |
| 2405 |
FILETYPE_PEM, encrypted_key_pem, truncated_passphrase |
| 2406 |
) |
| 2407 |
|
| 2408 |
def test_load_privatekey_truncated(self) -> None: |
| 2409 |
""" |
| 2410 |
`crypto.load_privatekey` should not truncate a passphrase that contains |
| 2411 |
a null byte. |
| 2412 |
""" |
| 2413 |
key = load_privatekey(FILETYPE_PEM, cleartextPrivateKeyPEM) |
| 2414 |
passphrase = b"foo\x00bar" |
| 2415 |
truncated_passphrase = passphrase.split(b"\x00", 1)[0] |
| 2416 |
|
| 2417 |
# By dumping using the truncated passphrase load should raise an error |
| 2418 |
# if we try to load using the full passphrase. If load truncated the |
| 2419 |
# passphrase, then we WILL load the privatekey and the test fails |
| 2420 |
encrypted_key_pem = dump_privatekey( |
| 2421 |
FILETYPE_PEM, key, "AES-256-CBC", truncated_passphrase |
| 2422 |
) |
| 2423 |
with pytest.raises(Error): |
| 2424 |
load_privatekey(FILETYPE_PEM, encrypted_key_pem, passphrase) |
| 2425 |
|
| 2426 |
|
| 2427 |
class TestLoadCertificate: |
| 2428 |
""" |
| 2429 |
Tests for `load_certificate`. |
| 2430 |
""" |
| 2431 |
|
| 2432 |
def test_bad_file_type(self) -> None: |
| 2433 |
""" |
| 2434 |
If the file type passed to `load_certificate` is neither |
| 2435 |
`FILETYPE_PEM` nor `FILETYPE_ASN1` then `ValueError` is raised. |
| 2436 |
""" |
| 2437 |
with pytest.raises(ValueError): |
| 2438 |
load_certificate(object(), b"") # type: ignore[arg-type] |
| 2439 |
|
| 2440 |
def test_bad_certificate(self) -> None: |
| 2441 |
""" |
| 2442 |
If the bytes passed to `load_certificate` are not a valid certificate, |
| 2443 |
an exception is raised. |
| 2444 |
""" |
| 2445 |
with pytest.raises(Error): |
| 2446 |
load_certificate(FILETYPE_ASN1, b"lol") |
| 2447 |
|
| 2448 |
|
| 2449 |
class TestCRL: |
| 2450 |
""" |
| 2451 |
Tests for `OpenSSL.crypto.CRL`. |
| 2452 |
""" |
| 2453 |
|
| 2454 |
cert = load_certificate(FILETYPE_PEM, root_cert_pem) |
| 2455 |
pkey = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2456 |
|
| 2457 |
root_cert = load_certificate(FILETYPE_PEM, root_cert_pem) |
| 2458 |
root_key = load_privatekey(FILETYPE_PEM, root_key_pem) |
| 2459 |
intermediate_cert = load_certificate(FILETYPE_PEM, intermediate_cert_pem) |
| 2460 |
intermediate_key = load_privatekey(FILETYPE_PEM, intermediate_key_pem) |
| 2461 |
intermediate_server_cert = load_certificate( |
| 2462 |
FILETYPE_PEM, intermediate_server_cert_pem |
| 2463 |
) |
| 2464 |
intermediate_server_key = load_privatekey( |
| 2465 |
FILETYPE_PEM, intermediate_server_key_pem |
| 2466 |
) |
| 2467 |
|
| 2468 |
@staticmethod |
| 2469 |
def _make_test_crl_cryptography( |
| 2470 |
issuer_cert: X509, issuer_key: PKey, certs: list[X509] = [] |
| 2471 |
) -> x509.CertificateRevocationList: |
| 2472 |
""" |
| 2473 |
Create a CRL using cryptography's API. |
| 2474 |
|
| 2475 |
:param list[X509] certs: A list of certificates to revoke. |
| 2476 |
:rtype: ``cryptography.x509.CertificateRevocationList`` |
| 2477 |
""" |
| 2478 |
from cryptography.x509.extensions import CRLReason, ReasonFlags |
| 2479 |
|
| 2480 |
builder = x509.CertificateRevocationListBuilder() |
| 2481 |
builder = builder.issuer_name(issuer_cert.to_cryptography().subject) |
| 2482 |
for cert in certs: |
| 2483 |
revoked = ( |
| 2484 |
x509.RevokedCertificateBuilder() |
| 2485 |
.serial_number(cert.get_serial_number()) |
| 2486 |
.revocation_date(datetime(2014, 6, 1, 0, 0, 0)) |
| 2487 |
.add_extension(CRLReason(ReasonFlags.unspecified), False) |
| 2488 |
.build() |
| 2489 |
) |
| 2490 |
builder = builder.add_revoked_certificate(revoked) |
| 2491 |
|
| 2492 |
builder = builder.last_update(datetime(2014, 6, 1, 0, 0, 0)) |
| 2493 |
# The year 5000 is far into the future so that this CRL isn't |
| 2494 |
# considered to have expired. |
| 2495 |
builder = builder.next_update(datetime(5000, 6, 1, 0, 0, 0)) |
| 2496 |
|
| 2497 |
key = issuer_key.to_cryptography_key() |
| 2498 |
assert isinstance(key, rsa.RSAPrivateKey) |
| 2499 |
crl = builder.sign( |
| 2500 |
key, |
| 2501 |
algorithm=hashes.SHA512(), |
| 2502 |
) |
| 2503 |
return crl |
| 2504 |
|
| 2505 |
def test_verify_with_revoked(self) -> None: |
| 2506 |
""" |
| 2507 |
`verify_certificate` raises error when an intermediate certificate is |
| 2508 |
revoked. |
| 2509 |
""" |
| 2510 |
store = X509Store() |
| 2511 |
store.add_cert(self.root_cert) |
| 2512 |
store.add_cert(self.intermediate_cert) |
| 2513 |
root_crl = self._make_test_crl_cryptography( |
| 2514 |
self.root_cert, self.root_key, certs=[self.intermediate_cert] |
| 2515 |
) |
| 2516 |
intermediate_crl = self._make_test_crl_cryptography( |
| 2517 |
self.intermediate_cert, self.intermediate_key, certs=[] |
| 2518 |
) |
| 2519 |
store.add_crl(root_crl) |
| 2520 |
store.add_crl(intermediate_crl) |
| 2521 |
store.set_flags( |
| 2522 |
X509StoreFlags.CRL_CHECK | X509StoreFlags.CRL_CHECK_ALL |
| 2523 |
) |
| 2524 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2525 |
with pytest.raises(X509StoreContextError) as err: |
| 2526 |
store_ctx.verify_certificate() |
| 2527 |
assert str(err.value) == "certificate revoked" |
| 2528 |
|
| 2529 |
def test_verify_with_missing_crl(self) -> None: |
| 2530 |
""" |
| 2531 |
`verify_certificate` raises error when an intermediate certificate's |
| 2532 |
CRL is missing. |
| 2533 |
""" |
| 2534 |
store = X509Store() |
| 2535 |
store.add_cert(self.root_cert) |
| 2536 |
store.add_cert(self.intermediate_cert) |
| 2537 |
root_crl = self._make_test_crl_cryptography( |
| 2538 |
self.root_cert, self.root_key, certs=[self.intermediate_cert] |
| 2539 |
) |
| 2540 |
store.add_crl(root_crl) |
| 2541 |
store.set_flags( |
| 2542 |
X509StoreFlags.CRL_CHECK | X509StoreFlags.CRL_CHECK_ALL |
| 2543 |
) |
| 2544 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2545 |
with pytest.raises(X509StoreContextError) as err: |
| 2546 |
store_ctx.verify_certificate() |
| 2547 |
assert str(err.value) == "unable to get certificate CRL" |
| 2548 |
assert err.value.certificate.get_subject().CN == "intermediate-service" |
| 2549 |
|
| 2550 |
|
| 2551 |
class TestX509StoreContext: |
| 2552 |
""" |
| 2553 |
Tests for `OpenSSL.crypto.X509StoreContext`. |
| 2554 |
""" |
| 2555 |
|
| 2556 |
root_cert = load_certificate(FILETYPE_PEM, root_cert_pem) |
| 2557 |
intermediate_cert = load_certificate(FILETYPE_PEM, intermediate_cert_pem) |
| 2558 |
intermediate_server_cert = load_certificate( |
| 2559 |
FILETYPE_PEM, intermediate_server_cert_pem |
| 2560 |
) |
| 2561 |
|
| 2562 |
def test_valid(self) -> None: |
| 2563 |
""" |
| 2564 |
`verify_certificate` returns ``None`` when called with a certificate |
| 2565 |
and valid chain. |
| 2566 |
""" |
| 2567 |
store = X509Store() |
| 2568 |
store.add_cert(self.root_cert) |
| 2569 |
store.add_cert(self.intermediate_cert) |
| 2570 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2571 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2572 |
|
| 2573 |
def test_reuse(self) -> None: |
| 2574 |
""" |
| 2575 |
`verify_certificate` can be called multiple times with the same |
| 2576 |
``X509StoreContext`` instance to produce the same result. |
| 2577 |
""" |
| 2578 |
store = X509Store() |
| 2579 |
store.add_cert(self.root_cert) |
| 2580 |
store.add_cert(self.intermediate_cert) |
| 2581 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2582 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2583 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2584 |
|
| 2585 |
@pytest.mark.parametrize( |
| 2586 |
"root_cert, chain, verified_cert", |
| 2587 |
[ |
| 2588 |
pytest.param( |
| 2589 |
root_cert, |
| 2590 |
[intermediate_cert], |
| 2591 |
intermediate_server_cert, |
| 2592 |
id="intermediate in chain", |
| 2593 |
), |
| 2594 |
pytest.param( |
| 2595 |
root_cert, |
| 2596 |
[], |
| 2597 |
intermediate_cert, |
| 2598 |
id="empty chain", |
| 2599 |
), |
| 2600 |
pytest.param( |
| 2601 |
root_cert, |
| 2602 |
[root_cert, intermediate_server_cert, intermediate_cert], |
| 2603 |
intermediate_server_cert, |
| 2604 |
id="extra certs in chain", |
| 2605 |
), |
| 2606 |
], |
| 2607 |
) |
| 2608 |
def test_verify_success_with_chain( |
| 2609 |
self, root_cert: X509, chain: list[X509], verified_cert: X509 |
| 2610 |
) -> None: |
| 2611 |
store = X509Store() |
| 2612 |
store.add_cert(root_cert) |
| 2613 |
store_ctx = X509StoreContext(store, verified_cert, chain=chain) |
| 2614 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2615 |
|
| 2616 |
def test_valid_untrusted_chain_reuse(self) -> None: |
| 2617 |
""" |
| 2618 |
`verify_certificate` using an untrusted chain can be called multiple |
| 2619 |
times with the same ``X509StoreContext`` instance to produce the same |
| 2620 |
result. |
| 2621 |
""" |
| 2622 |
store = X509Store() |
| 2623 |
store.add_cert(self.root_cert) |
| 2624 |
chain = [self.intermediate_cert] |
| 2625 |
|
| 2626 |
store_ctx = X509StoreContext( |
| 2627 |
store, self.intermediate_server_cert, chain=chain |
| 2628 |
) |
| 2629 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2630 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2631 |
|
| 2632 |
def test_chain_reference(self) -> None: |
| 2633 |
""" |
| 2634 |
``X509StoreContext`` properly keeps references to the untrusted chain |
| 2635 |
certificates. |
| 2636 |
""" |
| 2637 |
store = X509Store() |
| 2638 |
store.add_cert(self.root_cert) |
| 2639 |
chain = [load_certificate(FILETYPE_PEM, intermediate_cert_pem)] |
| 2640 |
|
| 2641 |
store_ctx = X509StoreContext( |
| 2642 |
store, self.intermediate_server_cert, chain=chain |
| 2643 |
) |
| 2644 |
|
| 2645 |
del chain |
| 2646 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2647 |
|
| 2648 |
@pytest.mark.parametrize( |
| 2649 |
"root_cert, chain, verified_cert", |
| 2650 |
[ |
| 2651 |
pytest.param( |
| 2652 |
root_cert, |
| 2653 |
[], |
| 2654 |
intermediate_server_cert, |
| 2655 |
id="intermediate missing", |
| 2656 |
), |
| 2657 |
pytest.param( |
| 2658 |
None, |
| 2659 |
[intermediate_cert], |
| 2660 |
intermediate_server_cert, |
| 2661 |
id="no trusted root", |
| 2662 |
), |
| 2663 |
pytest.param( |
| 2664 |
None, |
| 2665 |
[root_cert, intermediate_cert], |
| 2666 |
intermediate_server_cert, |
| 2667 |
id="untrusted root, full chain is available", |
| 2668 |
), |
| 2669 |
pytest.param( |
| 2670 |
intermediate_cert, |
| 2671 |
[root_cert, intermediate_cert], |
| 2672 |
intermediate_server_cert, |
| 2673 |
id="untrusted root, intermediate is trusted and in chain", |
| 2674 |
), |
| 2675 |
], |
| 2676 |
) |
| 2677 |
def test_verify_fail_with_chain( |
| 2678 |
self, root_cert: X509, chain: list[X509], verified_cert: X509 |
| 2679 |
) -> None: |
| 2680 |
store = X509Store() |
| 2681 |
if root_cert: |
| 2682 |
store.add_cert(root_cert) |
| 2683 |
|
| 2684 |
store_ctx = X509StoreContext(store, verified_cert, chain=chain) |
| 2685 |
|
| 2686 |
with pytest.raises(X509StoreContextError): |
| 2687 |
store_ctx.verify_certificate() |
| 2688 |
|
| 2689 |
@pytest.mark.parametrize( |
| 2690 |
"chain, expected_error", |
| 2691 |
[ |
| 2692 |
pytest.param( |
| 2693 |
[intermediate_cert, "This is not a certificate"], |
| 2694 |
TypeError, |
| 2695 |
id="non-certificate in chain", |
| 2696 |
), |
| 2697 |
pytest.param( |
| 2698 |
42, |
| 2699 |
TypeError, |
| 2700 |
id="non-list chain", |
| 2701 |
), |
| 2702 |
], |
| 2703 |
) |
| 2704 |
def test_untrusted_chain_wrong_args( |
| 2705 |
self, chain: list[X509], expected_error: type[Exception] |
| 2706 |
) -> None: |
| 2707 |
""" |
| 2708 |
Creating ``X509StoreContext`` with wrong chain raises an exception. |
| 2709 |
""" |
| 2710 |
store = X509Store() |
| 2711 |
store.add_cert(self.root_cert) |
| 2712 |
|
| 2713 |
with pytest.raises(expected_error): |
| 2714 |
X509StoreContext(store, self.intermediate_server_cert, chain=chain) |
| 2715 |
|
| 2716 |
def test_failure_building_untrusted_chain_raises( |
| 2717 |
self, monkeypatch: pytest.MonkeyPatch |
| 2718 |
) -> None: |
| 2719 |
""" |
| 2720 |
Creating ``X509StoreContext`` raises ``OpenSSL.crypto.Error`` when |
| 2721 |
the underlying lib fails to add the certificate to the stack. |
| 2722 |
""" |
| 2723 |
monkeypatch.setattr(_lib, "sk_X509_push", lambda _stack, _x509: -1) |
| 2724 |
|
| 2725 |
store = X509Store() |
| 2726 |
store.add_cert(self.root_cert) |
| 2727 |
chain = [self.intermediate_cert] |
| 2728 |
|
| 2729 |
with pytest.raises(Error): |
| 2730 |
X509StoreContext(store, self.intermediate_server_cert, chain=chain) |
| 2731 |
|
| 2732 |
def test_trusted_self_signed(self) -> None: |
| 2733 |
""" |
| 2734 |
`verify_certificate` returns ``None`` when called with a self-signed |
| 2735 |
certificate and itself in the chain. |
| 2736 |
""" |
| 2737 |
store = X509Store() |
| 2738 |
store.add_cert(self.root_cert) |
| 2739 |
store_ctx = X509StoreContext(store, self.root_cert) |
| 2740 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2741 |
|
| 2742 |
def test_untrusted_self_signed(self) -> None: |
| 2743 |
""" |
| 2744 |
`verify_certificate` raises error when a self-signed certificate is |
| 2745 |
verified without itself in the chain. |
| 2746 |
""" |
| 2747 |
store = X509Store() |
| 2748 |
store_ctx = X509StoreContext(store, self.root_cert) |
| 2749 |
with pytest.raises(X509StoreContextError) as exc: |
| 2750 |
store_ctx.verify_certificate() |
| 2751 |
|
| 2752 |
# OpenSSL 1.1.x and 3.0.x have different error messages |
| 2753 |
assert str(exc.value) in [ |
| 2754 |
"self signed certificate", |
| 2755 |
"self-signed certificate", |
| 2756 |
] |
| 2757 |
assert exc.value.certificate.get_subject().CN == "Testing Root CA" |
| 2758 |
|
| 2759 |
def test_invalid_chain_no_root(self) -> None: |
| 2760 |
""" |
| 2761 |
`verify_certificate` raises error when a root certificate is missing |
| 2762 |
from the chain. |
| 2763 |
""" |
| 2764 |
store = X509Store() |
| 2765 |
store.add_cert(self.intermediate_cert) |
| 2766 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2767 |
|
| 2768 |
with pytest.raises(X509StoreContextError) as exc: |
| 2769 |
store_ctx.verify_certificate() |
| 2770 |
|
| 2771 |
assert str(exc.value) == "unable to get issuer certificate" |
| 2772 |
assert exc.value.certificate.get_subject().CN == "intermediate" |
| 2773 |
|
| 2774 |
def test_invalid_chain_no_intermediate(self) -> None: |
| 2775 |
""" |
| 2776 |
`verify_certificate` raises error when an intermediate certificate is |
| 2777 |
missing from the chain. |
| 2778 |
""" |
| 2779 |
store = X509Store() |
| 2780 |
store.add_cert(self.root_cert) |
| 2781 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2782 |
|
| 2783 |
with pytest.raises(X509StoreContextError) as exc: |
| 2784 |
store_ctx.verify_certificate() |
| 2785 |
|
| 2786 |
assert str(exc.value) == "unable to get local issuer certificate" |
| 2787 |
assert exc.value.certificate.get_subject().CN == "intermediate-service" |
| 2788 |
|
| 2789 |
def test_modification_pre_verify(self) -> None: |
| 2790 |
""" |
| 2791 |
`verify_certificate` can use a store context modified after |
| 2792 |
instantiation. |
| 2793 |
""" |
| 2794 |
store_bad = X509Store() |
| 2795 |
store_bad.add_cert(self.intermediate_cert) |
| 2796 |
store_good = X509Store() |
| 2797 |
store_good.add_cert(self.root_cert) |
| 2798 |
store_good.add_cert(self.intermediate_cert) |
| 2799 |
store_ctx = X509StoreContext(store_bad, self.intermediate_server_cert) |
| 2800 |
|
| 2801 |
with pytest.raises(X509StoreContextError) as exc: |
| 2802 |
store_ctx.verify_certificate() |
| 2803 |
|
| 2804 |
assert str(exc.value) == "unable to get issuer certificate" |
| 2805 |
assert exc.value.certificate.get_subject().CN == "intermediate" |
| 2806 |
|
| 2807 |
store_ctx.set_store(store_good) |
| 2808 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2809 |
|
| 2810 |
def test_verify_with_time(self) -> None: |
| 2811 |
""" |
| 2812 |
`verify_certificate` raises error when the verification time is |
| 2813 |
set at notAfter. |
| 2814 |
""" |
| 2815 |
store = X509Store() |
| 2816 |
store.add_cert(self.root_cert) |
| 2817 |
store.add_cert(self.intermediate_cert) |
| 2818 |
|
| 2819 |
expire_time = self.intermediate_server_cert.get_notAfter() |
| 2820 |
assert expire_time is not None |
| 2821 |
expire_datetime = datetime.strptime( |
| 2822 |
expire_time.decode("utf-8"), "%Y%m%d%H%M%SZ" |
| 2823 |
) |
| 2824 |
try: |
| 2825 |
store.set_time(expire_datetime) |
| 2826 |
except OverflowError: |
| 2827 |
pytest.skip("Doesn't work with 32-bit time_t") |
| 2828 |
|
| 2829 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2830 |
with pytest.raises(X509StoreContextError) as exc: |
| 2831 |
store_ctx.verify_certificate() |
| 2832 |
|
| 2833 |
assert str(exc.value) == "certificate has expired" |
| 2834 |
|
| 2835 |
def test_get_verified_chain(self) -> None: |
| 2836 |
""" |
| 2837 |
`get_verified_chain` returns the verified chain. |
| 2838 |
""" |
| 2839 |
store = X509Store() |
| 2840 |
store.add_cert(self.root_cert) |
| 2841 |
store.add_cert(self.intermediate_cert) |
| 2842 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2843 |
chain = store_ctx.get_verified_chain() |
| 2844 |
assert len(chain) == 3 |
| 2845 |
intermediate_subject = self.intermediate_server_cert.get_subject() |
| 2846 |
assert chain[0].get_subject() == intermediate_subject |
| 2847 |
assert chain[1].get_subject() == self.intermediate_cert.get_subject() |
| 2848 |
assert chain[2].get_subject() == self.root_cert.get_subject() |
| 2849 |
# Test reuse |
| 2850 |
chain = store_ctx.get_verified_chain() |
| 2851 |
assert len(chain) == 3 |
| 2852 |
assert chain[0].get_subject() == intermediate_subject |
| 2853 |
assert chain[1].get_subject() == self.intermediate_cert.get_subject() |
| 2854 |
assert chain[2].get_subject() == self.root_cert.get_subject() |
| 2855 |
|
| 2856 |
def test_get_verified_chain_invalid_chain_no_root(self) -> None: |
| 2857 |
""" |
| 2858 |
`get_verified_chain` raises error when cert verification fails. |
| 2859 |
""" |
| 2860 |
store = X509Store() |
| 2861 |
store.add_cert(self.intermediate_cert) |
| 2862 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2863 |
|
| 2864 |
with pytest.raises(X509StoreContextError) as exc: |
| 2865 |
store_ctx.get_verified_chain() |
| 2866 |
|
| 2867 |
assert str(exc.value) == "unable to get issuer certificate" |
| 2868 |
assert exc.value.certificate.get_subject().CN == "intermediate" |
| 2869 |
|
| 2870 |
@pytest.fixture |
| 2871 |
def root_ca_file(self, tmp_path: pathlib.Path) -> pathlib.Path: |
| 2872 |
return self._create_ca_file( |
| 2873 |
tmp_path, "root_ca_hash_dir", self.root_cert |
| 2874 |
) |
| 2875 |
|
| 2876 |
@pytest.fixture |
| 2877 |
def intermediate_ca_file(self, tmp_path: pathlib.Path) -> pathlib.Path: |
| 2878 |
return self._create_ca_file( |
| 2879 |
tmp_path, "intermediate_ca_hash_dir", self.intermediate_cert |
| 2880 |
) |
| 2881 |
|
| 2882 |
@staticmethod |
| 2883 |
def _create_ca_file( |
| 2884 |
base_path: pathlib.Path, hash_directory: str, cacert: X509 |
| 2885 |
) -> pathlib.Path: |
| 2886 |
ca_hash = f"{cacert.subject_name_hash():08x}.0" |
| 2887 |
cafile = base_path / hash_directory / ca_hash |
| 2888 |
cafile.parent.mkdir(parents=True, exist_ok=True) |
| 2889 |
cafile.write_bytes(dump_certificate(FILETYPE_PEM, cacert)) |
| 2890 |
return cafile |
| 2891 |
|
| 2892 |
def test_verify_with_ca_file_location( |
| 2893 |
self, root_ca_file: pathlib.Path |
| 2894 |
) -> None: |
| 2895 |
store = X509Store() |
| 2896 |
store.load_locations(str(root_ca_file)) |
| 2897 |
|
| 2898 |
store_ctx = X509StoreContext(store, self.intermediate_cert) |
| 2899 |
store_ctx.verify_certificate() |
| 2900 |
|
| 2901 |
def test_verify_with_ca_path_location( |
| 2902 |
self, root_ca_file: pathlib.Path |
| 2903 |
) -> None: |
| 2904 |
store = X509Store() |
| 2905 |
store.load_locations(None, str(root_ca_file.parent)) |
| 2906 |
|
| 2907 |
store_ctx = X509StoreContext(store, self.intermediate_cert) |
| 2908 |
store_ctx.verify_certificate() |
| 2909 |
|
| 2910 |
def test_verify_with_cafile_and_capath( |
| 2911 |
self, |
| 2912 |
root_ca_file: pathlib.Path, |
| 2913 |
intermediate_ca_file: pathlib.Path, |
| 2914 |
) -> None: |
| 2915 |
store = X509Store() |
| 2916 |
store.load_locations( |
| 2917 |
cafile=str(root_ca_file), capath=str(intermediate_ca_file.parent) |
| 2918 |
) |
| 2919 |
|
| 2920 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2921 |
store_ctx.verify_certificate() |
| 2922 |
|
| 2923 |
def test_verify_with_multiple_ca_files( |
| 2924 |
self, root_ca_file: pathlib.Path, intermediate_ca_file: pathlib.Path |
| 2925 |
) -> None: |
| 2926 |
store = X509Store() |
| 2927 |
store.load_locations(str(root_ca_file)) |
| 2928 |
store.load_locations(str(intermediate_ca_file)) |
| 2929 |
|
| 2930 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2931 |
store_ctx.verify_certificate() |
| 2932 |
|
| 2933 |
def test_verify_failure_with_empty_ca_directory( |
| 2934 |
self, tmp_path: pathlib.Path |
| 2935 |
) -> None: |
| 2936 |
store = X509Store() |
| 2937 |
store.load_locations(None, str(tmp_path)) |
| 2938 |
|
| 2939 |
store_ctx = X509StoreContext(store, self.intermediate_cert) |
| 2940 |
with pytest.raises(X509StoreContextError) as exc: |
| 2941 |
store_ctx.verify_certificate() |
| 2942 |
|
| 2943 |
assert str(exc.value) == "unable to get local issuer certificate" |
| 2944 |
|
| 2945 |
def test_verify_with_partial_chain(self) -> None: |
| 2946 |
store = X509Store() |
| 2947 |
store.add_cert(self.intermediate_cert) |
| 2948 |
|
| 2949 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2950 |
with pytest.raises(X509StoreContextError): |
| 2951 |
store_ctx.verify_certificate() |
| 2952 |
|
| 2953 |
# Now set the partial verification flag for verification. |
| 2954 |
store.set_flags(X509StoreFlags.PARTIAL_CHAIN) |
| 2955 |
store_ctx = X509StoreContext(store, self.intermediate_server_cert) |
| 2956 |
assert store_ctx.verify_certificate() is None # type: ignore[func-returns-value] |
| 2957 |
|
| 2958 |
|
| 2959 |
class TestEllipticCurve: |
| 2960 |
""" |
| 2961 |
Tests for `_EllipticCurve`, `get_elliptic_curve`, and |
| 2962 |
`get_elliptic_curves`. |
| 2963 |
""" |
| 2964 |
|
| 2965 |
def test_set(self) -> None: |
| 2966 |
""" |
| 2967 |
`get_elliptic_curves` returns a `set`. |
| 2968 |
""" |
| 2969 |
assert isinstance(get_elliptic_curves(), set) |
| 2970 |
|
| 2971 |
def test_a_curve(self) -> None: |
| 2972 |
""" |
| 2973 |
`get_elliptic_curve` can be used to retrieve a particular supported |
| 2974 |
curve. |
| 2975 |
""" |
| 2976 |
curves = get_elliptic_curves() |
| 2977 |
curve = next(iter(curves)) |
| 2978 |
assert curve.name == get_elliptic_curve(curve.name).name |
| 2979 |
|
| 2980 |
def test_not_a_curve(self) -> None: |
| 2981 |
""" |
| 2982 |
`get_elliptic_curve` raises `ValueError` if called with a name which |
| 2983 |
does not identify a supported curve. |
| 2984 |
""" |
| 2985 |
with pytest.raises(ValueError): |
| 2986 |
get_elliptic_curve("this curve was just invented") |
| 2987 |
|
| 2988 |
def test_repr(self) -> None: |
| 2989 |
""" |
| 2990 |
The string representation of a curve object includes simply states the |
| 2991 |
object is a curve and what its name is. |
| 2992 |
""" |
| 2993 |
curves = get_elliptic_curves() |
| 2994 |
curve = next(iter(curves)) |
| 2995 |
assert f"<Curve {curve.name!r}>" == repr(curve) |
| 2996 |
|
| 2997 |
def test_to_EC_KEY(self) -> None: |
| 2998 |
""" |
| 2999 |
The curve object can export a version of itself as an EC_KEY* via the |
| 3000 |
private `_EllipticCurve._to_EC_KEY`. |
| 3001 |
""" |
| 3002 |
curves = get_elliptic_curves() |
| 3003 |
curve = next(iter(curves)) |
| 3004 |
# It's not easy to assert anything about this object. However, see |
| 3005 |
# leakcheck/crypto.py for a test that demonstrates it at least does |
| 3006 |
# not leak memory. |
| 3007 |
curve._to_EC_KEY() |
| 3008 |
|
| 3009 |
|
| 3010 |
class TestEllipticCurveEquality: |
| 3011 |
""" |
| 3012 |
Tests `_EllipticCurve`'s implementation of ``==`` and ``!=``. |
| 3013 |
""" |
| 3014 |
|
| 3015 |
def anInstance(self) -> _EllipticCurve: |
| 3016 |
""" |
| 3017 |
Get the curve object for an arbitrary curve supported by the system. |
| 3018 |
""" |
| 3019 |
return next(iter(get_elliptic_curves())) |
| 3020 |
|
| 3021 |
def anotherInstance(self) -> _EllipticCurve: |
| 3022 |
""" |
| 3023 |
Get the curve object for an arbitrary curve supported by the system - |
| 3024 |
but not the one returned by C{anInstance}. |
| 3025 |
""" |
| 3026 |
return list(get_elliptic_curves())[1] |
| 3027 |
|
| 3028 |
def test_identicalEq(self) -> None: |
| 3029 |
""" |
| 3030 |
An object compares equal to itself using the C{==} operator. |
| 3031 |
""" |
| 3032 |
o = self.anInstance() |
| 3033 |
assert o == o |
| 3034 |
|
| 3035 |
def test_identicalNe(self) -> None: |
| 3036 |
""" |
| 3037 |
An object doesn't compare not equal to itself using the C{!=} operator. |
| 3038 |
""" |
| 3039 |
o = self.anInstance() |
| 3040 |
assert not (o != o) |
| 3041 |
|
| 3042 |
def test_sameEq(self) -> None: |
| 3043 |
""" |
| 3044 |
Two objects that are equal to each other compare equal to each other |
| 3045 |
using the C{==} operator. |
| 3046 |
""" |
| 3047 |
a = self.anInstance() |
| 3048 |
b = self.anInstance() |
| 3049 |
assert a == b |
| 3050 |
|
| 3051 |
def test_sameNe(self) -> None: |
| 3052 |
""" |
| 3053 |
Two objects that are equal to each other do not compare not equal to |
| 3054 |
each other using the C{!=} operator. |
| 3055 |
""" |
| 3056 |
a = self.anInstance() |
| 3057 |
b = self.anInstance() |
| 3058 |
assert not (a != b) |
| 3059 |
|
| 3060 |
def test_differentEq(self) -> None: |
| 3061 |
""" |
| 3062 |
Two objects that are not equal to each other do not compare equal to |
| 3063 |
each other using the C{==} operator. |
| 3064 |
""" |
| 3065 |
a = self.anInstance() |
| 3066 |
b = self.anotherInstance() |
| 3067 |
assert not (a == b) |
| 3068 |
|
| 3069 |
def test_differentNe(self) -> None: |
| 3070 |
""" |
| 3071 |
Two objects that are not equal to each other compare not equal to each |
| 3072 |
other using the C{!=} operator. |
| 3073 |
""" |
| 3074 |
a = self.anInstance() |
| 3075 |
b = self.anotherInstance() |
| 3076 |
assert a != b |
| 3077 |
|
| 3078 |
def test_anotherTypeEq(self) -> None: |
| 3079 |
""" |
| 3080 |
The object does not compare equal to an object of an unrelated type |
| 3081 |
(which does not implement the comparison) using the C{==} operator. |
| 3082 |
""" |
| 3083 |
a = self.anInstance() |
| 3084 |
b = object() |
| 3085 |
assert not (a == b) |
| 3086 |
|
| 3087 |
def test_anotherTypeNe(self) -> None: |
| 3088 |
""" |
| 3089 |
The object compares not equal to an object of an unrelated type (which |
| 3090 |
does not implement the comparison) using the C{!=} operator. |
| 3091 |
""" |
| 3092 |
a = self.anInstance() |
| 3093 |
b = object() |
| 3094 |
assert a != b |
| 3095 |
|
| 3096 |
def test_delegatedEq(self) -> None: |
| 3097 |
""" |
| 3098 |
The result of comparison using C{==} is delegated to the right-hand |
| 3099 |
operand if it is of an unrelated type. |
| 3100 |
""" |
| 3101 |
called = False |
| 3102 |
|
| 3103 |
class Delegate: |
| 3104 |
def __eq__(self, other: object) -> bool: |
| 3105 |
nonlocal called |
| 3106 |
called = True |
| 3107 |
return False |
| 3108 |
|
| 3109 |
a = self.anInstance() |
| 3110 |
b = Delegate() |
| 3111 |
assert not (a == b) |
| 3112 |
assert called |
| 3113 |
|
| 3114 |
def test_delegateNe(self) -> None: |
| 3115 |
""" |
| 3116 |
The result of comparison using C{!=} is delegated to the right-hand |
| 3117 |
operand if it is of an unrelated type. |
| 3118 |
""" |
| 3119 |
called = False |
| 3120 |
|
| 3121 |
class Delegate: |
| 3122 |
def __ne__(self, other: object) -> bool: |
| 3123 |
nonlocal called |
| 3124 |
called = True |
| 3125 |
return False |
| 3126 |
|
| 3127 |
a = self.anInstance() |
| 3128 |
b = Delegate() |
| 3129 |
assert not (a != b) # type: ignore[comparison-overlap] |
| 3130 |
assert called |
| 3131 |
|
| 3132 |
|
| 3133 |
class TestEllipticCurveHash: |
| 3134 |
""" |
| 3135 |
Tests for `_EllipticCurve`'s implementation of hashing (thus use as |
| 3136 |
an item in a `dict` or `set`). |
| 3137 |
""" |
| 3138 |
|
| 3139 |
def test_contains(self) -> None: |
| 3140 |
""" |
| 3141 |
The ``in`` operator reports that a `set` containing a curve does |
| 3142 |
contain that curve. |
| 3143 |
""" |
| 3144 |
curve = next(iter(get_elliptic_curves())) |
| 3145 |
curves = set([curve]) |
| 3146 |
assert curve in curves |
| 3147 |
|
| 3148 |
def test_does_not_contain(self) -> None: |
| 3149 |
""" |
| 3150 |
The ``in`` operator reports that a `set` not containing a curve |
| 3151 |
does not contain that curve. |
| 3152 |
""" |
| 3153 |
all_curves = list(get_elliptic_curves()) |
| 3154 |
|
| 3155 |
curve = all_curves[0] |
| 3156 |
curves = set([all_curves[1]]) |
| 3157 |
assert curve not in curves |