Skip to content

Commit 38fe3ec

Browse files
authored
Merge bb67d56 into 331bbe6
2 parents 331bbe6 + bb67d56 commit 38fe3ec

2 files changed

Lines changed: 48 additions & 41 deletions

File tree

src/GlobalSignCAProxy/Client/GlobalSignApiClient.cs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -195,53 +195,50 @@ public CAConnectorCertificate PickupCertificateById(string caRequestId)
195195
}
196196
};
197197

198-
int retryCounter = 0;
199-
while (retryCounter <= Config.PickupRetries)
198+
using (var service = this.QueryService)
200199
{
201-
using (var service = this.QueryService)
202-
{
203-
var response = service.GetOrderByOrderID(request);
200+
var response = service.GetOrderByOrderID(request);
204201

205-
if (response.OrderResponseHeader.SuccessCode == 0)
202+
if (response.OrderResponseHeader.SuccessCode == 0)
203+
{
204+
Logger.Debug($"Order with order ID {caRequestId} successfully picked up");
205+
GlobalSignOrderStatus orderStatus = (GlobalSignOrderStatus)Enum.Parse(typeof(GlobalSignOrderStatus), response.OrderDetail.CertificateInfo.CertificateStatus);
206+
if (orderStatus == GlobalSignOrderStatus.Issued)
206207
{
207-
Logger.Debug($"Order with order ID {caRequestId} successfully picked up");
208-
GlobalSignOrderStatus orderStatus = (GlobalSignOrderStatus)Enum.Parse(typeof(GlobalSignOrderStatus), response.OrderDetail.CertificateInfo.CertificateStatus);
209-
if (orderStatus == GlobalSignOrderStatus.Issued)
208+
DateTime? orderDate = DateTime.TryParse(response?.OrderDetail?.OrderInfo?.OrderDate, out DateTime orderDateTime) ? orderDateTime : (DateTime?)null;
209+
DateTime? completeDate = DateTime.TryParse(response?.OrderDetail?.OrderInfo?.OrderCompleteDate, out DateTime orderCompleteDate) ? orderCompleteDate : (DateTime?)null;
210+
DateTime? deactivateDate = DateTime.TryParse(response?.OrderDetail?.OrderInfo?.OrderDeactivatedDate, out DateTime orderDeactivateDate) ? orderDeactivateDate : (DateTime?)null;
211+
Logger.MethodExit(ILogExtensions.MethodLogLevel.Debug);
212+
return new CAConnectorCertificate()
210213
{
211-
DateTime? orderDate = DateTime.TryParse(response?.OrderDetail?.OrderInfo?.OrderDate, out DateTime orderDateTime) ? orderDateTime : (DateTime?)null;
212-
DateTime? completeDate = DateTime.TryParse(response?.OrderDetail?.OrderInfo?.OrderCompleteDate, out DateTime orderCompleteDate) ? orderCompleteDate : (DateTime?)null;
213-
DateTime? deactivateDate = DateTime.TryParse(response?.OrderDetail?.OrderInfo?.OrderDeactivatedDate, out DateTime orderDeactivateDate) ? orderDeactivateDate : (DateTime?)null;
214-
Logger.MethodExit(ILogExtensions.MethodLogLevel.Debug);
215-
return new CAConnectorCertificate()
216-
{
217-
CARequestID = caRequestId,
218-
ProductID = response.OrderDetail.OrderInfo.ProductCode,
219-
SubmissionDate = orderDate,
220-
ResolutionDate = completeDate,
221-
Status = OrderStatus.ConvertToKeyfactorStatus(orderStatus),
222-
CSR = response.OrderDetail.Fulfillment.OriginalCSR,
223-
Certificate = response.OrderDetail.Fulfillment.ServerCertificate.X509Cert,
224-
RevocationReason = 0,
225-
RevocationDate = orderStatus == GlobalSignOrderStatus.Revoked ? deactivateDate : new DateTime?()
226-
};
227-
}
228-
}
229-
retryCounter++;
230-
string logMsg = $"Pickup certificate failed for order ID {caRequestId}. Attempt {retryCounter} of {Config.PickupRetries}.";
231-
if (retryCounter < Config.PickupRetries)
232-
{
233-
logMsg = logMsg + " Retrying...";
214+
CARequestID = caRequestId,
215+
ProductID = response.OrderDetail.OrderInfo.ProductCode,
216+
SubmissionDate = orderDate,
217+
ResolutionDate = completeDate,
218+
Status = OrderStatus.ConvertToKeyfactorStatus(orderStatus),
219+
CSR = response.OrderDetail.Fulfillment.OriginalCSR,
220+
Certificate = response.OrderDetail.Fulfillment.ServerCertificate.X509Cert,
221+
RevocationReason = 0,
222+
RevocationDate = orderStatus == GlobalSignOrderStatus.Revoked ? deactivateDate : new DateTime?()
223+
};
234224
}
235-
Logger.Debug(logMsg);
236-
Thread.Sleep(Config.PickupDelay * 1000);//convert seconds to ms for delay.
237225
}
226+
227+
string logMsg = $"Certificate for order {caRequestId} was not immediately available. Once issued, it should be picked up by the next gateway sync.";
228+
229+
Logger.Info(logMsg);
238230
}
239231

232+
240233
var gsError = GlobalSignErrorIndex.GetGlobalSignError(-9916);
241234
string errorMsg = "Unable to pickup certificate during configured pickup window. Check for required approvals in GlobalSign portal. This can also be caused by a delay with GlobalSign, in which case the certificate will get picked up by a future sync";
242235
Logger.Error(errorMsg);
243236
Logger.Error(gsError.DetailedMessage);
244-
throw new UnsuccessfulRequestException(errorMsg, gsError.HResult);
237+
return new CAConnectorCertificate()
238+
{
239+
CARequestID = caRequestId,
240+
Status = 13 //ExternalValidation
241+
};
245242
}
246243

247244
public List<DomainDetail> GetDomains()
@@ -419,6 +416,16 @@ public EnrollmentResult Reissue(GlobalSignReissueRequest reissueRequest, string
419416
{
420417
Logger.Debug($"Reissue request successfully submitted");
421418
var pickupResponse = PickupCertificateById(response.OrderID);
419+
420+
if (pickupResponse.Status == 13)
421+
{
422+
return new EnrollmentResult
423+
{
424+
CARequestID = response.OrderID,
425+
Status = (int)CSS.PKI.PKIConstants.Microsoft.RequestDisposition.EXTERNAL_VALIDATION
426+
};
427+
}
428+
422429
var cert = CertificateConverterFactory.FromPEM(pickupResponse.Certificate).ToX509Certificate2();
423430

424431
if (pickupResponse.Status == 20 || (cert.SerialNumber != priorSn))

src/GlobalSignCAProxy/GlobalSignCAProxy.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
151151
|| commonName.EndsWith($".{d.DomainName}", StringComparison.OrdinalIgnoreCase)).ToList();
152152
}
153153

154-
if (matchedDomains == null || matchedDomains.Count == 0)
155-
{
156-
throw new Exception("Unable to determine GlobalSign domain");
157-
}
158-
159154
if (matchedDomains.Count == 1)
160155
{
161156
domain = matchedDomains[0];
@@ -175,6 +170,10 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
175170
throw new Exception($"No domain matching common name {commonName} has provided MSSLProfileID of {profID}. Check configuration.");
176171
}
177172
}
173+
else
174+
{
175+
throw new Exception("Unable to determine GlobalSign domain, and no MSSLProfileID provided.");
176+
}
178177
}
179178

180179
Logger.Debug($"Domain info:\nDomain Name: {domain?.DomainName}\nMsslDomainId: {domain?.DomainID}\nMsslProfileId: {domain?.MSSLProfileID}");
@@ -478,4 +477,5 @@ private static string ParseSubject(string subject, string rdn)
478477

479478
#endregion Private Methods
480479
}
481-
}
480+
481+
}

0 commit comments

Comments
 (0)