|
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 |
|
@@ -116,7 +134,7 @@ public DomainControlValidation GetDomainControlValidation(string methodType, str |
116 | 134 | } |
117 | 135 |
|
118 | 136 | public RegistrationRequest GetRegistrationRequest(EnrollmentProductInfo productInfo, string csr, |
119 | | - Dictionary<string, string[]> sans) |
| 137 | + Dictionary<string, string[]> sans, List<GetCustomField> customFields) |
120 | 138 | { |
121 | 139 | //var cert = "-----BEGIN CERTIFICATE REQUEST-----\r\n"; |
122 | 140 | var cert = Pemify(csr); |
@@ -144,7 +162,7 @@ public RegistrationRequest GetRegistrationRequest(EnrollmentProductInfo productI |
144 | 162 | OrganizationContact = productInfo.ProductParameters["Organization Contact"], |
145 | 163 | BusinessUnit = productInfo.ProductParameters["Business Unit"], |
146 | 164 | ShowPrice = true, //User should not have to fill this out |
147 | | - CustomFields = GetCustomFields(productInfo), |
| 165 | + CustomFields = GetCustomFields(productInfo, customFields), |
148 | 166 | SubjectAlternativeNames = certificateType == "2" ? GetSubjectAlternativeNames(productInfo, sans) : null, |
149 | 167 | EvCertificateDetails = certificateType == "3" ? GetEvCertificateDetails(productInfo) : null |
150 | 168 | }; |
@@ -190,7 +208,7 @@ public Notifications GetNotifications(EnrollmentProductInfo productInfo) |
190 | 208 | } |
191 | 209 |
|
192 | 210 | public RenewalRequest GetRenewalRequest(EnrollmentProductInfo productInfo, string uUId, string csr, |
193 | | - Dictionary<string, string[]> sans) |
| 211 | + Dictionary<string, string[]> sans, List<GetCustomField> customFields) |
194 | 212 | { |
195 | 213 | //var cert = "-----BEGIN CERTIFICATE REQUEST-----\r\n"; |
196 | 214 | var cert = Pemify(csr); |
@@ -219,7 +237,7 @@ public RenewalRequest GetRenewalRequest(EnrollmentProductInfo productInfo, strin |
219 | 237 | BusinessUnit = productInfo.ProductParameters["Business Unit"], |
220 | 238 | ShowPrice = true, |
221 | 239 | SubjectAlternativeNames = certificateType == "2" ? GetSubjectAlternativeNames(productInfo, sans) : null, |
222 | | - CustomFields = GetCustomFields(productInfo), |
| 240 | + CustomFields = GetCustomFields(productInfo, customFields), |
223 | 241 | EvCertificateDetails = certificateType == "3" ? GetEvCertificateDetails(productInfo) : null |
224 | 242 | }; |
225 | 243 | } |
@@ -248,7 +266,7 @@ private List<SubjectAlternativeName> GetSubjectAlternativeNames(EnrollmentProduc |
248 | 266 | } |
249 | 267 |
|
250 | 268 | public ReissueRequest GetReissueRequest(EnrollmentProductInfo productInfo, string uUId, string csr, |
251 | | - Dictionary<string, string[]> sans) |
| 269 | + Dictionary<string, string[]> sans, List<GetCustomField> customFields) |
252 | 270 | { |
253 | 271 | //var cert = "-----BEGIN CERTIFICATE REQUEST-----\r\n"; |
254 | 272 | var cert = Pemify(csr); |
@@ -277,7 +295,7 @@ public ReissueRequest GetReissueRequest(EnrollmentProductInfo productInfo, strin |
277 | 295 | BusinessUnit = productInfo.ProductParameters["Business Unit"], |
278 | 296 | ShowPrice = true, |
279 | 297 | SubjectAlternativeNames = certificateType == "2" ? GetSubjectAlternativeNames(productInfo, sans) : null, |
280 | | - CustomFields = GetCustomFields(productInfo), |
| 298 | + CustomFields = GetCustomFields(productInfo, customFields), |
281 | 299 | EvCertificateDetails = certificateType == "3" ? GetEvCertificateDetails(productInfo) : null |
282 | 300 | }; |
283 | 301 | } |
|
0 commit comments