@@ -1176,6 +1176,63 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1176
1176
-----END PRIVATE KEY-----
1177
1177
""".strip()
1178
1178
1179
+ verify_cert = b"""
1180
+ -----BEGIN CERTIFICATE-----
1181
+ MIID9zCCAt+gAwIBAgIQIxMA+XhyS9Ou0qAc0zPyVTANBgkqhkiG9w0BAQsFADAN
1182
+ MQswCQYDVQQDDAJDQTAeFw0yNTAxMDUxMDQ4MjhaFw0yNjAxMDUxMDQ4MjhaMCUx
1183
+ IzAhBgkqhkiG9w0BCQEWFGRlbW8xQHRyaXNvZnQuY29tLnBsMIIBIjANBgkqhkiG
1184
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt0WRzh5y+QmEUjCm+iHXZLrstOSSEhiEcUre
1185
+ 3L8zkuGYVLCKBEvmaHQI7uCu/xdqEht6/wEBCiK+KLdGDVrD4v3A7TnmHzzhvqCs
1186
+ BTL/EmnD3ZMAJVYv4uEBaFpFPSYnPswd353E6KRkFYR4RmFjG9xLTayHXOKqCF6d
1187
+ Hd3uVR7NSs98uhcSYRV7g4NdjmaDj8kz5HeRMfr/uqbcriJ9tu/ljFBWYSwPeiNY
1188
+ nYhaOBLpUhZckyjFDfC+UpwOBPlkK7J047urvzG21xCtVU9DMHtXMkXYe/C+WSm1
1189
+ MRYtgcsOTxpGf+ujceltI2/+IUhWxr5ys7m+xM1jYaM4O1Pw0QIDAQABo4IBOTCC
1190
+ ATUwDAYDVR0TAQH/BAIwADAfBgNVHSMEGDAWgBQduUy7zqv6z3uk4fJeifohSntD
1191
+ 2TAtBgNVHR8EJjAkMCKgIKAehhxodHRwOi8vY2EudHJpc29mdC5jb20ucGwvY3Js
1192
+ MGYGCCsGAQUFBwEBBFowWDArBggrBgEFBQcwAoYfaHR0cDovL2NhLnRyaXNvZnQu
1193
+ Y29tLnBsL2NhY2VydDApBggrBgEFBQcwAYYdaHR0cDovL2NhLnRyaXNvZnQuY29t
1194
+ LnBsL29jc3AwHwYDVR0RBBgwFoEUZGVtbzFAdHJpc29mdC5jb20ucGwwHQYDVR0l
1195
+ BBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMEMB0GA1UdDgQWBBT0/QFDFX/CCMsX356G
1196
+ ImiWwPYxjDAOBgNVHQ8BAf8EBAMCA+gwDQYJKoZIhvcNAQELBQADggEBAL3Iisca
1197
+ IqoFBLMox3cIhCANWO/U1eOvjDjfM/tOHn+6jci/pL/ZHgdRtqCCiaCKtJED/f/9
1198
+ NFUKqcSZ9+vzW0RWLJxHgIvCSjLpoM06XClSlxjVnv62Hb1NC4FfDfnzyG+DZHus
1199
+ nz/MQuXNwHntA6+JyB/HWHUie2ierQYH2mEN1XIJm5luSGwtuGaWfNz/w324ukcV
1200
+ pMd3CbEOZqqfSYGWUHOVG90/OMSfKA/I0hia8Yij0X4Ny+b+bLnHaoozZwJ/UqBl
1201
+ 9ptbfiOOuFXJP7gt547Rp6+2C0XGJM+le0EYlUzbWE6UWgxaIRp5uc8HnUd5e4lX
1202
+ br+Ixxcl3WHckkk=
1203
+ -----END CERTIFICATE-----
1204
+ """.strip()
1205
+
1206
+ verify_key = b"""
1207
+ -----BEGIN RSA PRIVATE KEY-----
1208
+ MIIEowIBAAKCAQEAt0WRzh5y+QmEUjCm+iHXZLrstOSSEhiEcUre3L8zkuGYVLCK
1209
+ BEvmaHQI7uCu/xdqEht6/wEBCiK+KLdGDVrD4v3A7TnmHzzhvqCsBTL/EmnD3ZMA
1210
+ JVYv4uEBaFpFPSYnPswd353E6KRkFYR4RmFjG9xLTayHXOKqCF6dHd3uVR7NSs98
1211
+ uhcSYRV7g4NdjmaDj8kz5HeRMfr/uqbcriJ9tu/ljFBWYSwPeiNYnYhaOBLpUhZc
1212
+ kyjFDfC+UpwOBPlkK7J047urvzG21xCtVU9DMHtXMkXYe/C+WSm1MRYtgcsOTxpG
1213
+ f+ujceltI2/+IUhWxr5ys7m+xM1jYaM4O1Pw0QIDAQABAoIBAEiVCdiq4HfWmA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C9Vg2MAG3NnzLITopiMcw8rgN0n2uBVcsT4fV
1230
+ i2DhAoGBAIJtHUe9e8oPrasRlZ3bTFmDT+jNg+7RB8ebG8ZDqAUI3/gnklUd0+rF
1231
+ nPGI8GEpjwgBxB/zg4/rYz/TEP0E2pd0beWH2vKD31kQVngbz/zhzLHCNLyKDlB4
1232
+ vFHpXRHb7ddgTLjHbg6GvY/pRRCqSxWnLgNRW4m+pyLzAx/Hpk1D
1233
+ -----END RSA PRIVATE KEY-----
1234
+ """.strip()
1235
+
1179
1236
.. class :: PKCS7SignatureBuilder
1180
1237
1181
1238
The PKCS7 signature builder can create both basic PKCS7 signed messages as
@@ -1254,7 +1311,7 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1254
1311
:returns bytes: The signed PKCS7 message.
1255
1312
1256
1313
1257
- .. function :: pkcs7_verify_der(data, content, certificate, options)
1314
+ .. function :: pkcs7_verify_der(data, content=None , certificate=None , options=None )
1258
1315
1259
1316
.. versionadded :: 45.0.0
1260
1317
@@ -1263,16 +1320,16 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1263
1320
>>> from cryptography import x509
1264
1321
>>> from cryptography.hazmat.primitives import hashes, serialization
1265
1322
>>> from cryptography.hazmat.primitives.serialization import pkcs7
1266
- >>> cert = x509.load_pem_x509_certificate(ca_cert )
1267
- >>> key = serialization.load_pem_private_key(ca_key , None )
1323
+ >>> cert = x509.load_pem_x509_certificate(verify_cert )
1324
+ >>> key = serialization.load_pem_private_key(verify_key , None )
1268
1325
>>> signed = pkcs7.PKCS7SignatureBuilder().set_data(
1269
1326
... b " data to sign"
1270
1327
... ).add_signer(
1271
1328
... cert, key, hashes.SHA256()
1272
1329
... ).sign(
1273
1330
... serialization.Encoding.DER , []
1274
1331
... )
1275
- >>> pkcs7.pkcs7_verify_der(signed, None , cert, [] )
1332
+ >>> pkcs7.pkcs7_verify_der(signed)
1276
1333
1277
1334
Deserialize and verify a DER-encoded PKCS7 signed message. PKCS7 (or S/MIME) has multiple
1278
1335
versions, but this supports a subset of :rfc: `5751 `, also known as S/MIME Version 3.2. If the
@@ -1282,15 +1339,21 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1282
1339
:type data: bytes
1283
1340
1284
1341
:param content: if specified, the content to verify against the signed message. If the content
1285
- is not specified, the function will look for the content in the signed message.
1286
- :type data: bytes or None
1342
+ is not specified, the function will look for the content in the signed message. Defaults to
1343
+ None.
1344
+ :type content: bytes or None
1287
1345
1288
- :param certificate: A :class: `~cryptography.x509.Certificate ` to verify against the signed
1289
- message.
1346
+ :param certificate: if specified, a :class: `~cryptography.x509.Certificate ` to verify against
1347
+ the signed message. If None, the function will look for the signer certificate in the signed
1348
+ message. Defaults to None.
1349
+ :type certificate: :class: `~cryptography.x509.Certificate ` or None
1290
1350
1291
1351
:param options: A list of
1292
- :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For
1293
- this operation, no options are supported as of now.
1352
+ :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For this
1353
+ operation, the `NoSigs ` and `NoVerify ` options are supported. If `NoSigs ` is specified, the
1354
+ function will not verify the signature in the PKCS#7 message. If `NoVerify ` is specified,
1355
+ the function will not verify the certificates in the PKCS#7 message. Defaults to None.
1356
+ :type options: list[`~cryptography.x509.Certificate `] or None
1294
1357
1295
1358
:raises ValueError: If the recipient certificate does not match any of the signers in the
1296
1359
PKCS7 data.
@@ -1300,7 +1363,7 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1300
1363
:raises ValueError: If the PKCS7 data is not of the signed data type.
1301
1364
1302
1365
1303
- .. function :: pkcs7_verify_pem(data, content, certificate, options)
1366
+ .. function :: pkcs7_verify_pem(data, content=None , certificate=None , options=None )
1304
1367
1305
1368
.. versionadded :: 45.0.0
1306
1369
@@ -1309,16 +1372,16 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1309
1372
>>> from cryptography import x509
1310
1373
>>> from cryptography.hazmat.primitives import hashes, serialization
1311
1374
>>> from cryptography.hazmat.primitives.serialization import pkcs7
1312
- >>> cert = x509.load_pem_x509_certificate(ca_cert )
1313
- >>> key = serialization.load_pem_private_key(ca_key , None )
1375
+ >>> cert = x509.load_pem_x509_certificate(verify_cert )
1376
+ >>> key = serialization.load_pem_private_key(verify_key , None )
1314
1377
>>> signed = pkcs7.PKCS7SignatureBuilder().set_data(
1315
1378
... b " data to sign"
1316
1379
... ).add_signer(
1317
1380
... cert, key, hashes.SHA256()
1318
1381
... ).sign(
1319
1382
... serialization.Encoding.PEM , []
1320
1383
... )
1321
- >>> pkcs7.pkcs7_verify_pem(signed, None , cert, [] )
1384
+ >>> pkcs7.pkcs7_verify_pem(signed)
1322
1385
1323
1386
Deserialize and verify a PEM-encoded PKCS7 signed message. PKCS7 (or S/MIME) has multiple
1324
1387
versions, but this supports a subset of :rfc: `5751 `, also known as S/MIME Version 3.2. If the
@@ -1328,15 +1391,21 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1328
1391
:type data: bytes
1329
1392
1330
1393
:param content: if specified, the content to verify against the signed message. If the content
1331
- is not specified, the function will look for the content in the signed message.
1332
- :type data: bytes or None
1394
+ is not specified, the function will look for the content in the signed message. Defaults to
1395
+ None.
1396
+ :type content: bytes or None
1333
1397
1334
- :param certificate: A :class: `~cryptography.x509.Certificate ` to verify against the signed
1335
- message.
1398
+ :param certificate: if specified, a :class: `~cryptography.x509.Certificate ` to verify against
1399
+ the signed message. If None, the function will look for the signer certificate in the signed
1400
+ message. Defaults to None.
1401
+ :type certificate: :class: `~cryptography.x509.Certificate ` or None
1336
1402
1337
1403
:param options: A list of
1338
- :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For
1339
- this operation, no options are supported as of now.
1404
+ :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For this
1405
+ operation, the `NoSigs ` and `NoVerify ` options are supported. If `NoSigs ` is specified, the
1406
+ function will not verify the signature in the PKCS#7 message. If `NoVerify ` is specified,
1407
+ the function will not verify the certificates in the PKCS#7 message. Defaults to None.
1408
+ :type options: list[`~cryptography.x509.Certificate `] or None
1340
1409
1341
1410
:raises ValueError: If the PEM data does not have the PKCS7 tag.
1342
1411
@@ -1348,7 +1417,7 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1348
1417
:raises ValueError: If the PKCS7 data is not of the signed data type.
1349
1418
1350
1419
1351
- .. function :: pkcs7_verify_smime(data, content, certificate, options)
1420
+ .. function :: pkcs7_verify_smime(data, content=None , certificate=None , options=None )
1352
1421
1353
1422
.. versionadded :: 45.0.0
1354
1423
@@ -1357,16 +1426,16 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1357
1426
>>> from cryptography import x509
1358
1427
>>> from cryptography.hazmat.primitives import hashes, serialization
1359
1428
>>> from cryptography.hazmat.primitives.serialization import pkcs7
1360
- >>> cert = x509.load_pem_x509_certificate(ca_cert )
1361
- >>> key = serialization.load_pem_private_key(ca_key , None )
1429
+ >>> cert = x509.load_pem_x509_certificate(verify_cert )
1430
+ >>> key = serialization.load_pem_private_key(verify_key , None )
1362
1431
>>> signed = pkcs7.PKCS7SignatureBuilder().set_data(
1363
1432
... b " data to sign"
1364
1433
... ).add_signer(
1365
1434
... cert, key, hashes.SHA256()
1366
1435
... ).sign(
1367
1436
... serialization.Encoding.SMIME , []
1368
1437
... )
1369
- >>> pkcs7.pkcs7_verify_smime(signed, None , cert, [] )
1438
+ >>> pkcs7.pkcs7_verify_smime(signed)
1370
1439
1371
1440
Verify a PKCS7 signed message stored in a MIME message, by reading it, extracting the content
1372
1441
(if any) and signature, deserializing the signature and verifying it against the content. PKCS7
@@ -1379,15 +1448,21 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1379
1448
1380
1449
:param content: if specified, the content to verify against the signed message. If the content
1381
1450
is not specified, the function will look for the content in the MIME message and in the
1382
- signature.
1383
- :type data : bytes or None
1451
+ signature. Defaults to None.
1452
+ :type content : bytes or None
1384
1453
1385
- :param certificate: A :class: `~cryptography.x509.Certificate ` to verify against the signed
1386
- message.
1454
+ :param certificate: if specified, a :class: `~cryptography.x509.Certificate ` to verify against
1455
+ the signed message. If None, the function will look for the signer certificate in the signed
1456
+ message. Defaults to None.
1457
+ :type certificate: :class: `~cryptography.x509.Certificate ` or None
1387
1458
1388
1459
:param options: A list of
1389
- :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For
1390
- this operation, no options are supported as of now.
1460
+ :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For this
1461
+ operation, the `NoSigs ` and `NoVerify ` options are supported. If `NoSigs ` is specified, the
1462
+ function will not verify the signature in the PKCS#7 message. If `NoVerify ` is specified,
1463
+ the function will not verify the certificates in the PKCS#7 message. Defaults to None.
1464
+ :type options: list[`~cryptography.x509.Certificate `] or None
1465
+
1391
1466
1392
1467
:raises ValueError: If the MIME message is not a S/MIME signed message: content type is
1393
1468
different than ``multipart/signed `` or ``application/pkcs7-mime ``.
0 commit comments