1313
1414from pymdoccbor .exceptions import MsoPrivateKeyRequired
1515from pymdoccbor import settings
16- from pymdoccbor .x509 import MsoX509FabricInteface
16+ from pymdoccbor .x509 import selfsigned_x509cert
1717from pymdoccbor .tools import shuffle_dict
1818from cryptography import x509
1919from cryptography .hazmat .primitives import serialization
2222
2323logger = logging .getLogger ("pymdoccbor" )
2424
25- class MsoIssuer ( MsoX509FabricInteface ) :
25+ class MsoIssuer :
2626 """
2727 MsoIssuer helper class to create a new mso
2828 """
@@ -41,7 +41,8 @@ def __init__(
4141 hsm : bool | None = False ,
4242 private_key : dict | CoseKey | None = None ,
4343 digest_alg : str | None = settings .PYMDOC_HASHALG ,
44- revocation : dict | None = None
44+ revocation : dict | None = None ,
45+ cert_info : dict | None = None ,
4546 ) -> None :
4647 """
4748 Initialize a new MsoIssuer
@@ -74,8 +75,6 @@ def __init__(
7475 if not hsm :
7576 raise MsoPrivateKeyRequired ("MSO Writer requires a valid private key" )
7677
77- super ().__init__ (self .private_key )
78-
7978 if not validity :
8079 raise ValueError ("validity must be present" )
8180
@@ -84,7 +83,6 @@ def __init__(
8483
8584 self .data : dict = data
8685 self .hash_map : dict = {}
87- self .cert_path = cert_path
8886 self .disclosure_map : dict = {}
8987 self .digest_alg = digest_alg
9088 self .key_label = key_label
@@ -97,6 +95,14 @@ def __init__(
9795 self .validity = validity
9896 self .revocation = revocation
9997
98+ self .cert_path = cert_path
99+ self .cert_info = cert_info
100+
101+ if not self .cert_path and (not self .cert_info or not self .private_key ):
102+ raise ValueError (
103+ "cert_path or cert_info with a private key must be provided to properly insert a certificate"
104+ )
105+
100106 alg_map = {"ES256" : "sha256" , "ES384" : "sha384" , "ES512" : "sha512" }
101107
102108 if self .alg not in alg_map :
@@ -232,7 +238,10 @@ def sign(
232238 raise Exception (f"Certificate at { self .cert_path } failed parse" )
233239 _cert = cert .public_bytes (getattr (serialization .Encoding , "DER" ))
234240 else :
235- _cert = self .selfsigned_x509cert ()
241+ if not self .cert_info :
242+ raise ValueError ("cert_info must be provided if cert_path is not set" )
243+
244+ _cert = selfsigned_x509cert (self .cert_info , self .private_key )
236245
237246 if self .hsm :
238247 # print("payload diganostic notation: \n",cbor2diag(cbor2.dumps(cbor2.CBORTag(24, cbor2.dumps(payload)))))
0 commit comments