Skip to content

Commit a1bec12

Browse files
committed
Remove pem_cert_path and manage pem or der formats through cert-path parameter
set utc in valid from
1 parent eb60602 commit a1bec12

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

pymdoccbor/mdoc/issuer.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def new(
7474
validity: dict = None,
7575
devicekeyinfo: Union[dict, CoseKey, str] = None,
7676
cert_path: str = None,
77-
pem_cert_path: str = None,
7877
status_list: dict = {},
7978
):
8079
"""
@@ -139,7 +138,6 @@ def new(
139138
msoi = MsoIssuer(
140139
data=data,
141140
cert_path=cert_path,
142-
pem_cert_path=pem_cert_path,
143141
hsm=self.hsm,
144142
key_label=self.key_label,
145143
user_pin=self.user_pin,
@@ -157,12 +155,11 @@ def new(
157155
private_key=self.private_key,
158156
alg=self.alg,
159157
cert_path=cert_path,
160-
pem_cert_path=pem_cert_path,
161158
validity=validity,
162159
status_list=status_list
163160
)
164161

165-
mso = msoi.sign(doctype=doctype, device_key=devicekeyinfo,valid_from=datetime.datetime.now())
162+
mso = msoi.sign(doctype=doctype, device_key=devicekeyinfo,valid_from=datetime.datetime.now(datetime. UTC))
166163

167164
mso_cbor = mso.encode(
168165
tag=False,

pymdoccbor/mso/issuer.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)