Revize dd03da19
Přidáno uživatelem Stanislav Král před asi 4 roky(ů)
proj/services/cryptography.py | ||
---|---|---|
12 | 12 |
class CryptographyService: |
13 | 13 |
|
14 | 14 |
@staticmethod |
15 |
def subject_to_param_format(subject): |
|
15 |
def _subject_to_param_format(subject):
|
|
16 | 16 |
subj_dict = {} |
17 | 17 |
if subject.common_name is not None: |
18 | 18 |
subj_dict["CN"] = subject.common_name |
... | ... | |
96 | 96 |
assert key is not None |
97 | 97 |
assert subject is not None |
98 | 98 |
|
99 |
subj = self.subject_to_param_format(subject) |
|
99 |
subj = self._subject_to_param_format(subject)
|
|
100 | 100 |
|
101 | 101 |
with TemporaryFile("openssl.conf", config) as conf_path: |
102 | 102 |
args = ["req", "-x509", "-new", "-subj", subj, |
... | ... | |
116 | 116 |
|
117 | 117 |
return self._run_for_output(args, proc_input=bytes(key, encoding="utf-8")).decode() |
118 | 118 |
|
119 |
def create_csr(self, subject, subject_key, subject_key_pass=""): |
|
119 |
def _create_csr(self, subject, subject_key, subject_key_pass=""):
|
|
120 | 120 |
""" |
121 | 121 |
Creates a CSR (Certificate Signing Request) |
122 | 122 |
|
... | ... | |
126 | 126 |
:return: string containing the generated certificate signing request in PEM format |
127 | 127 |
""" |
128 | 128 |
|
129 |
subj_param = self.subject_to_param_format(subject) |
|
129 |
subj_param = self._subject_to_param_format(subject)
|
|
130 | 130 |
|
131 | 131 |
args = ["req", "-new", "-subj", subj_param, "-key", "-"] |
132 | 132 |
|
... | ... | |
136 | 136 |
|
137 | 137 |
return self._run_for_output(args, proc_input=bytes(subject_key, encoding="utf-8")).decode() |
138 | 138 |
|
139 |
def sign_csr(self, csr, issuer_pem, issuer_key, issuer_key_pass=None, extensions="", days=30): |
|
139 |
def _sign_csr(self, csr, issuer_pem, issuer_key, issuer_key_pass=None, extensions="", days=30):
|
|
140 | 140 |
""" |
141 | 141 |
Signs the given CSR by the given issuer CA |
142 | 142 |
|
... | ... | |
188 | 188 |
:param days: number of days for which the certificate will be valid |
189 | 189 |
:return: string containing the generated certificate in PEM format |
190 | 190 |
""" |
191 |
csr = self.create_csr(subject, subject_key, subject_key_pass=subject_key_pass) |
|
192 |
return self.sign_csr(csr, issuer_pem, issuer_key, issuer_key_pass=issuer_key_pass, extensions=extensions, |
|
193 |
days=days) |
|
191 |
csr = self._create_csr(subject, subject_key, subject_key_pass=subject_key_pass)
|
|
192 |
return self._sign_csr(csr, issuer_pem, issuer_key, issuer_key_pass=issuer_key_pass, extensions=extensions,
|
|
193 |
days=days)
|
|
194 | 194 |
|
195 | 195 |
@staticmethod |
196 | 196 |
def verify_cert(certificate): |
Také k dispozici: Unified diff
Re #8472 - Changed access modifiers of some methods and fixed verify_ca_test.py