@@ -1101,19 +1101,33 @@ def test_pkcs7_verify_der_no_data(
1101
1101
with pytest .raises (ValueError ):
1102
1102
pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
1103
1103
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
1107
1108
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" ,
1111
1126
)
1112
- enveloped = builder .encrypt (serialization .Encoding .DER , [])
1113
1127
1114
1128
# Verification
1115
1129
with pytest .raises (ValueError ):
1116
- pkcs7 .pkcs7_verify_der (enveloped , None , certificate , [])
1130
+ pkcs7 .pkcs7_verify_pem (enveloped , None , certificate , [])
1117
1131
1118
1132
def test_pkcs7_verify_der_wrong_certificate (
1119
1133
self , backend , data , certificate , private_key
0 commit comments