|
63 | 63 | "dump_privatekey", |
64 | 64 | "Revoked", |
65 | 65 | "CRL", |
66 | | - "PKCS7", |
67 | 66 | "PKCS12", |
68 | 67 | "NetscapeSPKI", |
69 | 68 | "load_publickey", |
|
74 | 73 | "verify", |
75 | 74 | "dump_crl", |
76 | 75 | "load_crl", |
77 | | - "load_pkcs7_data", |
78 | | - "load_pkcs12", |
79 | 76 | ] |
80 | 77 |
|
81 | 78 |
|
@@ -2567,52 +2564,6 @@ def export( |
2567 | 2564 | return dump_crl(type, self) |
2568 | 2565 |
|
2569 | 2566 |
|
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 | | - |
2616 | 2567 | class PKCS12: |
2617 | 2568 | """ |
2618 | 2569 | A PKCS #12 archive. |
@@ -2800,6 +2751,18 @@ def export( |
2800 | 2751 | return _bio_to_string(bio) |
2801 | 2752 |
|
2802 | 2753 |
|
| 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 | + |
2803 | 2766 | class NetscapeSPKI: |
2804 | 2767 | """ |
2805 | 2768 | A Netscape SPKI object. |
@@ -2890,6 +2853,15 @@ def set_pubkey(self, pkey: PKey) -> None: |
2890 | 2853 | _openssl_assert(set_result == 1) |
2891 | 2854 |
|
2892 | 2855 |
|
| 2856 | +utils.deprecated( |
| 2857 | + NetscapeSPKI, |
| 2858 | + __name__, |
| 2859 | + "NetscapeSPKI support in pyOpenSSL is deprecated.", |
| 2860 | + DeprecationWarning, |
| 2861 | + name="NetscapeSPKI", |
| 2862 | +) |
| 2863 | + |
| 2864 | + |
2893 | 2865 | class _PassphraseHelper: |
2894 | 2866 | def __init__( |
2895 | 2867 | self, |
@@ -3229,143 +3201,3 @@ def load_crl(type: int, buffer: Union[str, bytes]) -> CRL: |
3229 | 3201 | result = CRL.__new__(CRL) |
3230 | 3202 | result._crl = _ffi.gc(crl, _lib.X509_CRL_free) |
3231 | 3203 | 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