Revize 19e5260d
Přidáno uživatelem Stanislav Král před téměř 4 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, private_key_pem: str, passphrase=None) -> str: |
|
234 |
def extract_public_key_from_private_key(self, private_key_pem: str, passphrase=None) -> str:
|
|
235 | 235 |
""" |
236 | 236 |
Extracts a public key from the given private key passed in PEM format |
237 | 237 |
:param private_key_pem: PEM data representing the private key from which a public key should be extracted |
... | ... | |
243 | 243 |
args.extend(["-passin", f"pass:{passphrase}"]) |
244 | 244 |
return self.__run_for_output(args, proc_input=bytes(private_key_pem, encoding="utf-8")).decode() |
245 | 245 |
|
246 |
def extract_public_key_from_certificate(self, cert_pem: str) -> str: |
|
247 |
""" |
|
248 |
Extracts a public key from the given certificate passed in PEM format |
|
249 |
:param cert_pem: PEM data representing a certificate from which a public key should be extracted |
|
250 |
:return: a string containing the extracted public key in PEM format |
|
251 |
""" |
|
252 |
# extracting public key from a certificate does not seem to require a passphrase even when |
|
253 |
# signed using an encrypted PK |
|
254 |
args = ["x509", "-in", "-", "-noout", "-pubkey"] |
|
255 |
return self.__run_for_output(args, proc_input=bytes(cert_pem, encoding="utf-8")).decode() |
|
256 |
|
|
246 | 257 |
def parse_cert_pem(self, cert_pem): |
247 | 258 |
""" |
248 | 259 |
Parses the given certificate in PEM format and returns the subject of the certificate and it's NOT_BEFORE |
Také k dispozici: Unified diff
Re #8573 - Implemented extract_public_key_from_certificate