Skip to content

Commit fe5f3a9

Browse files
alexreaperhulk
andauthored
Two more testscases for key loading (#12370)
* Two more testscases for key loading * Update tests/hazmat/primitives/test_serialization.py Co-authored-by: Paul Kehrer <paul.l.kehrer@gmail.com> --------- Co-authored-by: Paul Kehrer <paul.l.kehrer@gmail.com>
1 parent 5baed58 commit fe5f3a9

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

docs/development/test-vectors.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ Custom asymmetric vectors
227227
comma).
228228
* ``asymmetric/Traditional_OpenSSL_Serialization/key1-malformed-iv.pem`` - An
229229
RSA key in an encrypted PEM with a malformed IV (not valid hex).
230+
* ``asymmetric/Traditional_OpenSSL_Serialization/key1-short-iv.pem`` - An
231+
RSA key in an encrypted PEM with an IV that's too short (less than 8 bytes).
230232

231233
Key exchange
232234
~~~~~~~~~~~~

tests/hazmat/primitives/test_serialization.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,15 @@ def test_load_bad_encryption_oid_key(self, key_file, password, backend):
11271127
),
11281128
)
11291129

1130+
def test_encrypted_pkcs8_non_utf_password(self):
1131+
data = load_vectors_from_file(
1132+
os.path.join("asymmetric", "PKCS8", "enc-rsa-pkcs8.pem"),
1133+
lambda f: f.read(),
1134+
mode="rb",
1135+
)
1136+
with pytest.raises(ValueError):
1137+
load_pem_private_key(data, password=b"\xff")
1138+
11301139
@pytest.mark.xfail()
11311140
def test_rsa_private_key_invalid_version(self):
11321141
data = load_vectors_from_file(
@@ -1194,6 +1203,19 @@ def test_pem_encryption_malformed_iv(self):
11941203
with pytest.raises(ValueError):
11951204
load_pem_private_key(data, password=b"password")
11961205

1206+
def test_pem_encryption_short_iv(self):
1207+
data = load_vectors_from_file(
1208+
os.path.join(
1209+
"asymmetric",
1210+
"Traditional_OpenSSL_Serialization",
1211+
"key1-short-iv.pem",
1212+
),
1213+
lambda f: f.read(),
1214+
mode="rb",
1215+
)
1216+
with pytest.raises(ValueError):
1217+
load_pem_private_key(data, password=b"password")
1218+
11971219

11981220
class TestKeySerializationEncryptionTypes:
11991221
def test_non_bytes_password(self):
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
Proc-Type: 4,ENCRYPTED
3+
DEK-Info: DES-EDE3-CBC,aaaa
4+
5+
18phyq8pG3Tgov4rWiT0moaDbzIOk7v4/4Jnw3sc6IuMFmAYnIKHRs75hQdlFAxG
6+
uSXcAKzCzjhkzgSNyNaJ8ZgeDM+DskDTA109iQWCeSxKZkuHBm2Xux9p7ynEhrMf
7+
+z0Dd5W36KRPs0PRwVoUAv/AYaLizBbAXaEx/e21uDB2cVnA2EhjEXEz7KZnqTWm
8+
qbSEAv/IJos1Eh1IvLupxh5naaRxfrHZgKu638ybxuxzJx+zn2DeB7g9uqVf3lCp
9+
B5bsoqumIhxBmIS7pKeWIq+GFVQuuHcDozRVolFuUvMkPdPfaGQjLI+ynaAfA9WH
10+
MULcRcBL+S8cp4xv8jmyW0n4Elak0ixw1UJLjeSrIGYLB+ZkYXPiUjhYZPzbKzdE
11+
rLstyGfFXH8Vjw6921P6iVH/JvskF9aj4NvYyZqxo9YznIN9nI8GWmqJgLyIYHET
12+
Ur5mp1/O+KGLWMzfX09/fUVF/mXBibcnJ/sixGCH4yNZR5kpnas6H8SmaGgKE1zk
13+
KYeuicGHm6nZ/uyjoL/AwvbUL1y9tHJ0vn816cCRdJ4ELZ5dotGPREPmkWzjv08A
14+
ZeTmdsgsGuUY/5mKZdIqlWCgrSKaZvS81+5tYgf0qMLBsAbLPDJy9kzTwCsEYxmh
15+
x9QxUeQ/UWVsMn6JqeBVp0B5z/sLcdx6GkFVGs9U2Al3aykVhrVq+0RUiYafluod
16+
Mkz1AczAxFtqdgaQIJbrwEAXoMc8/l8dunbuYoRuuf1y259U61aTm6wcknnDU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