Skip to content

Commit 7315922

Browse files
committed
allow manual lifetime specification
1 parent 8ba1320 commit 7315922

3 files changed

Lines changed: 34 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

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)