Skip to content

Commit a5b9814

Browse files
committed
updated tests to avoid unsupported algorithm
1 parent dcc4a64 commit a5b9814

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
@@ -943,19 +943,33 @@ def test_pkcs7_verify_der_no_data(
943943
with pytest.raises(ValueError):
944944
pkcs7.pkcs7_verify_der(signature, None, certificate, [])
945945

946-
def test_pkcs7_verify_der_not_signed(self, backend, data):
947-
# Encryption of data with a text/html content type header
948-
certificate, _ = _load_rsa_cert_key()
946+
def test_pkcs7_verify_invalid_signature(
947+
self, backend, data, certificate, private_key
948+
):
949+
# Signature
949950
builder = (
950-
pkcs7.PKCS7EnvelopeBuilder()
951-
.set_data(b"Hello world!")
952-
.add_recipient(certificate)
951+
pkcs7.PKCS7SignatureBuilder()
952+
.set_data(data)
953+
.add_signer(certificate, private_key, hashes.SHA256())
954+
)
955+
options = [pkcs7.PKCS7Options.NoAttributes]
956+
signature = builder.sign(serialization.Encoding.DER, options)
957+
958+
# Verification
959+
with pytest.raises(exceptions.InvalidSignature):
960+
pkcs7.pkcs7_verify_der(signature, b"Different", certificate, [])
961+
962+
def test_pkcs7_verify_der_not_signed(self, backend, data, certificate):
963+
# Getting some enveloped data
964+
enveloped = load_vectors_from_file(
965+
os.path.join("pkcs7", "enveloped.pem"),
966+
loader=lambda pemfile: pemfile.read(),
967+
mode="rb",
953968
)
954-
enveloped = builder.encrypt(serialization.Encoding.DER, [])
955969

956970
# Verification
957971
with pytest.raises(ValueError):
958-
pkcs7.pkcs7_verify_der(enveloped, None, certificate, [])
972+
pkcs7.pkcs7_verify_pem(enveloped, None, certificate, [])
959973

960974
def test_pkcs7_verify_der_wrong_certificate(
961975
self, backend, data, certificate, private_key

0 commit comments

Comments
 (0)