Skip to content

Commit d7e9dd4

Browse files
authored
Deprecate CRL APIs (#1251)
Deprecate `crypto.CRL`, `crypto.Revoked`, `crypto.load_crl` and `crypto.dump_crl`.
1 parent dca21f2 commit d7e9dd4

File tree

3 files changed

+70
-12
lines changed

3 files changed

+70
-12
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ Backward-incompatible changes:
1919
Deprecations:
2020
^^^^^^^^^^^^^
2121

22-
- Deprecated ``OpenSSL.crypto.PKCS12`` (which was intended to have been deprecated at the same time as ``OpenSSL.crypto.loads_pkcs12``).
22+
- Deprecated ``OpenSSL.crypto.PKCS12`` (which was intended to have been deprecated at the same time as ``OpenSSL.crypto.load_pkcs12``).
2323
- Deprecated ``OpenSSL.crypto.NetscapeSPKI``.
24+
- Deprecated ``OpenSSL.crypto.CRL``
25+
- Deprecated ``OpenSSL.crypto.Revoked``
26+
- Deprecated ``OpenSSL.crypto.load_crl`` and ``OpenSSL.crypto.dump_crl``
2427

2528
Changes:
2629
^^^^^^^^

src/OpenSSL/crypto.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,6 +2349,19 @@ def get_rev_date(self) -> Optional[bytes]:
23492349
return _get_asn1_time(dt)
23502350

23512351

2352+
_RevokedInternal = Revoked
2353+
utils.deprecated(
2354+
Revoked,
2355+
__name__,
2356+
(
2357+
"CRL support in pyOpenSSL is deprecated. You should use the APIs "
2358+
"in cryptography."
2359+
),
2360+
DeprecationWarning,
2361+
name="Revoked",
2362+
)
2363+
2364+
23522365
class CRL:
23532366
"""
23542367
A certificate revocation list.
@@ -2368,7 +2381,7 @@ def to_cryptography(self) -> x509.CertificateRevocationList:
23682381
"""
23692382
from cryptography.x509 import load_der_x509_crl
23702383

2371-
der = dump_crl(FILETYPE_ASN1, self)
2384+
der = _dump_crl_internal(FILETYPE_ASN1, self)
23722385
return load_der_x509_crl(der)
23732386

23742387
@classmethod
@@ -2391,9 +2404,9 @@ def from_cryptography(
23912404
from cryptography.hazmat.primitives.serialization import Encoding
23922405

23932406
der = crypto_crl.public_bytes(Encoding.DER)
2394-
return load_crl(FILETYPE_ASN1, der)
2407+
return _load_crl_internal(FILETYPE_ASN1, der)
23952408

2396-
def get_revoked(self) -> Optional[Tuple[Revoked, ...]]:
2409+
def get_revoked(self) -> Optional[Tuple[_RevokedInternal, ...]]:
23972410
"""
23982411
Return the revocations in this certificate revocation list.
23992412
@@ -2408,7 +2421,7 @@ def get_revoked(self) -> Optional[Tuple[Revoked, ...]]:
24082421
for i in range(_lib.sk_X509_REVOKED_num(revoked_stack)):
24092422
revoked = _lib.sk_X509_REVOKED_value(revoked_stack, i)
24102423
revoked_copy = _lib.X509_REVOKED_dup(revoked)
2411-
pyrev = Revoked.__new__(Revoked)
2424+
pyrev = _RevokedInternal.__new__(_RevokedInternal)
24122425
pyrev._revoked = _ffi.gc(revoked_copy, _lib.X509_REVOKED_free)
24132426
results.append(pyrev)
24142427
if results:
@@ -2578,7 +2591,20 @@ def export(
25782591
if not sign_result:
25792592
_raise_current_error()
25802593

2581-
return dump_crl(type, self)
2594+
return _dump_crl_internal(type, self)
2595+
2596+
2597+
_CRLInternal = CRL
2598+
utils.deprecated(
2599+
CRL,
2600+
__name__,
2601+
(
2602+
"CRL support in pyOpenSSL is deprecated. You should use the APIs "
2603+
"in cryptography."
2604+
),
2605+
DeprecationWarning,
2606+
name="CRL",
2607+
)
25822608

25832609

25842610
class PKCS12:
@@ -3190,6 +3216,19 @@ def dump_crl(type: int, crl: CRL) -> bytes:
31903216
return _bio_to_string(bio)
31913217

31923218

3219+
_dump_crl_internal = dump_crl
3220+
utils.deprecated(
3221+
dump_crl,
3222+
__name__,
3223+
(
3224+
"CRL support in pyOpenSSL is deprecated. You should use the APIs "
3225+
"in cryptography."
3226+
),
3227+
DeprecationWarning,
3228+
name="dump_crl",
3229+
)
3230+
3231+
31933232
def load_crl(type: int, buffer: Union[str, bytes]) -> CRL:
31943233
"""
31953234
Load Certificate Revocation List (CRL) data from a string *buffer*.
@@ -3215,6 +3254,19 @@ def load_crl(type: int, buffer: Union[str, bytes]) -> CRL:
32153254
if crl == _ffi.NULL:
32163255
_raise_current_error()
32173256

3218-
result = CRL.__new__(CRL)
3257+
result = _CRLInternal.__new__(_CRLInternal)
32193258
result._crl = _ffi.gc(crl, _lib.X509_CRL_free)
32203259
return result
3260+
3261+
3262+
_load_crl_internal = load_crl
3263+
utils.deprecated(
3264+
load_crl,
3265+
__name__,
3266+
(
3267+
"CRL support in pyOpenSSL is deprecated. You should use the APIs "
3268+
"in cryptography."
3269+
),
3270+
DeprecationWarning,
3271+
name="load_crl",
3272+
)

tests/test_crypto.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from OpenSSL._util import ffi as _ffi
2020
from OpenSSL._util import lib as _lib
2121
from OpenSSL.crypto import (
22-
CRL,
2322
FILETYPE_ASN1,
2423
FILETYPE_PEM,
2524
FILETYPE_TEXT,
@@ -28,7 +27,6 @@
2827
X509,
2928
Error,
3029
PKey,
31-
Revoked,
3230
X509Extension,
3331
X509Name,
3432
X509Req,
@@ -38,22 +36,27 @@
3836
X509StoreFlags,
3937
dump_certificate,
4038
dump_certificate_request,
41-
dump_crl,
4239
dump_privatekey,
4340
dump_publickey,
4441
get_elliptic_curve,
4542
get_elliptic_curves,
4643
load_certificate,
4744
load_certificate_request,
48-
load_crl,
4945
load_privatekey,
5046
load_publickey,
5147
sign,
5248
verify,
5349
)
5450

5551
with pytest.warns(DeprecationWarning):
56-
from OpenSSL.crypto import PKCS12, NetscapeSPKI
52+
from OpenSSL.crypto import (
53+
CRL,
54+
PKCS12,
55+
NetscapeSPKI,
56+
Revoked,
57+
dump_crl,
58+
load_crl,
59+
)
5760

5861
from .util import (
5962
NON_ASCII,

0 commit comments

Comments
 (0)