-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19083c8
commit 8969952
Showing
4 changed files
with
37 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from tempfile import NamedTemporaryFile | ||
from typing import Tuple | ||
|
||
from OpenSSL import crypto | ||
|
||
|
||
def get_certificate(cfx_certificate_filepath: str, password: str) -> Tuple: | ||
with open(cfx_certificate_filepath, 'rb') as cert_pfx: | ||
pkcs12 = crypto.load_pkcs12(cert_pfx.read(), password.encode()) | ||
|
||
cert = crypto.dump_certificate(crypto.FILETYPE_PEM, pkcs12.get_certificate()) | ||
key = crypto.dump_privatekey(crypto.FILETYPE_PEM, pkcs12.get_privatekey()) | ||
|
||
cert_ca = b'' | ||
|
||
if pkcs12.get_ca_certificates(): | ||
for ca in pkcs12.get_ca_certificates(): | ||
cert_ca = crypto.dump_certificate(crypto.FILETYPE_PEM, ca) + cert_ca | ||
|
||
cert_ca = cert + cert_ca | ||
|
||
cert_file = _create_temp_file(cert_ca) | ||
key_file = _create_temp_file(key) | ||
|
||
return cert_ca, cert_file, key, key_file | ||
|
||
|
||
def _create_temp_file(content: bytes) -> NamedTemporaryFile: | ||
temp_file = NamedTemporaryFile() | ||
temp_file.write(content) | ||
temp_file.seek(0) | ||
|
||
return temp_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters