2020
2121namespace Keyfactor . Extensions . Orchestrator . RemoteFile
2222{
23- public abstract class ReenrollmentBase : RemoteFileJobTypeBase
23+ public abstract class ReenrollmentBase : RemoteFileJobTypeBase , IReenrollmentJobExtension
2424 {
2525 public string ExtensionName => "Keyfactor.Extensions.Orchestrator.RemoteFile" ;
2626
@@ -41,7 +41,7 @@ internal enum SupportedKeyTypeEnum
4141 // 6) Modify ReenrollmentBase to implement IReenrollmentJobExtension
4242 // 6) Update README. Remember to explain the differences between ODKG and OOKG
4343
44- public JobResult ProcessJobToDo ( ReenrollmentJobConfiguration config , SubmitReenrollmentCSR submitReenrollment )
44+ public JobResult ProcessJob ( ReenrollmentJobConfiguration config , SubmitReenrollmentCSR submitReenrollment )
4545 {
4646 ILogger logger = LogHandler . GetClassLogger ( this . GetType ( ) ) ;
4747
@@ -80,21 +80,35 @@ public JobResult ProcessJobToDo(ReenrollmentJobConfiguration config, SubmitReenr
8080 }
8181 else
8282 {
83- csr = certificateStore . GenerateCSR ( SubjectText , config . Overwrite , config . Alias , KeyTypeEnum , KeySize , config . SANs , out privateKey ) ) ;
83+ csr = certificateStore . GenerateCSR ( SubjectText , config . Overwrite , config . Alias , KeyTypeEnum , KeySize , config . SANs , out privateKey ) ;
8484 }
8585
8686 X509Certificate2 cert = submitReenrollment . Invoke ( csr ) ;
87- cert .
87+
8888 if ( cert == null )
8989 throw new RemoteFileException ( "Enrollment of CSR failed. Please check Keyfactor Command logs for more information on potential enrollment errors." ) ;
9090
91- //AsymmetricAlgorithm alg = KeyTypeEnum == SupportedKeyTypeEnum.RSA ? RSA.Create() : ECDsa.Create();
92- //alg.ImportEncryptedPkcs8PrivateKey(string.Empty, Keyfactor.PKI.PEM.PemUtilities.PEMToDER(pemPrivateKey), out _);
93- //cert = KeyTypeEnum == SupportedKeyTypeEnum.RSA ? cert.CopyWithPrivateKey((RSA)alg) : cert.CopyWithPrivateKey((ECDsa)alg);
91+ switch ( privateKey )
92+ {
93+ case RSA rsa :
94+ cert = cert . CopyWithPrivateKey ( rsa ) ;
95+ break ;
96+
97+ case ECDsa ecdsa :
98+ cert = cert . CopyWithPrivateKey ( ecdsa ) ;
99+ break ;
100+
101+ case DSA dsa :
102+ cert = cert . CopyWithPrivateKey ( dsa ) ;
103+ break ;
104+
105+ default :
106+ throw new NotSupportedException ( $ "Unsupported key type: { privateKey ? . GetType ( ) . Name } ") ;
107+ }
94108
95109 // save certificate
96110 certificateStore . LoadCertificateStore ( certificateStoreSerializer , false ) ;
97- certificateStore . AddCertificate ( alias ?? cert . Thumbprint , Convert . ToBase64String ( cert . Export ( X509ContentType . Pfx ) ) , overwrite , null , RemoveRootCertificate ) ;
111+ certificateStore . AddCertificate ( config . Alias ?? cert . Thumbprint , Convert . ToBase64String ( cert . Export ( X509ContentType . Pfx ) ) , config . Overwrite , null , RemoveRootCertificate ) ;
98112 certificateStore . SaveCertificateStore ( certificateStoreSerializer . SerializeRemoteCertificateStore ( certificateStore . GetCertificateStore ( ) , storePathFile . Path , storePathFile . File , StorePassword , certificateStore . RemoteHandler ) ) ;
99113
100114 logger . LogDebug ( $ "END add Operation for { config . CertificateStoreDetails . StorePath } on { config . CertificateStoreDetails . ClientMachine } .") ;
0 commit comments