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