99using Keyfactor . Extensions . Orchestrator . RemoteFile . RemoteHandlers ;
1010using Keyfactor . Logging ;
1111using Keyfactor . PKI . X509 ;
12+ using Keyfactor . PKI . PEM ;
1213using Microsoft . Extensions . Logging ;
1314using Newtonsoft . Json ;
1415using Org . BouncyCastle . Pkcs ;
@@ -352,6 +353,7 @@ internal string GenerateCSROnDevice(string subjectText, bool overwrite, string a
352353 string csr = string . Empty ;
353354 privateKey = RSA . Create ( ) ;
354355
356+
355357 return csr ;
356358 }
357359
@@ -361,40 +363,21 @@ internal string GenerateCSR(string subjectText, bool overwrite, string alias, Su
361363 {
362364 throw new RemoteFileException ( $ "Alias { alias } already exists in store { StorePath + StoreFileName } and overwrite is set to False. Please try again with overwrite set to True if you wish to replace this entry.") ;
363365 }
364-
365- IEnumerable < KeyValuePair < SubjectAltNameElementType , string > > sansList =
366- sans . SelectMany (
367- kvp =>
368- kvp . Value . Select (
369- v => new KeyValuePair < SubjectAltNameElementType , string > (
370- Enum . Parse < SubjectAltNameElementType > ( kvp . Key , ignoreCase : true ) ,
371- v
372- )
373- )
374- ) ;
375-
376- string keyAlgorithm = string . Empty ;
377- switch ( keyType )
378- {
379- case SupportedKeyTypeEnum . RSA :
380- keyAlgorithm = "SHA256withRSA" ;
381- break ;
382- case SupportedKeyTypeEnum . ECC :
383- keyAlgorithm = "SHA256withECDSA" ;
384- if ( keySize == 384 ) keyAlgorithm = "SHA384withECDSA" ;
385- if ( keySize == 521 ) keyAlgorithm = "SHA512withECDSA" ;
386- break ;
387- }
388366
389- RequestGenerator generator = new RequestGenerator ( keyAlgorithm , keySize ) ;
390- generator . SANs = sansList ;
367+ List < string > sansList = sans
368+ . SelectMany ( san => san . Value . Select ( value => $ "{ san . Key } ={ value } ") )
369+ . ToList ( ) ;
370+
371+ RequestGenerator generator = new RequestGenerator ( keyType . ToString ( ) , keySize ) ;
372+ generator . SANs = X509Utilities . ParseSANs ( sansList ) ;
391373 generator . Subject = subjectText ;
392- string csr = System . Text . Encoding . ASCII . GetString ( generator . CreatePKCS10Request ( ) ) ;
374+ string csr = PemUtilities . DERToPEM ( generator . CreatePKCS10Request ( ) , PKI . PEM . PemUtilities . PemObjectType . CertRequest ) ;
375+
393376 privateKey = generator . GetRequestPrivateKey ( ) . ToNetPrivateKey ( ) ;
394377
395378 return csr ;
396379 }
397-
380+
398381 //internal string GenerateCSROnDevice(string subjectText, SupportedKeyTypeEnum keyType, int keySize, List<string> sans, out string privateKey)
399382 //{
400383 // string path = ApplicationSettings.TempFilePathForODKG;
0 commit comments