Revize 7444d4cb
Přidáno uživatelem Stanislav Král před asi 4 roky(ů)
proj/services/cryptography.py | ||
---|---|---|
38 | 38 |
return "".join([f"/{key}={value}" for key, value in subj_dict.items()]) |
39 | 39 |
|
40 | 40 |
@staticmethod |
41 |
def _run_for_output(args=None, proc_input=None, executable=OPENSSL_EXECUTABLE): |
|
41 |
def __run_for_output(args=None, proc_input=None, executable=OPENSSL_EXECUTABLE):
|
|
42 | 42 |
""" |
43 | 43 |
Launches a new process in which the given executable is run. STDIN and process arguments can be set. |
44 | 44 |
If the process ends with a non-zero then <CryptographyException> is raised. |
... | ... | |
81 | 81 |
:return: string containing the generated private key in PEM format |
82 | 82 |
""" |
83 | 83 |
if passphrase is None or len(passphrase) == 0: |
84 |
return self._run_for_output(["genrsa", "2048"]).decode() |
|
84 |
return self.__run_for_output(["genrsa", "2048"]).decode()
|
|
85 | 85 |
else: |
86 |
return self._run_for_output( |
|
86 |
return self.__run_for_output(
|
|
87 | 87 |
["genrsa", PRIVATE_KEY_ENCRYPTION_METHOD, "-passout", f"pass:{passphrase}", "2048"]).decode() |
88 | 88 |
|
89 | 89 |
def create_sscrt(self, key, subject, config="", extensions="", key_pass=None): |
... | ... | |
119 | 119 |
# waiting for the passphrase to be typed in |
120 | 120 |
args.extend(["-passin", f"pass:{key_pass}"]) |
121 | 121 |
|
122 |
return self._run_for_output(args, proc_input=bytes(key, encoding="utf-8")).decode() |
|
122 |
return self.__run_for_output(args, proc_input=bytes(key, encoding="utf-8")).decode()
|
|
123 | 123 |
|
124 | 124 |
def __create_csr(self, subject, subject_key, subject_key_pass=""): |
125 | 125 |
""" |
... | ... | |
139 | 139 |
# waiting for the passphrase to be typed in |
140 | 140 |
args.extend(["-passin", f"pass:{subject_key_pass}"]) |
141 | 141 |
|
142 |
return self._run_for_output(args, proc_input=bytes(subject_key, encoding="utf-8")).decode() |
|
142 |
return self.__run_for_output(args, proc_input=bytes(subject_key, encoding="utf-8")).decode()
|
|
143 | 143 |
|
144 | 144 |
def __sign_csr(self, csr, issuer_pem, issuer_key, issuer_key_pass=None, extensions="", days=30): |
145 | 145 |
""" |
... | ... | |
172 | 172 |
if len(extensions) > 0: |
173 | 173 |
params.extend(["-extfile", ext_path]) |
174 | 174 |
|
175 |
return self._run_for_output(params, proc_input=(bytes(proc_input, encoding="utf-8"))).decode() |
|
175 |
return self.__run_for_output(params, proc_input=(bytes(proc_input, encoding="utf-8"))).decode()
|
|
176 | 176 |
|
177 | 177 |
def create_crt(self, subject, subject_key, issuer_pem, issuer_key, subject_key_pass=None, issuer_key_pass=None, |
178 | 178 |
extensions="", |
Také k dispozici: Unified diff
Re #8472 - Changed access modifier of run_for_output method to private (was protected previously)