Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crypto hints PKCS12 deprecation warning #1150

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/plugins/analysis/crypto_material/internal/key_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from struct import unpack

import OpenSSL
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.serialization import pkcs12

from helperFunctions.data_conversion import make_unicode_string

Expand Down Expand Up @@ -48,9 +50,14 @@ def read_pkcs_cert(binary: bytes, offset: int):
return None
start, size = _get_start_and_size_of_der_field(binary=binary, offset=offset)
try:
x509_cert = OpenSSL.crypto.load_pkcs12(buffer=binary[offset : start + size]).get_certificate()
private_key, certificate, additional_certificates = pkcs12.load_key_and_certificates(
binary[offset : start + size], None
)
x509_cert = OpenSSL.crypto.load_certificate(
OpenSSL.crypto.FILETYPE_PEM, certificate.public_bytes(serialization.Encoding.PEM)
)
return make_unicode_string(OpenSSL.crypto.dump_certificate(type=OpenSSL.crypto.FILETYPE_TEXT, cert=x509_cert))
except OpenSSL.crypto.Error:
except ValueError:
logging.debug('Found PKCS#12 certificate, but passphrase is missing or false positive.')
return None

Expand Down
Loading