|
12 | 12 | using Keyfactor.PKI; |
13 | 13 | using Keyfactor.PKI.Enums.EJBCA; |
14 | 14 |
|
| 15 | +using Org.BouncyCastle.Bcpg; |
| 16 | + |
15 | 17 | namespace Keyfactor.Extensions.CAPlugin.CSCGlobal; |
16 | 18 |
|
17 | 19 | public class RequestManager |
18 | 20 | { |
19 | 21 | public static Func<string, string> Pemify = ss => |
20 | 22 | ss.Length <= 64 ? ss : ss.Substring(0, 64) + "\n" + Pemify(ss.Substring(64)); |
21 | 23 |
|
22 | | - private List<CustomField> GetCustomFields(EnrollmentProductInfo productInfo) |
| 24 | + private List<CustomField> GetCustomFields(EnrollmentProductInfo productInfo, List<GetCustomField> customFields) |
23 | 25 | { |
24 | 26 | var customFieldList = new List<CustomField>(); |
| 27 | + foreach (var field in customFields) |
| 28 | + { |
| 29 | + if (productInfo.ProductParameters.ContainsKey(field.Label)) |
| 30 | + { |
| 31 | + var newField = new CustomField |
| 32 | + { |
| 33 | + Name = field.Label, |
| 34 | + Value = productInfo.ProductParameters[field.Label] |
| 35 | + }; |
| 36 | + customFieldList.Add(newField); |
| 37 | + } |
| 38 | + else if (field.Mandatory) |
| 39 | + { |
| 40 | + throw new Exception($"Custom field {field.Label} is marked as mandatory, but was not supplied in the request."); |
| 41 | + } |
| 42 | + } |
25 | 43 | return customFieldList; |
26 | 44 | } |
27 | 45 |
|
@@ -55,12 +73,22 @@ public EnrollmentResult |
55 | 73 | StatusMessage = registrationResponse.RegistrationError.Description |
56 | 74 | }; |
57 | 75 |
|
58 | | - return new EnrollmentResult |
| 76 | + Dictionary<string, string> cnames = new Dictionary<string, string>(); |
| 77 | + if (registrationResponse.Result.DcvDetails != null && registrationResponse.Result.DcvDetails.Count > 0) |
| 78 | + { |
| 79 | + foreach (var dcv in registrationResponse.Result.DcvDetails) |
| 80 | + { |
| 81 | + cnames.Add(dcv.CName.Name, dcv.CName.Value); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + return new EnrollmentResult |
59 | 86 | { |
60 | 87 | Status = (int)EndEntityStatus.EXTERNALVALIDATION, //success |
61 | 88 | CARequestID = registrationResponse.Result.Status.Uuid, |
62 | 89 | StatusMessage = |
63 | | - $"Order Successfully Created With Order Number {registrationResponse.Result.CommonName}" |
| 90 | + $"Order Successfully Created With Order Number {registrationResponse.Result.CommonName}", |
| 91 | + EnrollmentContext = (cnames.Count > 0) ? cnames : null |
64 | 92 | }; |
65 | 93 | } |
66 | 94 |
|
@@ -116,7 +144,7 @@ public DomainControlValidation GetDomainControlValidation(string methodType, str |
116 | 144 | } |
117 | 145 |
|
118 | 146 | public RegistrationRequest GetRegistrationRequest(EnrollmentProductInfo productInfo, string csr, |
119 | | - Dictionary<string, string[]> sans) |
| 147 | + Dictionary<string, string[]> sans, List<GetCustomField> customFields) |
120 | 148 | { |
121 | 149 | //var cert = "-----BEGIN CERTIFICATE REQUEST-----\r\n"; |
122 | 150 | var cert = Pemify(csr); |
@@ -144,7 +172,7 @@ public RegistrationRequest GetRegistrationRequest(EnrollmentProductInfo productI |
144 | 172 | OrganizationContact = productInfo.ProductParameters["Organization Contact"], |
145 | 173 | BusinessUnit = productInfo.ProductParameters["Business Unit"], |
146 | 174 | ShowPrice = true, //User should not have to fill this out |
147 | | - CustomFields = GetCustomFields(productInfo), |
| 175 | + CustomFields = GetCustomFields(productInfo, customFields), |
148 | 176 | SubjectAlternativeNames = certificateType == "2" ? GetSubjectAlternativeNames(productInfo, sans) : null, |
149 | 177 | EvCertificateDetails = certificateType == "3" ? GetEvCertificateDetails(productInfo) : null |
150 | 178 | }; |
@@ -190,7 +218,7 @@ public Notifications GetNotifications(EnrollmentProductInfo productInfo) |
190 | 218 | } |
191 | 219 |
|
192 | 220 | public RenewalRequest GetRenewalRequest(EnrollmentProductInfo productInfo, string uUId, string csr, |
193 | | - Dictionary<string, string[]> sans) |
| 221 | + Dictionary<string, string[]> sans, List<GetCustomField> customFields) |
194 | 222 | { |
195 | 223 | //var cert = "-----BEGIN CERTIFICATE REQUEST-----\r\n"; |
196 | 224 | var cert = Pemify(csr); |
@@ -219,7 +247,7 @@ public RenewalRequest GetRenewalRequest(EnrollmentProductInfo productInfo, strin |
219 | 247 | BusinessUnit = productInfo.ProductParameters["Business Unit"], |
220 | 248 | ShowPrice = true, |
221 | 249 | SubjectAlternativeNames = certificateType == "2" ? GetSubjectAlternativeNames(productInfo, sans) : null, |
222 | | - CustomFields = GetCustomFields(productInfo), |
| 250 | + CustomFields = GetCustomFields(productInfo, customFields), |
223 | 251 | EvCertificateDetails = certificateType == "3" ? GetEvCertificateDetails(productInfo) : null |
224 | 252 | }; |
225 | 253 | } |
@@ -248,7 +276,7 @@ private List<SubjectAlternativeName> GetSubjectAlternativeNames(EnrollmentProduc |
248 | 276 | } |
249 | 277 |
|
250 | 278 | public ReissueRequest GetReissueRequest(EnrollmentProductInfo productInfo, string uUId, string csr, |
251 | | - Dictionary<string, string[]> sans) |
| 279 | + Dictionary<string, string[]> sans, List<GetCustomField> customFields) |
252 | 280 | { |
253 | 281 | //var cert = "-----BEGIN CERTIFICATE REQUEST-----\r\n"; |
254 | 282 | var cert = Pemify(csr); |
@@ -277,7 +305,7 @@ public ReissueRequest GetReissueRequest(EnrollmentProductInfo productInfo, strin |
277 | 305 | BusinessUnit = productInfo.ProductParameters["Business Unit"], |
278 | 306 | ShowPrice = true, |
279 | 307 | SubjectAlternativeNames = certificateType == "2" ? GetSubjectAlternativeNames(productInfo, sans) : null, |
280 | | - CustomFields = GetCustomFields(productInfo), |
| 308 | + CustomFields = GetCustomFields(productInfo, customFields), |
281 | 309 | EvCertificateDetails = certificateType == "3" ? GetEvCertificateDetails(productInfo) : null |
282 | 310 | }; |
283 | 311 | } |
|
0 commit comments