crypto: catch error when loading private key
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
831b32c279
commit
c0c246edab
|
@ -55,11 +55,14 @@ class CertificateKeyPair(CreatedUpdatedModel):
|
||||||
def private_key(self) -> Optional[RSAPrivateKey]:
|
def private_key(self) -> Optional[RSAPrivateKey]:
|
||||||
"""Get python cryptography PrivateKey instance"""
|
"""Get python cryptography PrivateKey instance"""
|
||||||
if not self._private_key and self._private_key != "":
|
if not self._private_key and self._private_key != "":
|
||||||
self._private_key = load_pem_private_key(
|
try:
|
||||||
str.encode("\n".join([x.strip() for x in self.key_data.split("\n")])),
|
self._private_key = load_pem_private_key(
|
||||||
password=None,
|
str.encode("\n".join([x.strip() for x in self.key_data.split("\n")])),
|
||||||
backend=default_backend(),
|
password=None,
|
||||||
)
|
backend=default_backend(),
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
return self._private_key
|
return self._private_key
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Reference in New Issue