@@ -34,7 +34,6 @@ def __init__(
34
34
data : dict ,
35
35
validity : dict ,
36
36
cert_path : str = None ,
37
- pem_cert_path : str = None ,
38
37
key_label : str = None ,
39
38
user_pin : str = None ,
40
39
lib_path : str = None ,
@@ -86,7 +85,6 @@ def __init__(
86
85
self .data : dict = data
87
86
self .hash_map : dict = {}
88
87
self .cert_path = cert_path
89
- self .pem_cert_path = pem_cert_path
90
88
self .disclosure_map : dict = {}
91
89
self .digest_alg : str = digest_alg
92
90
self .key_label = key_label
@@ -208,20 +206,19 @@ def sign(
208
206
}
209
207
210
208
if self .cert_path :
211
- # Load the DER certificate file
209
+ # Try to load the certificate file
212
210
with open (self .cert_path , "rb" ) as file :
213
211
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 )
225
222
_cert = cert .public_bytes (getattr (serialization .Encoding , "DER" ))
226
223
else :
227
224
_cert = self .selfsigned_x509cert ()
0 commit comments