@@ -943,19 +943,33 @@ def test_pkcs7_verify_der_no_data(
943
943
with pytest .raises (ValueError ):
944
944
pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
945
945
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
949
950
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" ,
953
968
)
954
- enveloped = builder .encrypt (serialization .Encoding .DER , [])
955
969
956
970
# Verification
957
971
with pytest .raises (ValueError ):
958
- pkcs7 .pkcs7_verify_der (enveloped , None , certificate , [])
972
+ pkcs7 .pkcs7_verify_pem (enveloped , None , certificate , [])
959
973
960
974
def test_pkcs7_verify_der_wrong_certificate (
961
975
self , backend , data , certificate , private_key
0 commit comments