@@ -90,8 +90,11 @@ async def by_pk_or_callsign(cls, inval: Union[str, uuid.UUID], allow_deleted: bo
90
90
return await cls .by_callsign (str (inval ), allow_deleted )
91
91
92
92
@classmethod
93
- async def create_with_cert (cls , callsign : str , extra : Optional [Dict [str , Any ]] = None ) -> "Person" :
93
+ async def create_with_cert (
94
+ cls , callsign : str , extra : Optional [Dict [str , Any ]] = None , csrpem : Optional [str ] = None
95
+ ) -> "Person" :
94
96
"""Create the cert etc and save the person"""
97
+ # FIXME: Verify the CSR has the callsign as CN
95
98
cnf = RMSettings .singleton ()
96
99
if callsign in cnf .valid_product_cns :
97
100
raise CallsignReserved ("Using product CNs as callsigns is forbidden" )
@@ -110,8 +113,11 @@ async def create_with_cert(cls, callsign: str, extra: Optional[Dict[str, Any]] =
110
113
newperson = Person (pk = puuid , callsign = callsign , certspath = str (certspath ), extra = extra )
111
114
session .add (newperson )
112
115
session .commit ()
113
- ckp = await async_create_keypair (newperson .privkeyfile , newperson .pubkeyfile )
114
- csrpem = await async_create_client_csr (ckp , newperson .csrfile , newperson .certsubject )
116
+ if csrpem :
117
+ newperson .csrfile .write_text (csrpem , encoding = "utf-8" )
118
+ else :
119
+ ckp = await async_create_keypair (newperson .privkeyfile , newperson .pubkeyfile )
120
+ csrpem = await async_create_client_csr (ckp , newperson .csrfile , newperson .certsubject )
115
121
certpem = (await sign_csr (csrpem )).replace ("\\ n" , "\n " )
116
122
newperson .certfile .write_text (certpem )
117
123
except Exception as exc :
@@ -150,7 +156,10 @@ async def create_pfx(self) -> Path:
150
156
def write_pfx () -> None :
151
157
"""Do the IO"""
152
158
nonlocal self
153
- p12bytes = convert_pem_to_pkcs12 (self .certfile , self .privkeyfile , self .callsign , None , self .callsign )
159
+ if self .privkeyfile .exists ():
160
+ p12bytes = convert_pem_to_pkcs12 (self .certfile , self .privkeyfile , self .callsign , None , self .callsign )
161
+ else :
162
+ p12bytes = convert_pem_to_pkcs12 (self .certfile , None , self .callsign , None , self .callsign )
154
163
self .pfxfile .write_bytes (p12bytes )
155
164
156
165
await asyncio .get_event_loop ().run_in_executor (None , write_pfx )
0 commit comments