Skip to content

Commit e13b387

Browse files
leefine02leefine02
authored andcommitted
1 parent 8eb6712 commit e13b387

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

RemoteFile/ReenrollmentBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public JobResult ProcessJob(ReenrollmentJobConfiguration config, SubmitReenrollm
5353

5454
certificateStore = new RemoteCertificateStore(config.CertificateStoreDetails.ClientMachine, UserName, UserPassword, config.CertificateStoreDetails.StorePath, StorePassword, SSHPort, IncludePortInSPN);
5555
certificateStore.Initialize(SudoImpersonatedUser, UseShellCommands);
56+
certificateStore.LoadCertificateStore(certificateStoreSerializer, false);
5657

5758
if (!certificateStore.DoesStoreExist())
5859
{
@@ -107,7 +108,6 @@ public JobResult ProcessJob(ReenrollmentJobConfiguration config, SubmitReenrollm
107108
}
108109

109110
// save certificate
110-
certificateStore.LoadCertificateStore(certificateStoreSerializer, false);
111111
certificateStore.AddCertificate(config.Alias ?? cert.Thumbprint, Convert.ToBase64String(cert.Export(X509ContentType.Pfx)), config.Overwrite, null, RemoveRootCertificate);
112112
certificateStore.SaveCertificateStore(certificateStoreSerializer.SerializeRemoteCertificateStore(certificateStore.GetCertificateStore(), storePathFile.Path, storePathFile.File, StorePassword, certificateStore.RemoteHandler));
113113

RemoteFile/RemoteCertificateStore.cs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Keyfactor.Extensions.Orchestrator.RemoteFile.RemoteHandlers;
1010
using Keyfactor.Logging;
1111
using Keyfactor.PKI.X509;
12+
using Keyfactor.PKI.PEM;
1213
using Microsoft.Extensions.Logging;
1314
using Newtonsoft.Json;
1415
using 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;

RemoteFile/RemoteFileJobTypeBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ internal void SetJobProperties(JobConfiguration config, CertificateStore certifi
8080
if (config.JobProperties != null)
8181
{
8282
KeyType = !config.JobProperties.ContainsKey("keyType") || config.JobProperties["keyType"] == null || string.IsNullOrEmpty(config.JobProperties["keyType"].ToString()) ? string.Empty : config.JobProperties["keyType"].ToString();
83+
if (KeyType == "ECDSA") KeyType = "ECC";
8384
KeySize = !config.JobProperties.ContainsKey("keySize") || config.JobProperties["keySize"] == null || string.IsNullOrEmpty(config.JobProperties["keySize"].ToString()) || !int.TryParse(config.JobProperties["keySize"].ToString(), out int notUsed2) ? 2048 : Convert.ToInt32(config.JobProperties["keySize"]);
8485
SubjectText = !config.JobProperties.ContainsKey("subjectText") || config.JobProperties["subjectText"] == null || string.IsNullOrEmpty(config.JobProperties["subjectText"].ToString()) ? string.Empty : config.JobProperties["subjectText"].ToString();
8586
}

0 commit comments

Comments
 (0)