Skip to content

Commit

Permalink
Constant Names more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
bhillkeyfactor committed Nov 8, 2021
1 parent 0048246 commit ebfe704
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
35 changes: 17 additions & 18 deletions DigiCertSymCaProxy/Client/DigiCertSymClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,13 @@ public async Task SubmitQueryOrderRequestAsync(BlockingCollection<ICertificateDe
try
{
var itemsProcessed = 0;
var pageCounter = 1;
var isComplete = false;
var retryCount = 0;

foreach (var seat in SeatList.Split(','))
{
Logger.Trace($"Processing SeatId {seat}");
pageCounter = 1;
var pageCounter = 1;
do
{
var queryOrderRequest =
Expand All @@ -202,23 +201,23 @@ public async Task SubmitQueryOrderRequestAsync(BlockingCollection<ICertificateDe
JsonConvert.SerializeObject(queryOrderRequest), Encoding.ASCII, "application/json"), ct))
{

if (!resp.IsSuccessStatusCode)
{
var responseMessage = resp.Content.ReadAsStringAsync().Result;
Logger.Trace($"Raw error response {responseMessage}");

//igngore missing Certificate in search 404 errors
if (!responseMessage.Contains("entity_not_found"))
{
Logger.Error(
$"Failed Request to Digicert mPKI. Retrying request. Status Code {resp.StatusCode} | Message: {responseMessage}");
retryCount++;
if (retryCount > 5)
throw new RetryCountExceededException(
$"5 consecutive failures to {resp.RequestMessage.RequestUri}");
if (!resp.IsSuccessStatusCode)
{
var responseMessage = resp.Content.ReadAsStringAsync().Result;
Logger.Trace($"Raw error response {responseMessage}");

//igngore missing Certificate in search 404 errors
if (!responseMessage.Contains("entity_not_found"))
{
Logger.Error(
$"Failed Request to Digicert mPKI. Retrying request. Status Code {resp.StatusCode} | Message: {responseMessage}");
retryCount++;
if (retryCount > 5)
throw new RetryCountExceededException(
$"5 consecutive failures to {resp.RequestMessage.RequestUri}");
}
break; //Seat has no certs move on to the next seat
}
break; //Seat has no certs move on to the next seat
}

var response = JsonConvert.DeserializeObject<CertificateSearchResponse>(
await resp.Content.ReadAsStringAsync());
Expand Down
10 changes: 8 additions & 2 deletions DigiCertSymCaProxy/DigiCertSymProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ namespace Keyfactor.AnyGateway.DigiCertSym
{
public class DigiCertSymProxy : BaseCAConnector
{
private readonly RequestManager _requestManager;
private RequestManager _requestManager;

public DigiCertSymProxy()
{
_requestManager = new RequestManager();
}

private IDigiCertSymClient DigiCertSymClient { get; set; }
Expand Down Expand Up @@ -249,6 +248,13 @@ public override void Initialize(ICAConnectorConfigProvider configProvider)
try
{
Logger.MethodEntry(ILogExtensions.MethodLogLevel.Debug);
_requestManager = new RequestManager
{
DnsConstantName = configProvider.CAConnectionData["DnsConstantName"].ToString(),
UpnConstantName = configProvider.CAConnectionData["UpnConstantName"].ToString(),
IpConstantName = configProvider.CAConnectionData["IpConstantName"].ToString(),
EmailConstantName = configProvider.CAConnectionData["EmailConstantName"].ToString()
};
DigiCertSymClient = new DigiCertSymClient(configProvider);
Logger.MethodExit(ILogExtensions.MethodLogLevel.Debug);
}
Expand Down
21 changes: 13 additions & 8 deletions DigiCertSymCaProxy/RequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public enum KeyfactorRevokeReasons : uint
CessationOfOperation = 5
}

public string DnsConstantName { get; set; }
public string UpnConstantName { get; set; }
public string IpConstantName { get; set; }
public string EmailConstantName { get; set; }

public static Func<string, string> Pemify = ss =>
ss.Length <= 64 ? ss : ss.Substring(0, 64) + "\n" + Pemify(ss.Substring(64));

Expand Down Expand Up @@ -229,12 +234,12 @@ public EnrollmentRequest GetEnrollmentRequest(EnrollmentProductInfo productInfo,
{
if (j < 2)
{
DnsName dns = new DnsName { Id = "custom_encode_dnsName", Value = item };
DnsName dns = new DnsName { Id = DnsConstantName, Value = item };
dnsList.Add(dns);
}
else
{
DnsName dns = new DnsName { Id = "custom_encode_dnsName" + j, Value = item };
DnsName dns = new DnsName { Id = DnsConstantName + j, Value = item };
dnsList.Add(dns);
}
j++;
Expand All @@ -256,12 +261,12 @@ public EnrollmentRequest GetEnrollmentRequest(EnrollmentProductInfo productInfo,
{
if (k < 2)
{
UserPrincipalName up = new UserPrincipalName { Id = "otherNameUPN", Value = item };
UserPrincipalName up = new UserPrincipalName { Id = UpnConstantName, Value = item };
upList.Add(up);
}
else
{
UserPrincipalName up = new UserPrincipalName { Id = "otherNameUPN" + k, Value = item };
UserPrincipalName up = new UserPrincipalName { Id = UpnConstantName + k, Value = item };
upList.Add(up);
}
k++;
Expand All @@ -282,12 +287,12 @@ public EnrollmentRequest GetEnrollmentRequest(EnrollmentProductInfo productInfo,
{
if (k < 2)
{
IpAddress ip = new IpAddress { Id = "san_ipAddress", Value = item };
IpAddress ip = new IpAddress { Id = IpConstantName, Value = item };
ipList.Add(ip);
}
else
{
IpAddress ip = new IpAddress { Id = "san_ipAddress" + k, Value = item };
IpAddress ip = new IpAddress { Id = IpConstantName + k, Value = item };
ipList.Add(ip);
}
k++;
Expand All @@ -308,12 +313,12 @@ public EnrollmentRequest GetEnrollmentRequest(EnrollmentProductInfo productInfo,
{
if (k < 2)
{
Rfc822Name mail = new Rfc822Name { Id = "mail_email", Value = item };
Rfc822Name mail = new Rfc822Name { Id = EmailConstantName, Value = item };
mailList.Add(mail);
}
else
{
Rfc822Name mail = new Rfc822Name { Id = "mail_email" + k, Value = item };
Rfc822Name mail = new Rfc822Name { Id = EmailConstantName + k, Value = item };
mailList.Add(mail);
}
k++;
Expand Down

0 comments on commit ebfe704

Please sign in to comment.