@@ -1063,6 +1063,25 @@ def test_pkcs7_verify_der(
1063
1063
# Verification
1064
1064
pkcs7 .pkcs7_verify_der (signature , data , certificate , [])
1065
1065
1066
+ def test_pkcs7_verify_der_no_content (
1067
+ self , backend , data , certificate , private_key
1068
+ ):
1069
+ """
1070
+ Tests verification when needing the content stored in the PKCS7 signed
1071
+ data structure.
1072
+ """
1073
+ # Signature
1074
+ builder = (
1075
+ pkcs7 .PKCS7SignatureBuilder ()
1076
+ .set_data (data )
1077
+ .add_signer (certificate , private_key , hashes .SHA256 ())
1078
+ )
1079
+ options = [pkcs7 .PKCS7Options .NoAttributes ]
1080
+ signature = builder .sign (serialization .Encoding .DER , options )
1081
+
1082
+ # Verification
1083
+ pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
1084
+
1066
1085
def test_pkcs7_verify_der_no_data (
1067
1086
self , backend , data , certificate , private_key
1068
1087
):
@@ -1082,6 +1101,20 @@ def test_pkcs7_verify_der_no_data(
1082
1101
with pytest .raises (ValueError ):
1083
1102
pkcs7 .pkcs7_verify_der (signature , None , certificate , [])
1084
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 ()
1107
+ builder = (
1108
+ pkcs7 .PKCS7EnvelopeBuilder ()
1109
+ .set_data (b"Hello world!" )
1110
+ .add_recipient (certificate )
1111
+ )
1112
+ enveloped = builder .encrypt (serialization .Encoding .DER , [])
1113
+
1114
+ # Verification
1115
+ with pytest .raises (ValueError ):
1116
+ pkcs7 .pkcs7_verify_der (enveloped , None , certificate , [])
1117
+
1085
1118
def test_pkcs7_verify_der_wrong_certificate (
1086
1119
self , backend , data , certificate , private_key
1087
1120
):
0 commit comments