Revize 4a40b0d2
Přidáno uživatelem Stanislav Král před asi 4 roky(ů)
src/services/cryptography.py | ||
---|---|---|
1 | 1 |
import subprocess |
2 |
import re |
|
2 | 3 | |
3 | 4 |
# encryption method to be used when generating private keys |
4 | 5 |
from src.utils.temporary_file import TemporaryFile |
... | ... | |
225 | 226 |
# the process failed because of some other reason (incorrect cert format) |
226 | 227 |
raise CryptographyException(OPENSSL_EXECUTABLE, args, err.decode()) |
227 | 228 | |
229 |
def parse_cert_pem(self, cert_pem): |
|
230 |
args = ["x509", "-noout", "-text", "-in", "-"] |
|
231 | ||
232 |
result = self.__run_for_output(args, proc_input=bytes(cert_pem, encoding="utf-8")).decode() |
|
233 |
match = re.search(r"Subject:\s(.*)", result) |
|
234 |
pass |
|
235 |
# TODO use logger |
|
236 |
if match is None: |
|
237 |
print(f"Could not find subject to parse: {result}") |
|
238 |
else: |
|
239 |
found = re.findall(r"\s?([^=\s]+)\s?=\s?([^,\n]+)", match) |
|
240 |
print(found) |
|
241 |
for pair in found: |
|
242 |
print(pair) |
|
243 | ||
244 | ||
228 | 245 | |
229 | 246 |
class CryptographyException(Exception): |
230 | 247 |
Také k dispozici: Unified diff
Re #8472 - WIP commit of adding a method capable of parsing a Subject from a cert PEM