@@ -958,19 +958,33 @@ def test_pkcs7_verify_der_no_data(
958
958
with pytest .raises (ValueError ):
959
959
pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
960
960
961
- def test_pkcs7_verify_der_not_signed (self , backend , data ):
962
- # Encryption of data with a text/html content type header
963
- certificate , _ = _load_rsa_cert_key ()
961
+ def test_pkcs7_verify_invalid_signature (
962
+ self , backend , data , certificate , private_key
963
+ ):
964
+ # Signature
964
965
builder = (
965
- pkcs7 .PKCS7EnvelopeBuilder ()
966
- .set_data (b"Hello world!" )
967
- .add_recipient (certificate )
966
+ pkcs7 .PKCS7SignatureBuilder ()
967
+ .set_data (data )
968
+ .add_signer (certificate , private_key , hashes .SHA256 ())
969
+ )
970
+ options = [pkcs7 .PKCS7Options .NoAttributes ]
971
+ signature = builder .sign (serialization .Encoding .DER , options )
972
+
973
+ # Verification
974
+ with pytest .raises (exceptions .InvalidSignature ):
975
+ pkcs7 .pkcs7_verify_der (signature , b"Different" , certificate , [])
976
+
977
+ def test_pkcs7_verify_der_not_signed (self , backend , data , certificate ):
978
+ # Getting some enveloped data
979
+ enveloped = load_vectors_from_file (
980
+ os .path .join ("pkcs7" , "enveloped.pem" ),
981
+ loader = lambda pemfile : pemfile .read (),
982
+ mode = "rb" ,
968
983
)
969
- enveloped = builder .encrypt (serialization .Encoding .DER , [])
970
984
971
985
# Verification
972
986
with pytest .raises (ValueError ):
973
- pkcs7 .pkcs7_verify_der (enveloped , None , certificate , [])
987
+ pkcs7 .pkcs7_verify_pem (enveloped , None , certificate , [])
974
988
975
989
def test_pkcs7_verify_der_wrong_certificate (
976
990
self , backend , data , certificate , private_key
0 commit comments