Skip to content

Commit 0fe822d

Browse files
authored
Removed deprecated functionality. (#1223)
Deprecated some functionality that should have been deprecated a long time ago.
1 parent 5134ca1 commit 0fe822d

File tree

4 files changed

+64
-576
lines changed

4 files changed

+64
-576
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ Backward-incompatible changes:
1212

1313
- Dropped support for Python 3.6.
1414
- The minimum ``cryptography`` version is now 41.0.0.
15+
- Removed ``OpenSSL.crypto.loads_pkcs7`` and ``OpenSSL.crypto.loads_pkcs12`` which had been deprecated for 3 years.
1516

1617
Deprecations:
1718
^^^^^^^^^^^^^
1819

20+
- Deprecated ``OpenSSL.crypto.PKCS12`` (which was intended to have been deprecated at the same time as ``OpenSSL.crypto.loads_pkcs12``).
21+
- Deprecated ``OpenSSL.crypto.NetscapeSPKI``.
22+
1923
Changes:
2024
^^^^^^^^
2125

doc/api/crypto.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ Certificate revocation lists
6868

6969
.. autofunction:: load_crl
7070

71-
.. autofunction:: load_pkcs7_data
72-
73-
.. autofunction:: load_pkcs12
74-
7571
Signing and verifying signatures
7672
--------------------------------
7773

@@ -159,21 +155,11 @@ PKey objects
159155
.. autoclass:: PKey
160156
:members:
161157

162-
.. _openssl-pkcs7:
163-
164158
.. py:data:: TYPE_RSA
165159
TYPE_DSA
166160
167161
Key type constants.
168162

169-
PKCS7 objects
170-
-------------
171-
172-
PKCS7 objects have the following methods:
173-
174-
.. autoclass:: PKCS7
175-
:members:
176-
177163
.. _openssl-pkcs12:
178164

179165
PKCS12 objects

src/OpenSSL/crypto.py

Lines changed: 21 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"dump_privatekey",
6464
"Revoked",
6565
"CRL",
66-
"PKCS7",
6766
"PKCS12",
6867
"NetscapeSPKI",
6968
"load_publickey",
@@ -74,8 +73,6 @@
7473
"verify",
7574
"dump_crl",
7675
"load_crl",
77-
"load_pkcs7_data",
78-
"load_pkcs12",
7976
]
8077

8178

@@ -2567,52 +2564,6 @@ def export(
25672564
return dump_crl(type, self)
25682565

25692566

2570-
class PKCS7:
2571-
_pkcs7: Any
2572-
2573-
def type_is_signed(self) -> bool:
2574-
"""
2575-
Check if this NID_pkcs7_signed object
2576-
2577-
:return: True if the PKCS7 is of type signed
2578-
"""
2579-
return bool(_lib.PKCS7_type_is_signed(self._pkcs7))
2580-
2581-
def type_is_enveloped(self) -> bool:
2582-
"""
2583-
Check if this NID_pkcs7_enveloped object
2584-
2585-
:returns: True if the PKCS7 is of type enveloped
2586-
"""
2587-
return bool(_lib.PKCS7_type_is_enveloped(self._pkcs7))
2588-
2589-
def type_is_signedAndEnveloped(self) -> bool:
2590-
"""
2591-
Check if this NID_pkcs7_signedAndEnveloped object
2592-
2593-
:returns: True if the PKCS7 is of type signedAndEnveloped
2594-
"""
2595-
return bool(_lib.PKCS7_type_is_signedAndEnveloped(self._pkcs7))
2596-
2597-
def type_is_data(self) -> bool:
2598-
"""
2599-
Check if this NID_pkcs7_data object
2600-
2601-
:return: True if the PKCS7 is of type data
2602-
"""
2603-
return bool(_lib.PKCS7_type_is_data(self._pkcs7))
2604-
2605-
def get_type_name(self) -> str:
2606-
"""
2607-
Returns the type name of the PKCS7 structure
2608-
2609-
:return: A string with the typename
2610-
"""
2611-
nid = _lib.OBJ_obj2nid(self._pkcs7.type)
2612-
string_type = _lib.OBJ_nid2sn(nid)
2613-
return _ffi.string(string_type)
2614-
2615-
26162567
class PKCS12:
26172568
"""
26182569
A PKCS #12 archive.
@@ -2800,6 +2751,18 @@ def export(
28002751
return _bio_to_string(bio)
28012752

28022753

2754+
utils.deprecated(
2755+
PKCS12,
2756+
__name__,
2757+
(
2758+
"PKCS#12 support in pyOpenSSL is deprecated. You should use the APIs "
2759+
"in cryptography."
2760+
),
2761+
DeprecationWarning,
2762+
name="PKCS12",
2763+
)
2764+
2765+
28032766
class NetscapeSPKI:
28042767
"""
28052768
A Netscape SPKI object.
@@ -2890,6 +2853,15 @@ def set_pubkey(self, pkey: PKey) -> None:
28902853
_openssl_assert(set_result == 1)
28912854

28922855

2856+
utils.deprecated(
2857+
NetscapeSPKI,
2858+
__name__,
2859+
"NetscapeSPKI support in pyOpenSSL is deprecated.",
2860+
DeprecationWarning,
2861+
name="NetscapeSPKI",
2862+
)
2863+
2864+
28932865
class _PassphraseHelper:
28942866
def __init__(
28952867
self,
@@ -3229,143 +3201,3 @@ def load_crl(type: int, buffer: Union[str, bytes]) -> CRL:
32293201
result = CRL.__new__(CRL)
32303202
result._crl = _ffi.gc(crl, _lib.X509_CRL_free)
32313203
return result
3232-
3233-
3234-
def load_pkcs7_data(type: int, buffer: Union[str, bytes]) -> PKCS7:
3235-
"""
3236-
Load pkcs7 data from the string *buffer* encoded with the type
3237-
*type*.
3238-
3239-
:param type: The file type (one of FILETYPE_PEM or FILETYPE_ASN1)
3240-
:param buffer: The buffer with the pkcs7 data.
3241-
:return: The PKCS7 object
3242-
"""
3243-
if isinstance(buffer, str):
3244-
buffer = buffer.encode("ascii")
3245-
3246-
bio = _new_mem_buf(buffer)
3247-
3248-
if type == FILETYPE_PEM:
3249-
pkcs7 = _lib.PEM_read_bio_PKCS7(bio, _ffi.NULL, _ffi.NULL, _ffi.NULL)
3250-
elif type == FILETYPE_ASN1:
3251-
pkcs7 = _lib.d2i_PKCS7_bio(bio, _ffi.NULL)
3252-
else:
3253-
raise ValueError("type argument must be FILETYPE_PEM or FILETYPE_ASN1")
3254-
3255-
if pkcs7 == _ffi.NULL:
3256-
_raise_current_error()
3257-
3258-
pypkcs7 = PKCS7.__new__(PKCS7)
3259-
pypkcs7._pkcs7 = _ffi.gc(pkcs7, _lib.PKCS7_free)
3260-
return pypkcs7
3261-
3262-
3263-
utils.deprecated(
3264-
load_pkcs7_data,
3265-
__name__,
3266-
(
3267-
"PKCS#7 support in pyOpenSSL is deprecated. You should use the APIs "
3268-
"in cryptography."
3269-
),
3270-
DeprecationWarning,
3271-
name="load_pkcs7_data",
3272-
)
3273-
3274-
3275-
def load_pkcs12(
3276-
buffer: Union[str, bytes], passphrase: Optional[bytes] = None
3277-
) -> PKCS12:
3278-
"""
3279-
Load pkcs12 data from the string *buffer*. If the pkcs12 structure is
3280-
encrypted, a *passphrase* must be included. The MAC is always
3281-
checked and thus required.
3282-
3283-
See also the man page for the C function :py:func:`PKCS12_parse`.
3284-
3285-
:param buffer: The buffer the certificate is stored in
3286-
:param passphrase: (Optional) The password to decrypt the PKCS12 lump
3287-
:returns: The PKCS12 object
3288-
"""
3289-
passphrase = _text_to_bytes_and_warn("passphrase", passphrase)
3290-
3291-
if isinstance(buffer, str):
3292-
buffer = buffer.encode("ascii")
3293-
3294-
bio = _new_mem_buf(buffer)
3295-
3296-
# Use null passphrase if passphrase is None or empty string. With PKCS#12
3297-
# password based encryption no password and a zero length password are two
3298-
# different things, but OpenSSL implementation will try both to figure out
3299-
# which one works.
3300-
if not passphrase:
3301-
passphrase = _ffi.NULL
3302-
3303-
p12 = _lib.d2i_PKCS12_bio(bio, _ffi.NULL)
3304-
if p12 == _ffi.NULL:
3305-
_raise_current_error()
3306-
p12 = _ffi.gc(p12, _lib.PKCS12_free)
3307-
3308-
pkey = _ffi.new("EVP_PKEY**")
3309-
cert = _ffi.new("X509**")
3310-
cacerts = _ffi.new("Cryptography_STACK_OF_X509**")
3311-
3312-
parse_result = _lib.PKCS12_parse(p12, passphrase, pkey, cert, cacerts)
3313-
if not parse_result:
3314-
_raise_current_error()
3315-
3316-
cacerts = _ffi.gc(cacerts[0], _lib.sk_X509_free)
3317-
3318-
# openssl 1.0.0 sometimes leaves an X509_check_private_key error in the
3319-
# queue for no particular reason. This error isn't interesting to anyone
3320-
# outside this function. It's not even interesting to us. Get rid of it.
3321-
try:
3322-
_raise_current_error()
3323-
except Error:
3324-
pass
3325-
3326-
if pkey[0] == _ffi.NULL:
3327-
pykey = None
3328-
else:
3329-
pykey = PKey.__new__(PKey)
3330-
pykey._pkey = _ffi.gc(pkey[0], _lib.EVP_PKEY_free)
3331-
3332-
if cert[0] == _ffi.NULL:
3333-
pycert = None
3334-
friendlyname = None
3335-
else:
3336-
pycert = X509._from_raw_x509_ptr(cert[0])
3337-
3338-
friendlyname_length = _ffi.new("int*")
3339-
friendlyname_buffer = _lib.X509_alias_get0(
3340-
cert[0], friendlyname_length
3341-
)
3342-
friendlyname = _ffi.buffer(
3343-
friendlyname_buffer, friendlyname_length[0]
3344-
)[:]
3345-
if friendlyname_buffer == _ffi.NULL:
3346-
friendlyname = None
3347-
3348-
pycacerts = []
3349-
for i in range(_lib.sk_X509_num(cacerts)):
3350-
x509 = _lib.sk_X509_value(cacerts, i)
3351-
pycacert = X509._from_raw_x509_ptr(x509)
3352-
pycacerts.append(pycacert)
3353-
3354-
pkcs12 = PKCS12.__new__(PKCS12)
3355-
pkcs12._pkey = pykey
3356-
pkcs12._cert = pycert
3357-
pkcs12._cacerts = pycacerts if pycacerts else None
3358-
pkcs12._friendlyname = friendlyname
3359-
return pkcs12
3360-
3361-
3362-
utils.deprecated(
3363-
load_pkcs12,
3364-
__name__,
3365-
(
3366-
"PKCS#12 support in pyOpenSSL is deprecated. You should use the APIs "
3367-
"in cryptography."
3368-
),
3369-
DeprecationWarning,
3370-
name="load_pkcs12",
3371-
)

0 commit comments

Comments
 (0)