@@ -34,7 +34,6 @@ def __init__(
3434 data : dict ,
3535 validity : dict ,
3636 cert_path : str = None ,
37- pem_cert_path : str = None ,
3837 key_label : str = None ,
3938 user_pin : str = None ,
4039 lib_path : str = None ,
@@ -86,7 +85,6 @@ def __init__(
8685 self .data : dict = data
8786 self .hash_map : dict = {}
8887 self .cert_path = cert_path
89- self .pem_cert_path = pem_cert_path
9088 self .disclosure_map : dict = {}
9189 self .digest_alg : str = digest_alg
9290 self .key_label = key_label
@@ -208,20 +206,19 @@ def sign(
208206 }
209207
210208 if self .cert_path :
211- # Load the DER certificate file
209+ # Try to load the certificate file
212210 with open (self .cert_path , "rb" ) as file :
213211 certificate = file .read ()
214-
215- cert = x509 .load_der_x509_certificate (certificate )
216-
217- _cert = cert .public_bytes (getattr (serialization .Encoding , "DER" ))
218- elif self .pem_cert_path :
219- # Load the PEM certificate file
220- with open (self .pem_cert_path , "rb" ) as file :
221- certificate = file .read ()
222-
223- cert = x509 .load_pem_x509_certificate (certificate )
224-
212+ try :
213+ cert = x509 .load_pem_x509_certificate (certificate )
214+ except Exception as e :
215+ logger .error (f"Certificate at { self .cert_path } could not be loaded as PEM, trying DER" )
216+ try :
217+ cert = x509 .load_der_x509_certificate (certificate )
218+ except Exception as e :
219+ _err_msg = f"Certificate at { self .cert_path } could not be loaded as DER"
220+ logger .critical (_err_msg )
221+ raise Exception (_err_msg )
225222 _cert = cert .public_bytes (getattr (serialization .Encoding , "DER" ))
226223 else :
227224 _cert = self .selfsigned_x509cert ()
0 commit comments