Fix openssl_pkcs12 crash with cryptography backend when loading passphrase-protected files (#248)

* Convert passphrase to bytes when loading PKCS#12 file with cryptography.

* Add tests with PKCS#12 passphrase.

* Add changelog fragment.
This commit is contained in:
Felix Fontein
2021-06-11 20:03:16 +02:00
committed by GitHub
parent cda2edf92c
commit 0df33de73e
4 changed files with 12 additions and 6 deletions

View File

@@ -23,7 +23,7 @@ import base64
import binascii
import re
from ansible.module_utils._text import to_text
from ansible.module_utils._text import to_text, to_bytes
from ._asn1 import serialize_asn1_string_as_der
try:
@@ -444,7 +444,8 @@ def parse_pkcs12(pkcs12_bytes, passphrase=None):
'''
if _load_key_and_certificates is None:
raise ValueError('load_key_and_certificates() not present in the current cryptography version')
private_key, certificate, additional_certificates = _load_key_and_certificates(pkcs12_bytes, passphrase)
private_key, certificate, additional_certificates = _load_key_and_certificates(
pkcs12_bytes, to_bytes(passphrase) if passphrase is not None else None)
friendly_name = None
if certificate: