Revize e8face67
Přidáno uživatelem Stanislav Král před více než 3 roky(ů)
src/services/cryptography.py | ||
---|---|---|
231 | 231 |
# the process failed because of some other reason (incorrect cert format) |
232 | 232 |
raise CryptographyException(OPENSSL_EXECUTABLE, args, err.decode()) |
233 | 233 |
|
234 |
def extract_public_key(self, cert_pem: str) -> str:
|
|
234 |
def extract_public_key(self, private_key_pem: str, passphrase=None) -> str:
|
|
235 | 235 |
""" |
236 |
Extracts a public key from the given certificate passed in PEM format |
|
237 |
:param cert_pem: PEM data representing a certificate from which a public key should be extracted |
|
236 |
Extracts a public key from the given private key passed in PEM format |
|
237 |
:param private_key_pem: PEM data representing the private key from which a public key should be extracted |
|
238 |
:param passphrase: passphrase to be provided when the supplied private key is encrypted |
|
238 | 239 |
:return: a string containing the extracted public key in PEM format |
239 | 240 |
""" |
240 |
args = ["x509", "-in", "-", "-noout", "-pubkey"] |
|
241 |
return self.__run_for_output(args, proc_input=bytes(cert_pem, encoding="utf-8")).decode() |
|
241 |
args = ["rsa", "-in", "-", "-pubout"] |
|
242 |
if passphrase is not None: |
|
243 |
args.extend(["-passin", f"pass:{passphrase}"]) |
|
244 |
return self.__run_for_output(args, proc_input=bytes(private_key_pem, encoding="utf-8")).decode() |
|
242 | 245 |
|
243 | 246 |
def parse_cert_pem(self, cert_pem): |
244 | 247 |
""" |
Také k dispozici: Unified diff
Re #8573 - Changed extract_public_key method in such way that it now extracts a public key from a private key instead of a certificate