Skip to content

Commit

Permalink
Merge pull request #25 from Keyfactor/blanksubject
Browse files Browse the repository at this point in the history
Allow for empty CN subject fields
  • Loading branch information
dgaley authored Apr 2, 2024
2 parents 26810c5 + 03c7625 commit 4d58a10
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/SectigoCAProxy/SectigoCAProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,11 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
{
Logger.Debug("Parse Subject for Common Name, Organization, and Org Unit");

string commonName = ParseSubject(subject, "CN=");
Logger.Trace($"Common Name: {commonName}");
string commonName = ParseSubject(subject, "CN=", false);
if (!string.IsNullOrEmpty(commonName))
{
Logger.Trace($"Common Name: {commonName}");
}

string orgStr = null;
if (productInfo.ProductParameters.ContainsKey("Organization"))
Expand Down Expand Up @@ -390,7 +393,7 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
comments = $"CERTIFICATE_REQUESTOR: {productInfo.ProductParameters["Keyfactor-Requester"]}"//this is how the current gateway passes this data
};

Logger.Debug($"Submit {enrollmentType} request for {subject}");
Logger.Debug($"Submit {enrollmentType} request");
sslId = Task.Run(async () => await Client.Enroll(request)).Result;
newCert = Task.Run(async () => await Client.GetCertificate(sslId)).Result;
Logger.Debug($"Enrolled for Certificate {newCert.CommonName} (ID: {newCert.Id}) | Status: {newCert.status}. Attempt to Pickup Certificate.");
Expand Down Expand Up @@ -635,16 +638,21 @@ private static string ParseSanList(Dictionary<string, string[]> san, bool multiD

if (!multiDomain)
{
if (allSans.Contains(commonName) && allSans.Count() > 1)
if (!string.IsNullOrEmpty(commonName) && allSans.Contains(commonName) && allSans.Count() > 1)
{
List<string> sans = allSans.ToList();
sans.Remove(commonName);
sanList = string.Join(",", sans.ToArray());
}
else
{
List<string> sans = allSans.ToList();
sanList = string.Join(",", sans.ToArray());
}
}
else
{
if (allSans.Contains(commonName))
if (!string.IsNullOrEmpty(commonName) && allSans.Contains(commonName))
{
List<string> sans = allSans.ToList();
sans.Remove(commonName);
Expand Down

0 comments on commit 4d58a10

Please sign in to comment.