Skip to content

Commit 6943ee5

Browse files
authored
Deprecate CSR support in pyOpenSSL (#1316)
1 parent 01b9b56 commit 6943ee5

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Backward-incompatible changes:
1313
Deprecations:
1414
^^^^^^^^^^^^^
1515

16+
- Deprecated ``OpenSSL.crypto.X509Req``, ``OpenSSL.crypto.load_certificate_request``, ``OpenSSL.crypto.dump_certificate_request``. Instead, :class:`cryptography.x509.CertificateSigningRequest`, :class:`cryptography.x509.CertificateSigningRequestBuilder`, :func:`cryptography.x509.load_der_x509_csr`, or :func:`cryptography.x509.load_pem_x509_csr` should be used.
17+
1618
Changes:
1719
^^^^^^^^
1820

src/OpenSSL/crypto.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ def to_cryptography(self) -> x509.CertificateSigningRequest:
993993
"""
994994
from cryptography.x509 import load_der_x509_csr
995995

996-
der = dump_certificate_request(FILETYPE_ASN1, self)
996+
der = _dump_certificate_request_internal(FILETYPE_ASN1, self)
997997

998998
return load_der_x509_csr(der)
999999

@@ -1017,7 +1017,7 @@ def from_cryptography(
10171017
from cryptography.hazmat.primitives.serialization import Encoding
10181018

10191019
der = crypto_req.public_bytes(Encoding.DER)
1020-
return load_certificate_request(FILETYPE_ASN1, der)
1020+
return _load_certificate_request_internal(FILETYPE_ASN1, der)
10211021

10221022
def set_pubkey(self, pkey: PKey) -> None:
10231023
"""
@@ -1193,6 +1193,20 @@ def verify(self, pkey: PKey) -> bool:
11931193
return result
11941194

11951195

1196+
_X509ReqInternal = X509Req
1197+
1198+
utils.deprecated(
1199+
X509Req,
1200+
__name__,
1201+
(
1202+
"CSR support in pyOpenSSL is deprecated. You should use the APIs "
1203+
"in cryptography."
1204+
),
1205+
DeprecationWarning,
1206+
name="X509Req",
1207+
)
1208+
1209+
11961210
class X509:
11971211
"""
11981212
An X.509 certificate.
@@ -2816,6 +2830,20 @@ def dump_certificate_request(type: int, req: X509Req) -> bytes:
28162830
return _bio_to_string(bio)
28172831

28182832

2833+
_dump_certificate_request_internal = dump_certificate_request
2834+
2835+
utils.deprecated(
2836+
dump_certificate_request,
2837+
__name__,
2838+
(
2839+
"CSR support in pyOpenSSL is deprecated. You should use the APIs "
2840+
"in cryptography."
2841+
),
2842+
DeprecationWarning,
2843+
name="dump_certificate_request",
2844+
)
2845+
2846+
28192847
def load_certificate_request(type: int, buffer: bytes) -> X509Req:
28202848
"""
28212849
Load a certificate request (X509Req) from the string *buffer* encoded with
@@ -2839,11 +2867,25 @@ def load_certificate_request(type: int, buffer: bytes) -> X509Req:
28392867

28402868
_openssl_assert(req != _ffi.NULL)
28412869

2842-
x509req = X509Req.__new__(X509Req)
2870+
x509req = _X509ReqInternal.__new__(_X509ReqInternal)
28432871
x509req._req = _ffi.gc(req, _lib.X509_REQ_free)
28442872
return x509req
28452873

28462874

2875+
_load_certificate_request_internal = load_certificate_request
2876+
2877+
utils.deprecated(
2878+
load_certificate_request,
2879+
__name__,
2880+
(
2881+
"CSR support in pyOpenSSL is deprecated. You should use the APIs "
2882+
"in cryptography."
2883+
),
2884+
DeprecationWarning,
2885+
name="load_certificate_request",
2886+
)
2887+
2888+
28472889
def sign(pkey: PKey, data: Union[str, bytes], digest: str) -> bytes:
28482890
"""
28492891
Sign a data string using the given key and message digest.

0 commit comments

Comments
 (0)