@@ -1262,6 +1262,63 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1262
1262
-----END PRIVATE KEY-----
1263
1263
""".strip()
1264
1264
1265
+ verify_cert = b"""
1266
+ -----BEGIN CERTIFICATE-----
1267
+ MIID9zCCAt+gAwIBAgIQIxMA+XhyS9Ou0qAc0zPyVTANBgkqhkiG9w0BAQsFADAN
1268
+ MQswCQYDVQQDDAJDQTAeFw0yNTAxMDUxMDQ4MjhaFw0yNjAxMDUxMDQ4MjhaMCUx
1269
+ IzAhBgkqhkiG9w0BCQEWFGRlbW8xQHRyaXNvZnQuY29tLnBsMIIBIjANBgkqhkiG
1270
+ 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt0WRzh5y+QmEUjCm+iHXZLrstOSSEhiEcUre
1271
+ 3L8zkuGYVLCKBEvmaHQI7uCu/xdqEht6/wEBCiK+KLdGDVrD4v3A7TnmHzzhvqCs
1272
+ BTL/EmnD3ZMAJVYv4uEBaFpFPSYnPswd353E6KRkFYR4RmFjG9xLTayHXOKqCF6d
1273
+ Hd3uVR7NSs98uhcSYRV7g4NdjmaDj8kz5HeRMfr/uqbcriJ9tu/ljFBWYSwPeiNY
1274
+ nYhaOBLpUhZckyjFDfC+UpwOBPlkK7J047urvzG21xCtVU9DMHtXMkXYe/C+WSm1
1275
+ MRYtgcsOTxpGf+ujceltI2/+IUhWxr5ys7m+xM1jYaM4O1Pw0QIDAQABo4IBOTCC
1276
+ ATUwDAYDVR0TAQH/BAIwADAfBgNVHSMEGDAWgBQduUy7zqv6z3uk4fJeifohSntD
1277
+ 2TAtBgNVHR8EJjAkMCKgIKAehhxodHRwOi8vY2EudHJpc29mdC5jb20ucGwvY3Js
1278
+ MGYGCCsGAQUFBwEBBFowWDArBggrBgEFBQcwAoYfaHR0cDovL2NhLnRyaXNvZnQu
1279
+ Y29tLnBsL2NhY2VydDApBggrBgEFBQcwAYYdaHR0cDovL2NhLnRyaXNvZnQuY29t
1280
+ LnBsL29jc3AwHwYDVR0RBBgwFoEUZGVtbzFAdHJpc29mdC5jb20ucGwwHQYDVR0l
1281
+ BBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMEMB0GA1UdDgQWBBT0/QFDFX/CCMsX356G
1282
+ ImiWwPYxjDAOBgNVHQ8BAf8EBAMCA+gwDQYJKoZIhvcNAQELBQADggEBAL3Iisca
1283
+ IqoFBLMox3cIhCANWO/U1eOvjDjfM/tOHn+6jci/pL/ZHgdRtqCCiaCKtJED/f/9
1284
+ NFUKqcSZ9+vzW0RWLJxHgIvCSjLpoM06XClSlxjVnv62Hb1NC4FfDfnzyG+DZHus
1285
+ nz/MQuXNwHntA6+JyB/HWHUie2ierQYH2mEN1XIJm5luSGwtuGaWfNz/w324ukcV
1286
+ pMd3CbEOZqqfSYGWUHOVG90/OMSfKA/I0hia8Yij0X4Ny+b+bLnHaoozZwJ/UqBl
1287
+ 9ptbfiOOuFXJP7gt547Rp6+2C0XGJM+le0EYlUzbWE6UWgxaIRp5uc8HnUd5e4lX
1288
+ br+Ixxcl3WHckkk=
1289
+ -----END CERTIFICATE-----
1290
+ """.strip()
1291
+
1292
+ verify_key = b"""
1293
+ -----BEGIN RSA PRIVATE KEY-----
1294
+ MIIEowIBAAKCAQEAt0WRzh5y+QmEUjCm+iHXZLrstOSSEhiEcUre3L8zkuGYVLCK
1295
+ BEvmaHQI7uCu/xdqEht6/wEBCiK+KLdGDVrD4v3A7TnmHzzhvqCsBTL/EmnD3ZMA
1296
+ JVYv4uEBaFpFPSYnPswd353E6KRkFYR4RmFjG9xLTayHXOKqCF6dHd3uVR7NSs98
1297
+ uhcSYRV7g4NdjmaDj8kz5HeRMfr/uqbcriJ9tu/ljFBWYSwPeiNYnYhaOBLpUhZc
1298
+ kyjFDfC+UpwOBPlkK7J047urvzG21xCtVU9DMHtXMkXYe/C+WSm1MRYtgcsOTxpG
1299
+ f+ujceltI2/+IUhWxr5ys7m+xM1jYaM4O1Pw0QIDAQABAoIBAEiVCdiq4HfWmA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C9Vg2MAG3NnzLITopiMcw8rgN0n2uBVcsT4fV
1316
+ i2DhAoGBAIJtHUe9e8oPrasRlZ3bTFmDT+jNg+7RB8ebG8ZDqAUI3/gnklUd0+rF
1317
+ nPGI8GEpjwgBxB/zg4/rYz/TEP0E2pd0beWH2vKD31kQVngbz/zhzLHCNLyKDlB4
1318
+ vFHpXRHb7ddgTLjHbg6GvY/pRRCqSxWnLgNRW4m+pyLzAx/Hpk1D
1319
+ -----END RSA PRIVATE KEY-----
1320
+ """.strip()
1321
+
1265
1322
.. class :: PKCS7SignatureBuilder
1266
1323
1267
1324
The PKCS7 signature builder can create both basic PKCS7 signed messages as
@@ -1340,7 +1397,7 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1340
1397
:returns bytes: The signed PKCS7 message.
1341
1398
1342
1399
1343
- .. function :: pkcs7_verify_der(data, content, certificate, options)
1400
+ .. function :: pkcs7_verify_der(data, content=None , certificate=None , options=None )
1344
1401
1345
1402
.. versionadded :: 45.0.0
1346
1403
@@ -1349,16 +1406,16 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1349
1406
>>> from cryptography import x509
1350
1407
>>> from cryptography.hazmat.primitives import hashes, serialization
1351
1408
>>> from cryptography.hazmat.primitives.serialization import pkcs7
1352
- >>> cert = x509.load_pem_x509_certificate(ca_cert )
1353
- >>> key = serialization.load_pem_private_key(ca_key , None )
1409
+ >>> cert = x509.load_pem_x509_certificate(verify_cert )
1410
+ >>> key = serialization.load_pem_private_key(verify_key , None )
1354
1411
>>> signed = pkcs7.PKCS7SignatureBuilder().set_data(
1355
1412
... b " data to sign"
1356
1413
... ).add_signer(
1357
1414
... cert, key, hashes.SHA256()
1358
1415
... ).sign(
1359
1416
... serialization.Encoding.DER , []
1360
1417
... )
1361
- >>> pkcs7.pkcs7_verify_der(signed, None , cert, [] )
1418
+ >>> pkcs7.pkcs7_verify_der(signed)
1362
1419
1363
1420
Deserialize and verify a DER-encoded PKCS7 signed message. PKCS7 (or S/MIME) has multiple
1364
1421
versions, but this supports a subset of :rfc: `5751 `, also known as S/MIME Version 3.2. If the
@@ -1368,15 +1425,21 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1368
1425
:type data: bytes
1369
1426
1370
1427
:param content: if specified, the content to verify against the signed message. If the content
1371
- is not specified, the function will look for the content in the signed message.
1372
- :type data: bytes or None
1428
+ is not specified, the function will look for the content in the signed message. Defaults to
1429
+ None.
1430
+ :type content: bytes or None
1373
1431
1374
- :param certificate: A :class: `~cryptography.x509.Certificate ` to verify against the signed
1375
- message.
1432
+ :param certificate: if specified, a :class: `~cryptography.x509.Certificate ` to verify against
1433
+ the signed message. If None, the function will look for the signer certificate in the signed
1434
+ message. Defaults to None.
1435
+ :type certificate: :class: `~cryptography.x509.Certificate ` or None
1376
1436
1377
1437
:param options: A list of
1378
- :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For
1379
- this operation, no options are supported as of now.
1438
+ :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For this
1439
+ operation, the `NoSigs ` and `NoVerify ` options are supported. If `NoSigs ` is specified, the
1440
+ function will not verify the signature in the PKCS#7 message. If `NoVerify ` is specified,
1441
+ the function will not verify the certificates in the PKCS#7 message. Defaults to None.
1442
+ :type options: list[`~cryptography.x509.Certificate `] or None
1380
1443
1381
1444
:raises ValueError: If the recipient certificate does not match any of the signers in the
1382
1445
PKCS7 data.
@@ -1386,7 +1449,7 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1386
1449
:raises ValueError: If the PKCS7 data is not of the signed data type.
1387
1450
1388
1451
1389
- .. function :: pkcs7_verify_pem(data, content, certificate, options)
1452
+ .. function :: pkcs7_verify_pem(data, content=None , certificate=None , options=None )
1390
1453
1391
1454
.. versionadded :: 45.0.0
1392
1455
@@ -1395,16 +1458,16 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1395
1458
>>> from cryptography import x509
1396
1459
>>> from cryptography.hazmat.primitives import hashes, serialization
1397
1460
>>> from cryptography.hazmat.primitives.serialization import pkcs7
1398
- >>> cert = x509.load_pem_x509_certificate(ca_cert )
1399
- >>> key = serialization.load_pem_private_key(ca_key , None )
1461
+ >>> cert = x509.load_pem_x509_certificate(verify_cert )
1462
+ >>> key = serialization.load_pem_private_key(verify_key , None )
1400
1463
>>> signed = pkcs7.PKCS7SignatureBuilder().set_data(
1401
1464
... b " data to sign"
1402
1465
... ).add_signer(
1403
1466
... cert, key, hashes.SHA256()
1404
1467
... ).sign(
1405
1468
... serialization.Encoding.PEM , []
1406
1469
... )
1407
- >>> pkcs7.pkcs7_verify_pem(signed, None , cert, [] )
1470
+ >>> pkcs7.pkcs7_verify_pem(signed)
1408
1471
1409
1472
Deserialize and verify a PEM-encoded PKCS7 signed message. PKCS7 (or S/MIME) has multiple
1410
1473
versions, but this supports a subset of :rfc: `5751 `, also known as S/MIME Version 3.2. If the
@@ -1414,15 +1477,21 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1414
1477
:type data: bytes
1415
1478
1416
1479
:param content: if specified, the content to verify against the signed message. If the content
1417
- is not specified, the function will look for the content in the signed message.
1418
- :type data: bytes or None
1480
+ is not specified, the function will look for the content in the signed message. Defaults to
1481
+ None.
1482
+ :type content: bytes or None
1419
1483
1420
- :param certificate: A :class: `~cryptography.x509.Certificate ` to verify against the signed
1421
- message.
1484
+ :param certificate: if specified, a :class: `~cryptography.x509.Certificate ` to verify against
1485
+ the signed message. If None, the function will look for the signer certificate in the signed
1486
+ message. Defaults to None.
1487
+ :type certificate: :class: `~cryptography.x509.Certificate ` or None
1422
1488
1423
1489
:param options: A list of
1424
- :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For
1425
- this operation, no options are supported as of now.
1490
+ :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For this
1491
+ operation, the `NoSigs ` and `NoVerify ` options are supported. If `NoSigs ` is specified, the
1492
+ function will not verify the signature in the PKCS#7 message. If `NoVerify ` is specified,
1493
+ the function will not verify the certificates in the PKCS#7 message. Defaults to None.
1494
+ :type options: list[`~cryptography.x509.Certificate `] or None
1426
1495
1427
1496
:raises ValueError: If the PEM data does not have the PKCS7 tag.
1428
1497
@@ -1434,7 +1503,7 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1434
1503
:raises ValueError: If the PKCS7 data is not of the signed data type.
1435
1504
1436
1505
1437
- .. function :: pkcs7_verify_smime(data, content, certificate, options)
1506
+ .. function :: pkcs7_verify_smime(data, content=None , certificate=None , options=None )
1438
1507
1439
1508
.. versionadded :: 45.0.0
1440
1509
@@ -1443,16 +1512,16 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1443
1512
>>> from cryptography import x509
1444
1513
>>> from cryptography.hazmat.primitives import hashes, serialization
1445
1514
>>> from cryptography.hazmat.primitives.serialization import pkcs7
1446
- >>> cert = x509.load_pem_x509_certificate(ca_cert )
1447
- >>> key = serialization.load_pem_private_key(ca_key , None )
1515
+ >>> cert = x509.load_pem_x509_certificate(verify_cert )
1516
+ >>> key = serialization.load_pem_private_key(verify_key , None )
1448
1517
>>> signed = pkcs7.PKCS7SignatureBuilder().set_data(
1449
1518
... b " data to sign"
1450
1519
... ).add_signer(
1451
1520
... cert, key, hashes.SHA256()
1452
1521
... ).sign(
1453
1522
... serialization.Encoding.SMIME , []
1454
1523
... )
1455
- >>> pkcs7.pkcs7_verify_smime(signed, None , cert, [] )
1524
+ >>> pkcs7.pkcs7_verify_smime(signed)
1456
1525
1457
1526
Verify a PKCS7 signed message stored in a MIME message, by reading it, extracting the content
1458
1527
(if any) and signature, deserializing the signature and verifying it against the content. PKCS7
@@ -1465,15 +1534,21 @@ contain certificates, CRLs, and much more. PKCS7 files commonly have a ``p7b``,
1465
1534
1466
1535
:param content: if specified, the content to verify against the signed message. If the content
1467
1536
is not specified, the function will look for the content in the MIME message and in the
1468
- signature.
1469
- :type data : bytes or None
1537
+ signature. Defaults to None.
1538
+ :type content : bytes or None
1470
1539
1471
- :param certificate: A :class: `~cryptography.x509.Certificate ` to verify against the signed
1472
- message.
1540
+ :param certificate: if specified, a :class: `~cryptography.x509.Certificate ` to verify against
1541
+ the signed message. If None, the function will look for the signer certificate in the signed
1542
+ message. Defaults to None.
1543
+ :type certificate: :class: `~cryptography.x509.Certificate ` or None
1473
1544
1474
1545
:param options: A list of
1475
- :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For
1476
- this operation, no options are supported as of now.
1546
+ :class: `~cryptography.hazmat.primitives.serialization.pkcs7.PKCS7Options `. For this
1547
+ operation, the `NoSigs ` and `NoVerify ` options are supported. If `NoSigs ` is specified, the
1548
+ function will not verify the signature in the PKCS#7 message. If `NoVerify ` is specified,
1549
+ the function will not verify the certificates in the PKCS#7 message. Defaults to None.
1550
+ :type options: list[`~cryptography.x509.Certificate `] or None
1551
+
1477
1552
1478
1553
:raises ValueError: If the MIME message is not a S/MIME signed message: content type is
1479
1554
different than ``multipart/signed `` or ``application/pkcs7-mime ``.
0 commit comments