Skip to content

Commit 1a42e9d

Browse files
authored
Merge c221bcb into 9f5af81
2 parents 9f5af81 + c221bcb commit 1a42e9d

4 files changed

Lines changed: 30 additions & 62 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,5 @@ Switch to .NET 8
1717

1818
1.1.1
1919
Allow for manual specification of enrollment term length
20-
21-
1.1.2
2220
Add Lifetime parameter to allow for manual specification of cert validity
2321
Bugfix - Properly handle syncs of 0 records

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1 align="center" style="border-bottom: none">
2-
Sectigo Certificate Manager Gateway AnyCA Gateway REST Plugin
2+
Sectigo Certificate Manager AnyCA Gateway REST Plugin
33
</h1>
44

55
<p align="center">
@@ -45,10 +45,10 @@ The Sectigo AnyCA Gateway REST plugin extends the capabilities of the Sectigo Ce
4545

4646
## Compatibility
4747

48-
The Sectigo Certificate Manager Gateway AnyCA Gateway REST plugin is compatible with the Keyfactor AnyCA Gateway REST 24.2.0 and later.
48+
The Sectigo Certificate Manager AnyCA Gateway REST plugin is compatible with the Keyfactor AnyCA Gateway REST 24.2.0 and later.
4949

5050
## Support
51-
The Sectigo Certificate Manager Gateway AnyCA Gateway REST plugin is supported by Keyfactor for Keyfactor customers. If you have a support issue, please open a support ticket with your Keyfactor representative. If you have a support issue, please open a support ticket via the Keyfactor Support Portal at https://support.keyfactor.com.
51+
The Sectigo Certificate Manager AnyCA Gateway REST plugin is supported by Keyfactor for Keyfactor customers. If you have a support issue, please open a support ticket with your Keyfactor representative. If you have a support issue, please open a support ticket via the Keyfactor Support Portal at https://support.keyfactor.com.
5252

5353
> To report a problem or suggest a new feature, use the **[Issues](../../issues)** tab. If you want to contribute actual bug fixes or proposed enhancements, use the **[Pull requests](../../pulls)** tab.
5454
@@ -61,7 +61,7 @@ In addition, for the admin account you plan to use, make sure it has the API adm
6161

6262
1. Install the AnyCA Gateway REST per the [official Keyfactor documentation](https://software.keyfactor.com/Guides/AnyCAGatewayREST/Content/AnyCAGatewayREST/InstallIntroduction.htm).
6363

64-
2. On the server hosting the AnyCA Gateway REST, download and unzip the latest [Sectigo Certificate Manager Gateway AnyCA Gateway REST plugin](https://github.com/Keyfactor/sectigo-scm-caplugin/releases/latest) from GitHub.
64+
2. On the server hosting the AnyCA Gateway REST, download and unzip the latest [Sectigo Certificate Manager AnyCA Gateway REST plugin](https://github.com/Keyfactor/sectigo-scm-caplugin/releases/latest) from GitHub.
6565

6666
3. Copy the unzipped directory (usually called `net6.0` or `net8.0`) to the Extensions directory:
6767

@@ -72,11 +72,11 @@ In addition, for the admin account you plan to use, make sure it has the API adm
7272
Program Files\Keyfactor\AnyCA Gateway\AnyGatewayREST\net8.0\Extensions
7373
```
7474

75-
> The directory containing the Sectigo Certificate Manager Gateway AnyCA Gateway REST plugin DLLs (`net6.0` or `net8.0`) can be named anything, as long as it is unique within the `Extensions` directory.
75+
> The directory containing the Sectigo Certificate Manager AnyCA Gateway REST plugin DLLs (`net6.0` or `net8.0`) can be named anything, as long as it is unique within the `Extensions` directory.
7676

7777
4. Restart the AnyCA Gateway REST service.
7878

79-
5. Navigate to the AnyCA Gateway REST portal and verify that the Gateway recognizes the Sectigo Certificate Manager Gateway plugin by hovering over the ⓘ symbol to the right of the Gateway on the top left of the portal.
79+
5. Navigate to the AnyCA Gateway REST portal and verify that the Gateway recognizes the Sectigo Certificate Manager plugin by hovering over the ⓘ symbol to the right of the Gateway on the top left of the portal.
8080

8181
## Configuration
8282

sectigo-scm-caplugin/Client/SectigoClient.cs

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using Newtonsoft.Json;
99
using Newtonsoft.Json.Linq;
1010

11+
using Org.BouncyCastle.Asn1.Ocsp;
12+
1113
using System;
1214
using System.Collections.Concurrent;
1315
using System.Collections.Generic;
@@ -19,6 +21,8 @@
1921
using System.Threading;
2022
using System.Threading.Tasks;
2123

24+
using Error = Keyfactor.Extensions.CAPlugin.Sectigo.API.Error;
25+
2226
namespace Keyfactor.Extensions.CAPlugin.Sectigo.Client
2327
{
2428
public class SectigoClient
@@ -34,7 +38,9 @@ public SectigoClient(HttpClient client)
3438

3539
public async Task<Certificate> GetCertificate(int sslId)
3640
{
37-
var response = await RestClient.GetAsync($"api/ssl/v1/{sslId}");
41+
string url = $"api/ssl/v1/{sslId}";
42+
Logger.LogTrace($"API Request: GET {url}");
43+
var response = await RestClient.GetAsync(url);
3844
return await ProcessResponse<Certificate>(response);
3945
}
4046

@@ -139,7 +145,7 @@ public async Task CertificateListProducer(BlockingCollection<Certificate> certs,
139145
public async Task<List<Certificate>> PageCertificates(int position = 0, int size = 25, string filter = "")
140146
{
141147
string filterQueryString = string.IsNullOrEmpty(filter) ? string.Empty : $"&{filter}";
142-
Logger.LogTrace($"API Request: api/ssl/v1?position={position}&size={size}{filterQueryString}".TrimEnd());
148+
Logger.LogTrace($"API Request: GET api/ssl/v1?position={position}&size={size}{filterQueryString}".TrimEnd());
143149
var response = await RestClient.GetAsync($"api/ssl/v1?position={position}&size={size}{filterQueryString}".TrimEnd());
144150
return await ProcessResponse<List<Certificate>>(response);
145151
}
@@ -151,37 +157,26 @@ public async Task<bool> RevokeSslCertificateById(int sslId, int revcode, string
151157
reasonCode = revcode,
152158
reason = revreason
153159
};
160+
Logger.LogTrace($"API Request: POST api/ssl/v1/revoke/{sslId}\nParameters: {JsonConvert.SerializeObject(data, Formatting.Indented)}");
154161
var response = await RestClient.PostAsJsonAsync($"api/ssl/v1/revoke/{sslId}", data);
155-
if (response.IsSuccessStatusCode)
156-
{
157-
return true;
158-
}
159-
var failedResp = ProcessResponse<RevocationResponse>(response).Result;
160-
return failedResp.IsSuccess;//Should throw an exception with error message from API
162+
var resp = ProcessResponse<RevocationResponse>(response).Result;
163+
164+
return true;//Should throw an exception with error message from API, should only hit this if success
161165
}
162166

163167
public async Task<ListOrganizationsResponse> ListOrganizations()
164168
{
169+
Logger.LogTrace($"API Request: GET api/organization/v1");
165170
var response = await RestClient.GetAsync("api/organization/v1");
166-
if (response.IsSuccessStatusCode)
167-
{
168-
string responseContent = await response.Content.ReadAsStringAsync();
169-
Logger.LogTrace($"Raw Response: {responseContent}");
170-
}
171171
var orgsResponse = await ProcessResponse<List<Organization>>(response);
172172

173173
return new ListOrganizationsResponse { Organizations = orgsResponse };
174174
}
175175

176176
public async Task<OrganizationDetailsResponse> GetOrganizationDetails(int orgId)
177177
{
178+
Logger.LogTrace($"API Request: GET api/organization/v1/{orgId}");
178179
var response = await RestClient.GetAsync($"api/organization/v1/{orgId}");
179-
if (response.IsSuccessStatusCode)
180-
{
181-
string responseContent = await response.Content.ReadAsStringAsync();
182-
Logger.LogTrace($"Raw Response: {responseContent}");
183-
}
184-
185180
var orgDetailsResponse = await ProcessResponse<OrganizationDetailsResponse>(response);
186181
return orgDetailsResponse;
187182
}
@@ -203,6 +198,7 @@ public async Task<ListPersonsResponse> ListPersons(int orgId)
203198

204199
public async Task<ListCustomFieldsResponse> ListCustomFields()
205200
{
201+
Logger.LogTrace($"API Request: GET api/ssl/v1/customFields");
206202
var response = await RestClient.GetAsync("api/ssl/v1/customFields");
207203
return new ListCustomFieldsResponse { CustomFields = await ProcessResponse<List<CustomField>>(response) };
208204
}
@@ -214,13 +210,14 @@ public async Task<ListSslProfilesResponse> ListSslProfiles(int? orgId = null)
214210
{
215211
urlSuffix = $"?organizationId={orgId}";
216212
}
217-
213+
Logger.LogTrace($"API Request: GET api/ssl/v1/types{urlSuffix}");
218214
var response = await RestClient.GetAsync($"api/ssl/v1/types{urlSuffix}");
219215
return new ListSslProfilesResponse { SslProfiles = await ProcessResponse<List<Profile>>(response) };
220216
}
221217

222218
public async Task<List<Person>> PagePersons(int orgId, int position = 0, int size = 25)
223219
{
220+
Logger.LogTrace($"API Request: GET api/person/v1?position={position}&size={size}&organizationId={orgId}");
224221
var response = await RestClient.GetAsync($"api/person/v1?position={position}&size={size}&organizationId={orgId}");
225222
return await ProcessResponse<List<Person>>(response);
226223
}
@@ -229,6 +226,7 @@ public async Task<int> Enroll(EnrollRequest request)
229226
{
230227
try
231228
{
229+
Logger.LogTrace($"API Request: POST api/ssl/v1/enroll\nParameters: {JsonConvert.SerializeObject(request, Formatting.Indented)}");
232230
var response = await RestClient.PostAsJsonAsync("api/ssl/v1/enroll", request);
233231
var enrollResponse = await ProcessResponse<EnrollResponse>(response);
234232

@@ -248,35 +246,14 @@ public async Task<int> Enroll(EnrollRequest request)
248246
}
249247
}
250248

251-
public async Task<int> Renew(int sslId)
252-
{
253-
try
254-
{
255-
var response = await RestClient.PostAsJsonAsync($"api/ssl/v1/renewById/{sslId}", "");
256-
var renewResponse = await ProcessResponse<EnrollResponse>(response);
257-
258-
return renewResponse.sslId;
259-
}
260-
catch (InvalidOperationException invalidOp)
261-
{
262-
throw new Exception($"Invalid Operation. {invalidOp.Message}|{invalidOp.StackTrace}");
263-
}
264-
catch (HttpRequestException httpEx)
265-
{
266-
throw new Exception($"HttpRequestException. {httpEx.Message}|{httpEx.StackTrace}");
267-
}
268-
catch (Exception)
269-
{
270-
throw;
271-
}
272-
}
273-
274249
public async Task<X509Certificate2> PickupCertificate(int sslId, string subject)
275250
{
251+
Logger.LogTrace($"API Request: GET api/ssl/v1/collect/{sslId}/x509C0");
276252
var response = await RestClient.GetAsync($"api/ssl/v1/collect/{sslId}/x509CO");
277-
253+
278254
if (response.IsSuccessStatusCode && response.Content.Headers.ContentLength > 0)
279255
{
256+
Logger.LogTrace($"Raw response: {response.Content.ReadAsStringAsync()}");
280257
string pemChain = await response.Content.ReadAsStringAsync();
281258

282259
string[] splitChain = pemChain.Replace("\r\n", string.Empty).Split(new string[] { "-----" }, StringSplitOptions.RemoveEmptyEntries);
@@ -287,24 +264,19 @@ public async Task<X509Certificate2> PickupCertificate(int sslId, string subject)
287264
//return new X509Certificate2();
288265
}
289266

290-
public async Task Reissue(ReissueRequest request, int sslId)
291-
{
292-
var response = await RestClient.PostAsJsonAsync($"api/ssl/v1/replace/{sslId}", request);
293-
response.EnsureSuccessStatusCode();
294-
}
295-
296267
#region Static Methods
297268

298269
private static async Task<T> ProcessResponse<T>(HttpResponseMessage response)
299270
{
271+
string responseContent = await response.Content.ReadAsStringAsync();
272+
Logger.LogDebug($"Raw API response: {responseContent}");
300273
if (response.IsSuccessStatusCode)
301274
{
302-
string responseContent = await response.Content.ReadAsStringAsync();
303275
return JsonConvert.DeserializeObject<T>(responseContent);
304276
}
305277
else
306278
{
307-
var error = JsonConvert.DeserializeObject<Error>(await response.Content.ReadAsStringAsync());
279+
var error = JsonConvert.DeserializeObject<Error>(responseContent);
308280
throw new Exception($"{error.Code} | {error.Description}");
309281
}
310282
}

sectigo-scm-caplugin/SectigoCAPlugin.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,6 @@ public async Task<EnrollmentResult> Enroll(string csr, string subject, Dictionar
249249
};
250250

251251
_logger.LogDebug($"Submit {enrollmentType} request");
252-
var jsonReq = JsonConvert.SerializeObject(request, Formatting.Indented);
253-
_logger.LogDebug($"Request object: {jsonReq}");
254252
sslId = Task.Run(async () => await client.Enroll(request)).Result;
255253
newCert = Task.Run(async () => await client.GetCertificate(sslId)).Result;
256254
_logger.LogDebug($"Enrolled for Certificate {newCert.CommonName} (ID: {newCert.Id}) | Status: {newCert.status}. Attempt to Pickup Certificate.");

0 commit comments

Comments
 (0)