From c0c246edab282aaca81d13b3371318c8d38e24cf Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 21 Jun 2021 15:57:48 +0200 Subject: [PATCH] crypto: catch error when loading private key Signed-off-by: Jens Langhammer --- authentik/crypto/models.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/authentik/crypto/models.py b/authentik/crypto/models.py index 3b447e66d..afe30e6ee 100644 --- a/authentik/crypto/models.py +++ b/authentik/crypto/models.py @@ -55,11 +55,14 @@ class CertificateKeyPair(CreatedUpdatedModel): def private_key(self) -> Optional[RSAPrivateKey]: """Get python cryptography PrivateKey instance""" if not self._private_key and self._private_key != "": - self._private_key = load_pem_private_key( - str.encode("\n".join([x.strip() for x in self.key_data.split("\n")])), - password=None, - backend=default_backend(), - ) + try: + self._private_key = load_pem_private_key( + str.encode("\n".join([x.strip() for x in self.key_data.split("\n")])), + password=None, + backend=default_backend(), + ) + except ValueError: + return None return self._private_key @property