Skip to content

Commit 41c3a33

Browse files
committed
updated tests to avoid unsupported algorithm
1 parent c2ce2cd commit 41c3a33

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

tests/hazmat/primitives/test_pkcs7.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,19 +1101,33 @@ def test_pkcs7_verify_der_no_data(
11011101
with pytest.raises(ValueError):
11021102
pkcs7.pkcs7_verify_der(signature, None, certificate, [])
11031103

1104-
def test_pkcs7_verify_der_not_signed(self, backend, data):
1105-
# Encryption of data with a text/html content type header
1106-
certificate, _ = _load_rsa_cert_key()
1104+
def test_pkcs7_verify_invalid_signature(
1105+
self, backend, data, certificate, private_key
1106+
):
1107+
# Signature
11071108
builder = (
1108-
pkcs7.PKCS7EnvelopeBuilder()
1109-
.set_data(b"Hello world!")
1110-
.add_recipient(certificate)
1109+
pkcs7.PKCS7SignatureBuilder()
1110+
.set_data(data)
1111+
.add_signer(certificate, private_key, hashes.SHA256())
1112+
)
1113+
options = [pkcs7.PKCS7Options.NoAttributes]
1114+
signature = builder.sign(serialization.Encoding.DER, options)
1115+
1116+
# Verification
1117+
with pytest.raises(exceptions.InvalidSignature):
1118+
pkcs7.pkcs7_verify_der(signature, b"Different", certificate, [])
1119+
1120+
def test_pkcs7_verify_der_not_signed(self, backend, data, certificate):
1121+
# Getting some enveloped data
1122+
enveloped = load_vectors_from_file(
1123+
os.path.join("pkcs7", "enveloped.pem"),
1124+
loader=lambda pemfile: pemfile.read(),
1125+
mode="rb",
11111126
)
1112-
enveloped = builder.encrypt(serialization.Encoding.DER, [])
11131127

11141128
# Verification
11151129
with pytest.raises(ValueError):
1116-
pkcs7.pkcs7_verify_der(enveloped, None, certificate, [])
1130+
pkcs7.pkcs7_verify_pem(enveloped, None, certificate, [])
11171131

11181132
def test_pkcs7_verify_der_wrong_certificate(
11191133
self, backend, data, certificate, private_key

0 commit comments

Comments
 (0)