77
88logger = logging .getLogger ("pymdoccbor" )
99
10- from pycose .headers import Algorithm
11- from pycose .keys import CoseKey
12-
13- from datetime import timezone
14-
1510from pycose .headers import Algorithm #, KID
1611from pycose .keys import CoseKey , EC2Key
17-
1812from pycose .messages import Sign1Message
1913
2014from typing import Union
2115
22-
2316from pymdoccbor .exceptions import MsoPrivateKeyRequired
2417from pymdoccbor import settings
2518from pymdoccbor .x509 import MsoX509Fabric
@@ -40,8 +33,8 @@ def __init__(
4033 self ,
4134 data : dict ,
4235 validity : dict ,
43- revocation : str = None ,
4436 cert_path : str = None ,
37+ pem_cert_path : str = None ,
4538 key_label : str = None ,
4639 user_pin : str = None ,
4740 lib_path : str = None ,
@@ -51,13 +44,13 @@ def __init__(
5144 hsm : bool = False ,
5245 private_key : Union [dict , CoseKey ] = None ,
5346 digest_alg : str = settings .PYMDOC_HASHALG ,
47+ status_list : dict = {}
5448 ) -> None :
5549 """
5650 Initialize a new MsoIssuer
5751
5852 :param data: dict: the data to sign
5953 :param validity: validity: the validity info of the mso
60- :param revocation: str: the revocation status
6154 :param cert_path: str: the path to the certificate
6255 :param key_label: str: key label
6356 :param user_pin: str: user pin
@@ -68,6 +61,7 @@ def __init__(
6861 :param hsm: bool: hardware security module
6962 :param private_key: Union[dict, CoseKey]: the signing key
7063 :param digest_alg: str: the digest algorithm
64+ :param status_list: dict: the status list to include in the mso
7165 """
7266
7367 if not hsm :
@@ -82,16 +76,17 @@ def __init__(
8276 raise ValueError ("private_key must be a dict or CoseKey object" )
8377 else :
8478 raise MsoPrivateKeyRequired ("MSO Writer requires a valid private key" )
85-
79+
8680 if not validity :
8781 raise ValueError ("validity must be present" )
88-
82+
8983 if not alg :
9084 raise ValueError ("alg must be present" )
9185
9286 self .data : dict = data
9387 self .hash_map : dict = {}
9488 self .cert_path = cert_path
89+ self .pem_cert_path = pem_cert_path
9590 self .disclosure_map : dict = {}
9691 self .digest_alg : str = digest_alg
9792 self .key_label = key_label
@@ -102,7 +97,7 @@ def __init__(
10297 self .alg = alg
10398 self .kid = kid
10499 self .validity = validity
105- self .revocation = revocation
100+ self .status_list = status_list
106101
107102 alg_map = {"ES256" : "sha256" , "ES384" : "sha384" , "ES512" : "sha512" }
108103
@@ -209,18 +204,24 @@ def sign(
209204 "deviceKey" : device_key ,
210205 },
211206 "digestAlgorithm" : alg_map .get (self .alg ),
207+ "status" : self .status_list
212208 }
213209
214- if self .revocation is not None :
215- payload .update ({"status" : self .revocation })
216-
217210 if self .cert_path :
218211 # Load the DER certificate file
219212 with open (self .cert_path , "rb" ) as file :
220213 certificate = file .read ()
221214
222215 cert = x509 .load_der_x509_certificate (certificate )
223216
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+
224225 _cert = cert .public_bytes (getattr (serialization .Encoding , "DER" ))
225226 else :
226227 _cert = self .selfsigned_x509cert ()
0 commit comments