Skip to content

Commit 075ff9d

Browse files
authored
Merge 330cdb9 into 8ba1320
2 parents 8ba1320 + 330cdb9 commit 075ff9d

5 files changed

Lines changed: 39 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ Fix for JSON serialization of revocation
1414
1.1.0
1515
Add support for using the cert upload feature to upload auth certs
1616
Switch to .NET 8
17+
18+
1.1.1
19+
Allow for manual specification of enrollment term length

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ In addition, for the admin account you plan to use, make sure it has the API adm
113113
* **MultiDomain** - This flag lets Keyfactor know if the certificate can contain multiple domain names. Depending on the setting, the SAN entries of the request will change to support Sectigo requirements.
114114
* **Organization** - If the organization name is provided here, the Sectigo gateway will use that organization name in requests instead of whatever is in the O= field in the request subject.
115115
* **Department** - If your Sectigo account is using department-level products, put the appropriate department name here. Previously, this was alternatively supplied in the OU= subject field, which is now deprecated.
116+
* **Lifetime** - OPTIONAL: The term length (in days) to use for enrollment. If not provided, the default is the first value available in the profile definition in your Sectigo account.
116117

117118

118119

integration-manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
{
7979
"name": "Department",
8080
"description": "If your Sectigo account is using department-level products, put the appropriate department name here. Previously, this was alternatively supplied in the OU= subject field, which is now deprecated."
81+
},
82+
{
83+
"name": "Lifetime",
84+
"description": "OPTIONAL: The term length (in days) to use for enrollment. If not provided, the default is the first value available in the profile definition in your Sectigo account."
8185
}
8286
]
8387
}

sectigo-scm-caplugin/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class Config
2727
public const string MULTIDOMAIN = "MultiDomain";
2828
public const string ORGANIZATION = "Organization";
2929
public const string DEPARTMENT = "Department";
30+
public const string LIFETIME = "Lifetime";
3031
}
3132

3233
//headers for API client

sectigo-scm-caplugin/SectigoCAPlugin.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,26 @@ public async Task<EnrollmentResult> Enroll(string csr, string subject, Dictionar
196196
_logger.LogTrace($"Found {enrollmentProfile.name} profile for enroll request");
197197
}
198198

199+
int termLength;
200+
var profileTerms = Task.Run(async () => await GetProfileTerms(int.Parse(productInfo.ProductID))).Result;
201+
if (!string.IsNullOrEmpty(productInfo.ProductParameters[Constants.Config.LIFETIME]))
202+
{
203+
var tempTerm = int.Parse(productInfo.ProductParameters[Constants.Config.LIFETIME]);
204+
if (profileTerms.Contains(tempTerm))
205+
{
206+
termLength = tempTerm;
207+
}
208+
else
209+
{
210+
_logger.LogError($"Specified term length of {tempTerm} does not match available terms for product ID {productInfo.ProductID}. Available terms are {string.Join(",", profileTerms)}");
211+
throw new Exception($"Specified term length of {tempTerm} does not match available terms for product ID {productInfo.ProductID}");
212+
}
213+
}
214+
else
215+
{
216+
termLength = profileTerms[0];
217+
}
218+
199219
int sslId;
200220
string priorSn = string.Empty;
201221
Certificate newCert = null;
@@ -216,7 +236,7 @@ public async Task<EnrollmentResult> Enroll(string csr, string subject, Dictionar
216236
{
217237
csr = csr,
218238
orgId = requestOrgId,
219-
term = Task.Run(async () => await GetProfileTerm(int.Parse(productInfo.ProductID))).Result,
239+
term = termLength,
220240
certType = enrollmentProfile.id,
221241
//External requestor is expected to be an email. Use config to pull the enrollment field or send blank
222242
//sectigo will default to the account (API account) making the request.
@@ -431,6 +451,13 @@ public Dictionary<string, PropertyConfigInfo> GetTemplateParameterAnnotations()
431451
Hidden = false,
432452
DefaultValue = "",
433453
Type = "String"
454+
},
455+
[Constants.Config.LIFETIME] = new PropertyConfigInfo()
456+
{
457+
Comments = "OPTIONAL: The term length (in days) to use for enrollment. If not provided, the default is the first value available in the profile definition in your Sectigo account.",
458+
Hidden = false,
459+
DefaultValue = "",
460+
Type = "String"
434461
}
435462
};
436463
}
@@ -674,11 +701,11 @@ private async Task<Organization> GetOrganizationAsync(string orgName)
674701
return orgList.Organizations.Where(x => x.name.ToLower().Equals(orgName.ToLower())).FirstOrDefault();
675702
}
676703

677-
private async Task<int> GetProfileTerm(int profileId)
704+
private async Task<List<int>> GetProfileTerms(int profileId)
678705
{
679706
var client = SectigoClient.InitializeClient(_config, _certificateResolver);
680707
var profileList = await client.ListSslProfiles();
681-
return profileList.SslProfiles.Where(x => x.id == profileId).FirstOrDefault().terms[0];
708+
return profileList.SslProfiles.Where(x => x.id == profileId).FirstOrDefault().terms.ToList();
682709
}
683710

684711
private async Task<Profile> GetProfile(int profileId)

0 commit comments

Comments
 (0)