Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev 1.2 #34

Open
wants to merge 7 commits into
base: release-1.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@
* Allow organization name to be provided in the template section of the config
# 1.2.0
* Allow for blank CN to be provided
* Fixes for Certificate Authentication
* Fixes for Certificate Authentication
# 1.2.1
* Fix for handling sync of expired records
* Handle null Keyfactor-Requestor
* Properly pass in custom fields to enrollment API
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,4 @@ There are no specific Changes for the GatewayRegistration section. Refer to the
}
```


1 change: 1 addition & 0 deletions src/SectigoCAProxy/API/EnrollRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class CustomField

public string value { get; set; }

[JsonIgnore]
public bool mandatory { get; set; }
}
}
39 changes: 30 additions & 9 deletions src/SectigoCAProxy/SectigoCAProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,32 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
}

var fieldList = Task.Run(async () => await Client.ListCustomFields()).Result;
var mandatoryFields = fieldList.CustomFields?.Where(f => f.mandatory);
var allFields = fieldList.CustomFields?.Select(f => f);

Logger.Debug("Check for mandatory custom fields");
foreach (CustomField reqField in mandatoryFields)
Logger.Debug("Check for custom fields");
List<CustomField> customFields = new List<CustomField>();
foreach (CustomField field in allFields)
{
Logger.Trace($"Checking product parameters for {reqField.name}");
if (!productInfo.ProductParameters.ContainsKey(reqField.name))
Logger.Trace($"Checking product parameters for {field.name}");
if (productInfo.ProductParameters.ContainsKey(field.name) && !string.IsNullOrEmpty(productInfo.ProductParameters[field.name]))
{
Logger.MethodExit(ILogExtensions.MethodLogLevel.Debug);
return new EnrollmentResult { Status = 30, StatusMessage = $"Template {productInfo.ProductID} or Enrollment Fields do not contain a mandatory custom field value for of {reqField.name}" };
var value = productInfo.ProductParameters[field.name];
Logger.Debug($"Found value for custom field {field.name}: {value}");
customFields.Add(new CustomField() { name = field.name, value = value });
}
else
{
if (field.mandatory)
{
Logger.MethodExit(ILogExtensions.MethodLogLevel.Debug);
return new EnrollmentResult { Status = 30, StatusMessage = $"Custom field {field.name} is mandatory, but no value provided by template {productInfo.ProductID} or Enrollment Fields" };
}
else
{
Logger.Debug($"No value found for custom field {field.name}, but it is not mandatory.");
}
}

}
Logger.Debug($"Search for Organization by Name {orgStr}");

Expand Down Expand Up @@ -377,7 +392,11 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
case RequestUtilities.EnrollmentType.New:
case RequestUtilities.EnrollmentType.Reissue:
case RequestUtilities.EnrollmentType.Renew:

string comment = string.Empty;
if (productInfo.ProductParameters.ContainsKey("Keyfactor-Requester"))
{
comment = $"CERTIFICATE_REQUESTOR: {productInfo.ProductParameters["Keyfactor-Requester"]}";
}
EnrollRequest request = new EnrollRequest
{
csr = csr,
Expand All @@ -390,7 +409,8 @@ public override EnrollmentResult Enroll(ICertificateDataReader certificateDataRe
numberServers = 1,
serverType = -1,
subjAltNames = sanList,//,
comments = $"CERTIFICATE_REQUESTOR: {productInfo.ProductParameters["Keyfactor-Requester"]}"//this is how the current gateway passes this data
comments = comment,
customFields = customFields
};

Logger.Debug($"Submit {enrollmentType} request");
Expand Down Expand Up @@ -711,6 +731,7 @@ private static int ConvertToKeyfactorStatus(string status)
case "APPROVED":
case "APPLIED":
case "DOWNLOADED":
case "EXPIRED":
return 20;

case "REQUESTED":
Expand Down
Loading