Skip to content

Commit a25afcc

Browse files
leefine02leefine02
authored andcommitted
1 parent 1c76847 commit a25afcc

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

RemoteFile/ManagementBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
8282
}
8383
else
8484
{
85-
certificateStore.CreateCertificateStore(certificateStoreSerializer, config, logger);
85+
certificateStore.CreateCertificateStore(certificateStoreSerializer, config.CertificateStoreDetails.Properties, config.CertificateStoreDetails.StorePath, logger);
8686
}
8787
logger.LogDebug($"END create Operation for {config.CertificateStoreDetails.StorePath} on {config.CertificateStoreDetails.ClientMachine}.");
8888
break;

RemoteFile/ReenrollmentBase.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
namespace 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}.");

RemoteFile/RemoteCertificateStore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ internal static PathFile SplitStorePathFile(string pathFileName)
347347
}
348348
}
349349

350-
internal string GenerateCSROnDevice(string subjectText, bool overwrite, string alias, SupportedKeyTypeEnum keyType, int keySize, Dictionary<string, string[]> sans, out AsymmetricAlgorithm pemPrivateKey)
350+
internal string GenerateCSROnDevice(string subjectText, bool overwrite, string alias, SupportedKeyTypeEnum keyType, int keySize, Dictionary<string, string[]> sans, out AsymmetricAlgorithm privateKey)
351351
{
352352
string csr = string.Empty;
353-
pemPrivateKey = string.Empty;
353+
privateKey = RSA.Create();
354354

355355
return csr;
356356
}

RemoteFile/manifest.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
"assemblypath": "RemoteFile.dll",
1414
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.Discovery"
1515
},
16+
"CertStores.RFPkcs12.Reenrollment": {
17+
"assemblypath": "RemoteFile.dll",
18+
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.Reenrollment"
19+
},
1620
"CertStores.RFPEM.Inventory": {
1721
"assemblypath": "RemoteFile.dll",
1822
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.PEM.Inventory"
@@ -25,6 +29,10 @@
2529
"assemblypath": "RemoteFile.dll",
2630
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.Discovery"
2731
},
32+
"CertStores.RFPEM.Reenrollment": {
33+
"assemblypath": "RemoteFile.dll",
34+
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.Reenrollment"
35+
},
2836
"CertStores.RFJKS.Inventory": {
2937
"assemblypath": "RemoteFile.dll",
3038
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.JKS.Inventory"
@@ -37,6 +45,10 @@
3745
"assemblypath": "RemoteFile.dll",
3846
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.Discovery"
3947
},
48+
"CertStores.RFJKS.Reenrollment": {
49+
"assemblypath": "RemoteFile.dll",
50+
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.Reenrollment"
51+
},
4052
"CertStores.RFKDB.Inventory": {
4153
"assemblypath": "RemoteFile.dll",
4254
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.KDB.Inventory"
@@ -61,6 +73,10 @@
6173
"assemblypath": "RemoteFile.dll",
6274
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.Discovery"
6375
},
76+
"CertStores.RFDER.Reenrollment": {
77+
"assemblypath": "RemoteFile.dll",
78+
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.Reenrollment"
79+
},
6480
"CertStores.RFORA.Inventory": {
6581
"assemblypath": "RemoteFile.dll",
6682
"TypeFullName": "Keyfactor.Extensions.Orchestrator.RemoteFile.OraWlt.Inventory"

0 commit comments

Comments
 (0)