Skip to content

Commit fdd1961

Browse files
author
Lee Fine
committed
1 parent 30080b4 commit fdd1961

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
v4.0.0
22
- Added ability to run post job commands for Management-Add and ODKG jobs.
3+
- Bug Fix: Issue adding certificates without private keys introduced in 3.0.0
34

45
v3.0.0
56
- Added support for post quantum ML-DSA certificates for store types RFPEM, RFJKS, RFPkcs12, and RFDER

RemoteFile/RemoteCertificateStore.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
using static Keyfactor.Extensions.Orchestrator.RemoteFile.ReenrollmentBase;
2626
using static Keyfactor.PKI.PKIConstants.X509;
2727
using Keyfactor.PKI.PrivateKeys;
28+
using Keyfactor.PKI.CryptographicObjects.Formatters;
29+
using Org.BouncyCastle.X509;
2830

2931
namespace Keyfactor.Extensions.Orchestrator.RemoteFile
3032
{
@@ -263,7 +265,7 @@ internal void AddCertificate(string alias, string certificateEntry, bool overwri
263265
RemoveRootCertificate(Convert.FromBase64String(certificateEntry), pfxPassword) :
264266
Convert.FromBase64String(certificateEntry);
265267

266-
using (MemoryStream ms = new MemoryStream(newCertBytes))
268+
using (MemoryStream ms = new MemoryStream(string.IsNullOrEmpty(pfxPassword) ? ConvertDERToP12(newCertBytes) : newCertBytes))
267269
{
268270
newEntry.Load(ms, string.IsNullOrEmpty(pfxPassword) ? new char[0] : pfxPassword.ToCharArray());
269271
}
@@ -580,6 +582,23 @@ private string FormatPath(string path)
580582

581583
return "'" + path + (path.Substring(path.Length - 1) == @"\" ? string.Empty : @"\") + "'";
582584
}
585+
586+
private byte[] ConvertDERToP12(byte[] cert)
587+
{
588+
X509Certificate x509Cert = new X509CertificateParser().ReadCertificate(cert);
589+
Pkcs12Store store = new Pkcs12StoreBuilder().Build();
590+
store.SetCertificateEntry("temp", new X509CertificateEntry(x509Cert));
591+
592+
using (var ms = new MemoryStream())
593+
{
594+
store.Save(
595+
ms,
596+
new char[] {},
597+
new SecureRandom()
598+
);
599+
return ms.ToArray();
600+
}
601+
}
583602
}
584603

585604
class PathFile

0 commit comments

Comments
 (0)