Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bhillkeyfactor committed Nov 17, 2021
1 parent d4131ab commit b30a8c8
Showing 1 changed file with 40 additions and 45 deletions.
85 changes: 40 additions & 45 deletions DigiCertSymCaProxy/RequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,9 @@ public EnrollmentRequest GetEnrollmentRequest(EnrollmentProductInfo productInfo,
//2. Loop though list of Parsed CSR Elements and replace in JSON
var csrValues = csrParsed?.Subject.ToString().Split(',');

var getCommonNameFromSubject= false;

//certBot workflow, common name always comes only through SAN and is not in common name
if(csrValues[0].Length > 0)
{
getCommonNameFromSubject = true;
}
bool getCommonNameFromSubject= csrValues != null && csrValues[0].Length > 0;

//certBot workflow, common name always comes only through SAN and is not in common name
if (csrValues != null && getCommonNameFromSubject)
foreach (var csrValue in csrValues)
{
Expand All @@ -230,42 +225,42 @@ public EnrollmentRequest GetEnrollmentRequest(EnrollmentProductInfo productInfo,

Logger.Trace($"Enrollment Serialized JSON before DNS and OU, result: {JsonConvert.SerializeObject(enrollmentRequest)}");

//5. Loop through DNS Entries, if comming from Certbot, then need to get common name from here as well
if (san.ContainsKey("dns"))
{
var dnsList = new List<DnsName>();
var dnsKp = san["dns"];
Logger.Trace($"dnsKP: {dnsKp}");
List<string> commonNameList = new List<string>();

var j = 1;
foreach (var item in dnsKp)
{
commonNameList.Add(item);
if (j < 2)
{
DnsName dns = new DnsName { Id = DnsConstantName, Value = item };
dnsList.Add(dns);
}
else
{
DnsName dns = new DnsName { Id = DnsConstantName + j, Value = item };
dnsList.Add(dns);
}
j++;
}
string commonName = string.Join(",", commonNameList);

var jsonResultDns = JsonConvert.SerializeObject(enrollmentRequest);

if(!getCommonNameFromSubject)
jsonResultDns = ReplaceCsrEntry(new string[] {"CN", commonName }, jsonResult);

enrollmentRequest = JsonConvert.DeserializeObject<EnrollmentRequest>(jsonResultDns);
//5. Loop through DNS Entries, if coming from Cert bot, then need to get common name from here as well
if (san.ContainsKey("dns"))
{
var dnsList = new List<DnsName>();
var dnsKp = san["dns"];
Logger.Trace($"dnsKP: {dnsKp}");
var commonNameList = new List<string>();

var j = 1;
foreach (var item in dnsKp)
{
commonNameList.Add(item);
if (j < 2)
{
DnsName dns = new DnsName { Id = DnsConstantName, Value = item };
dnsList.Add(dns);
}
else
{
DnsName dns = new DnsName { Id = DnsConstantName + j, Value = item };
dnsList.Add(dns);
}
j++;
}
string commonName = string.Join(",", commonNameList);

var jsonResultDns = JsonConvert.SerializeObject(enrollmentRequest);

if(!getCommonNameFromSubject)
jsonResultDns = ReplaceCsrEntry(new[] {"CN", commonName }, jsonResult);

enrollmentRequest = JsonConvert.DeserializeObject<EnrollmentRequest>(jsonResultDns);
sn.DnsName = dnsList;
}

//6. Loop through User Principal Entries
}

//6. Loop through User Principal Entries
if (san.ContainsKey("upn"))
{
var upList = new List<UserPrincipalName>();
Expand All @@ -290,8 +285,8 @@ public EnrollmentRequest GetEnrollmentRequest(EnrollmentProductInfo productInfo,
}
sn.UserPrincipalName = upList;
}

//7. Loop through IP Entries

//7. Loop through IP Entries
if (san.ContainsKey("ip4") || san.ContainsKey("ip6"))
{
var ipList = new List<IpAddress>();
Expand All @@ -317,7 +312,7 @@ public EnrollmentRequest GetEnrollmentRequest(EnrollmentProductInfo productInfo,
sn.IpAddress = ipList;
}

//8. Loop through mail Entries
//8. Loop through mail Entries
if (san.ContainsKey("mail"))
{
var mailList = new List<Rfc822Name>();
Expand Down

0 comments on commit b30a8c8

Please sign in to comment.