Skip to content

Commit

Permalink
Merge pull request #7 from Keyfactor/bugfix-domainparsing
Browse files Browse the repository at this point in the history
Fix domain parsing
  • Loading branch information
dgaley authored Oct 20, 2021
2 parents b9f7eb6 + c589b82 commit f7d5231
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Binary file modified README.md.tpl
Binary file not shown.
8 changes: 4 additions & 4 deletions src/GlobalSignCAProxy/Api/GlobalSignErrorIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public static GlobalSignError GetGlobalSignError(int errorCode)
}
private static readonly Dictionary<int, GlobalSignError> ErrorDictionary = new Dictionary<int, GlobalSignError>
{
{ 101, new GlobalSignError { HResult = 0xA0060000, SuccessCode = -1, ErrorCode = -101, ErrorMessage = "Invalid parameter entered.", ErrorDetails = "Invalid parameter entered. Please check that the parameters match the API specification. Please review the specific ErrorMessage returned in the XML response for parameter details and consult the XML Field definitions section of the applicable API document." }},
{ 102, new GlobalSignError { HResult = 0xA0060001, SuccessCode = -1, ErrorCode = -102, ErrorMessage = "Mandatory parameter missing", ErrorDetails = "Mandatory parameter missing. Please check that the parameters match the API specification. Please review the specific ErrorMessage returned in the XML response for parameter details and consult the XML Field definitions section of the applicable API document." }},
{ 103, new GlobalSignError { HResult = 0xA0060002, SuccessCode = -1, ErrorCode = -103, ErrorMessage = "Parameter length check error", ErrorDetails = "Parameter length check error. Please check that the parameters match the API specification. Please review the specific ErrorMessage returned in the XML response for parameter details and consult the XML Field definitions section of the applicable API document." }},
{ 104, new GlobalSignError { HResult = 0xA0060003, SuccessCode = -1, ErrorCode = -104, ErrorMessage = "Parameter format check error.", ErrorDetails = "Parameter format check error. Please check that the parameters match the API specification. Please review the specific ErrorMessage returned in the XML response for parameter details and consult the XML Field definitions section of the applicable API document." }},
{ 101, new GlobalSignError { HResult = 0xA0060000, SuccessCode = -1, ErrorCode = -101, ErrorMessage = "Invalid parameter entered.", ErrorDetails = "Invalid parameter entered. Please check that the parameters match the API specification. Parameter: {0}" }},
{ 102, new GlobalSignError { HResult = 0xA0060001, SuccessCode = -1, ErrorCode = -102, ErrorMessage = "Mandatory parameter missing", ErrorDetails = "Mandatory parameter missing. Please check that the parameters match the API specification. Parameter: {0}" }},
{ 103, new GlobalSignError { HResult = 0xA0060002, SuccessCode = -1, ErrorCode = -103, ErrorMessage = "Parameter length check error", ErrorDetails = "Parameter length check error. Please check that the parameters match the API specification. Parameter: {0}" }},
{ 104, new GlobalSignError { HResult = 0xA0060003, SuccessCode = -1, ErrorCode = -104, ErrorMessage = "Parameter format check error.", ErrorDetails = "Parameter format check error. Please check that the parameters match the API specification. Parameter: {0}" }},
{ 105, new GlobalSignError { HResult = 0xA0060004, SuccessCode = -1, ErrorCode = -105, ErrorMessage = "Invalid parameter combination", ErrorDetails = "Invalid parameter combination. Please that check the parameters match the API specification." }},
{ 300, new GlobalSignError { HResult = 0xA0060005, SuccessCode = -1, ErrorCode = -300, ErrorMessage = "Database Error. Please retry and if the issue persists contact support with detailed information concerning the issue.", ErrorDetails = "Database Error. Please retry and if the issue persists contact support with detailed information concerning the issue." }},
{ 4001, new GlobalSignError { HResult = 0xA0060006, SuccessCode = -1, ErrorCode = -4001, ErrorMessage = "Login failure invalid user ID Login failure.", ErrorDetails = "UserName or Password is incorrect. Please make sure that you have specified the correct UserName and Password." }},
Expand Down
8 changes: 7 additions & 1 deletion src/GlobalSignCAProxy/Client/GlobalSignApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ public EnrollmentResult Enroll(GlobalSignEnrollRequest enrollRequest)
};
}
}
GlobalSignError err = GlobalSignErrorIndex.GetGlobalSignError(int.Parse(response.OrderResponseHeader.Errors[0].ErrorCode));

int errorCode = int.Parse(response.OrderResponseHeader.Errors[0].ErrorCode);
GlobalSignError err = GlobalSignErrorIndex.GetGlobalSignError(errorCode);
if (errorCode <= -101 && errorCode >= -104) // Invalid parameter errors, provide more information
{
err.ErrorDetails = string.Format(err.ErrorDetails, response.OrderResponseHeader.Errors[0].ErrorField);
}
foreach (var e in response.OrderResponseHeader.Errors)
{
Logger.Error($"{e.ErrorCode}|{e.ErrorField}|{e.ErrorMessage}");
Expand Down
9 changes: 4 additions & 5 deletions src/GlobalSignCAProxy/GlobalSignCAProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
}
//get domain ID for enrollment
var commonName = ParseSubject(subject, "CN=");
var months = productInfo.ProductParameters["Lifetime"];
var months = productInfo.ProductParameters["Lifetime"];

//get domain
var domain = apiClient.GetDomains().Where(d => commonName.EndsWith(d.DomainName, StringComparison.OrdinalIgnoreCase)).First();

//parse domain from common name
var cnArray = commonName.Split('.');
var domainValue = $"{cnArray[cnArray.Length - 2]}.{cnArray[cnArray.Length - 1]}";
var domain = apiClient.GetDomains().Where(x => x.DomainName.Equals(domainValue)).FirstOrDefault();

var productType = GlobalSignCertType.AllTypes.Where(x => x.ProductCode.Equals(productInfo.ProductID, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();

Expand Down

0 comments on commit f7d5231

Please sign in to comment.