Skip to content

Commit ee3ee82

Browse files
authored
Merge pull request #145 from Keyfactor/64674-Remove_Old_Certs_On_Renewal
64674 remove old certs on renewal
2 parents 632a51c + 5c593e9 commit ee3ee82

File tree

7 files changed

+87
-36
lines changed

7 files changed

+87
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
2.6.3
22
* Fixed reenrollment job when RDN Components contained escaped commas
3+
* Updated renewal job for IIS Certs to delete the old cert if not bound or used by other web sites.
34

45
2.6.2
56
* Fixed error when attempting to connect to remote computer using UO service account

IISU/ImplementedStoreTypes/WinIIS/Inventory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public JobResult ProcessJob(InventoryJobConfiguration jobConfiguration, SubmitIn
9595
{
9696
Result = OrchestratorJobStatusJobResult.Success,
9797
JobHistoryId = jobConfiguration.JobHistoryId,
98-
FailureMessage = ""
98+
FailureMessage = $"Inventory completed returning {inventoryItems.Count} Items."
9999
};
100100
}
101101

IISU/ImplementedStoreTypes/WinIIS/Management.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System;
1717
using System.Collections.Generic;
1818
using System.Collections.ObjectModel;
19+
using System.Linq;
1920
using System.Management.Automation;
2021
using Keyfactor.Extensions.Orchestrator.WindowsCertStore.Models;
2122
using Keyfactor.Logging;
@@ -89,6 +90,7 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
8990
string protocol = jobProperties?.WinRmProtocol;
9091
string port = jobProperties?.WinRmPort;
9192
bool includePortInSPN = (bool)jobProperties?.SpnPortFlag;
93+
string alias = config.JobCertificate.Alias.Split(':').FirstOrDefault() ?? string.Empty; // Thumbprint is first part of the alias
9294

9395
_psHelper = new(protocol, port, includePortInSPN, _clientMachineName, serverUserName, serverPassword);
9496

@@ -171,6 +173,14 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
171173
psResult = OrchestratorJobStatusJobResult.Unknown;
172174
}
173175

176+
// Only is the binding returns successful, check of original cert is still bound to any site, if not remove it from the store
177+
if (psResult == OrchestratorJobStatusJobResult.Success && !string.IsNullOrEmpty(alias))
178+
{
179+
_logger.LogTrace("Attempting to remove original certificate from store if it is no longer bound to any site.");
180+
RemoveIISCertificate(alias);
181+
_logger.LogTrace("Returned from removing cert if not used.");
182+
}
183+
174184
complete = new JobResult
175185
{
176186
Result = psResult,

IISU/PowerShellScripts/WinCertScripts.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ function Remove-KFIISCertificateIfUnused {
818818

819819
if ($bindings.Count -gt 0) {
820820
Write-Warning "The certificate with thumbprint $thumbprint is still used by the following bindings:"
821-
$bindings | Format-Table -AutoSize
821+
$bindings | Format-Table -AutoSize | Out-String | Write-Warning
822822
return
823823
}
824824

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ The Windows Certificate Universal Orchestrator extension implements 3 Certificat
8282
This integration is compatible with Keyfactor Universal Orchestrator version 10.1 and later.
8383

8484
## Support
85-
The Windows Certificate Universal Orchestrator extension If you have a support issue, please open a support ticket by either contacting your Keyfactor representative or via the Keyfactor Support Portal at https://support.keyfactor.com.
85+
The Windows Certificate Universal Orchestrator extension is supported by Keyfactor. If you require support for any issues or have feature request, please open a support ticket by either contacting your Keyfactor representative or via the Keyfactor Support Portal at https://support.keyfactor.com.
8686

87-
> 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.
87+
> If you want to contribute bug fixes or additional enhancements, use the **[Pull requests](../../pulls)** tab.
8888
8989
## Requirements & Prerequisites
9090

@@ -135,6 +135,26 @@ For customers wishing to use something other than the local administrator accoun
135135
- Access any Cryptographic Service Provider (CSP) referenced in re-enrollment jobs.
136136
- Read and Write values in the registry (HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server) when performing SQL Server certificate binding.
137137

138+
### Using Crypto Service Providers (CSP)
139+
When adding or reenrolling certificates, you may specify an optional CSP to be used when generating and storing the private keys. This value would typically be specified when leveraging a Hardware Security Module (HSM). The specified cryptographic provider must be available on the target server being managed.
140+
141+
The list of installed cryptographic providers can be obtained by running the PowerShell command on the target server:
142+
143+
certutil -csplist
144+
145+
When performing a ReEnrollment or On Device Key Generation (ODKG) job, if no CSP is specified, a default value of 'Microsoft Strong Cryptographic Provider' will be used.
146+
147+
When performing an Add job, if no CSP is specified, the machine's default CSP will be used, in most cases this could be the 'Microsoft Enhanced Cryptographic Provider v1.0' provider.
148+
149+
Each CSP only supports certain key types and algorithms.
150+
151+
Below is a brief summary of the CSPs and their support for RSA and ECC algorithms:
152+
|CSP Name|Supports RSA?|Supports ECC?|
153+
|---|---|---|
154+
|Microsoft RSA SChannel Cryptographic Provider |||
155+
|Microsoft Software Key Storage Provider |||
156+
|Microsoft Enhanced Cryptographic Provider |||
157+
138158

139159
## Certificate Store Types
140160

@@ -257,7 +277,7 @@ the Keyfactor Command Portal
257277

258278
| Name | Display Name | Description | Type | Default Value | Entry has a private key | Adding an entry | Removing an entry | Reenrolling an entry |
259279
| ---- | ------------ | ---- | ------------- | ----------------------- | ---------------- | ----------------- | ------------------- | ----------- |
260-
| ProviderName | Crypto Provider Name | Name of the Windows cryptographic provider to use during reenrollment jobs when generating and storing the private keys. If not specified, defaults to 'Microsoft Strong Cryptographic Provider'. This value would typically be specified when leveraging a Hardware Security Module (HSM). The specified cryptographic provider must be available on the target server being managed. The list of installed cryptographic providers can be obtained by running 'certutil -csplist' on the target Server. | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked |
280+
| ProviderName | Crypto Provider Name | Name of the Windows cryptographic service provider to use when generating and storing private keys. For more information, refer to the section 'Using Crypto Service Providers' | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked |
261281
| SAN | SAN | String value specifying the Subject Alternative Name (SAN) to be used when performing reenrollment jobs. Format as a list of <san_type>=<san_value> entries separated by ampersands; Example: 'dns=www.example.com&dns=www.example2.com' for multiple SANs. Can be made optional if RFC 2818 is disabled on the CA. | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | ✅ Checked |
262282

263283
The Entry Parameters tab should look like this:
@@ -392,7 +412,7 @@ the Keyfactor Command Portal
392412
| SiteName | IIS Site Name | String value specifying the name of the IIS web site to bind the certificate to. Example: 'Default Web Site' or any custom site name such as 'MyWebsite'. | String | Default Web Site | 🔲 Unchecked | ✅ Checked | ✅ Checked | ✅ Checked |
393413
| SniFlag | SSL Flags | A 128-Bit Flag that determines what type of SSL settings you wish to use. The default is 0, meaning No SNI. For more information, check IIS documentation for the appropriate bit setting.) | String | 0 | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked |
394414
| Protocol | Protocol | Multiple choice value specifying the protocol to bind to. Example: 'https' for secure communication. | MultipleChoice | https | 🔲 Unchecked | ✅ Checked | ✅ Checked | ✅ Checked |
395-
| ProviderName | Crypto Provider Name | Name of the Windows cryptographic provider to use during reenrollment jobs when generating and storing the private keys. If not specified, defaults to 'Microsoft Strong Cryptographic Provider'. This value would typically be specified when leveraging a Hardware Security Module (HSM). The specified cryptographic provider must be available on the target server being managed. The list of installed cryptographic providers can be obtained by running 'certutil -csplist' on the target Server. | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked |
415+
| ProviderName | Crypto Provider Name | Name of the Windows cryptographic service provider to use when generating and storing private keys. For more information, refer to the section 'Using Crypto Service Providers' | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked |
396416
| SAN | SAN | String value specifying the Subject Alternative Name (SAN) to be used when performing reenrollment jobs. Format as a list of <san_type>=<san_value> entries separated by ampersands; Example: 'dns=www.example.com&dns=www.example2.com' for multiple SANs. Can be made optional if RFC 2818 is disabled on the CA. | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | ✅ Checked |
397417

398418
The Entry Parameters tab should look like this:
@@ -515,7 +535,7 @@ the Keyfactor Command Portal
515535
| Name | Display Name | Description | Type | Default Value | Entry has a private key | Adding an entry | Removing an entry | Reenrolling an entry |
516536
| ---- | ------------ | ---- | ------------- | ----------------------- | ---------------- | ----------------- | ------------------- | ----------- |
517537
| InstanceName | Instance Name | String value specifying the SQL Server instance name to bind the certificate to. Example: 'MSSQLServer' for the default instance or 'Instance1' for a named instance. | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked |
518-
| ProviderName | Crypto Provider Name | Optional string value specifying the name of the Windows cryptographic provider to use during reenrollment jobs when generating and storing private keys. Example: 'Microsoft Strong Cryptographic Provider'. | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked |
538+
| ProviderName | Crypto Provider Name | Name of the Windows cryptographic service provider to use when generating and storing private keys. For more information, refer to the section 'Using Crypto Service Providers' | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked |
519539
| SAN | SAN | String value specifying the Subject Alternative Name (SAN) to be used when performing reenrollment jobs. Format as a list of <san_type>=<san_value> entries separated by ampersands; Example: 'dns=www.example.com&dns=www.example2.com' for multiple SANs. | String | | 🔲 Unchecked | 🔲 Unchecked | 🔲 Unchecked | ✅ Checked |
520540

521541
The Entry Parameters tab should look like this:

docsource/content.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ For customers wishing to use something other than the local administrator accoun
8282
- Access any Cryptographic Service Provider (CSP) referenced in re-enrollment jobs.
8383
- Read and Write values in the registry (HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server) when performing SQL Server certificate binding.
8484

85+
### Using Crypto Service Providers (CSP)
86+
When adding or reenrolling certificates, you may specify an optional CSP to be used when generating and storing the private keys. This value would typically be specified when leveraging a Hardware Security Module (HSM). The specified cryptographic provider must be available on the target server being managed.
87+
88+
The list of installed cryptographic providers can be obtained by running the PowerShell command on the target server:
89+
90+
certutil -csplist
91+
92+
When performing a ReEnrollment or On Device Key Generation (ODKG) job, if no CSP is specified, a default value of 'Microsoft Strong Cryptographic Provider' will be used.
93+
94+
When performing an Add job, if no CSP is specified, the machine's default CSP will be used, in most cases this could be the 'Microsoft Enhanced Cryptographic Provider v1.0' provider.
95+
96+
Each CSP only supports certain key types and algorithms.
97+
98+
Below is a brief summary of the CSPs and their support for RSA and ECC algorithms:
99+
|CSP Name|Supports RSA?|Supports ECC?|
100+
|---|---|---|
101+
|Microsoft RSA SChannel Cryptographic Provider |||
102+
|Microsoft Software Key Storage Provider |||
103+
|Microsoft Enhanced Cryptographic Provider |||
104+
85105
## Client Machine Instructions
86106
Prior to version 2.6, this extension would only run in the Windows environment. Version 2.6 and greater is capable of running on Linux, however, only the SSH protocol is supported.
87107

integration-manifest.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"DependsOn": "",
116116
"DefaultValue": "",
117117
"Options": "",
118-
"Description": "Name of the Windows cryptographic provider to use during reenrollment jobs when generating and storing the private keys. If not specified, defaults to 'Microsoft Strong Cryptographic Provider'. This value would typically be specified when leveraging a Hardware Security Module (HSM). The specified cryptographic provider must be available on the target server being managed. The list of installed cryptographic providers can be obtained by running 'certutil -csplist' on the target Server."
118+
"Description": "Name of the Windows cryptographic service provider to use when generating and storing private keys. For more information, refer to the section 'Using Crypto Service Providers'"
119119
},
120120
{
121121
"Name": "SAN",
@@ -306,21 +306,21 @@
306306
"Options": "https,http",
307307
"Description": "Multiple choice value specifying the protocol to bind to. Example: 'https' for secure communication."
308308
},
309-
{
310-
"Name": "ProviderName",
311-
"DisplayName": "Crypto Provider Name",
312-
"Type": "String",
313-
"RequiredWhen": {
314-
"HasPrivateKey": false,
315-
"OnAdd": false,
316-
"OnRemove": false,
317-
"OnReenrollment": false
318-
},
319-
"DependsOn": "",
320-
"DefaultValue": "",
321-
"Options": "",
322-
"Description": "Name of the Windows cryptographic provider to use during reenrollment jobs when generating and storing the private keys. If not specified, defaults to 'Microsoft Strong Cryptographic Provider'. This value would typically be specified when leveraging a Hardware Security Module (HSM). The specified cryptographic provider must be available on the target server being managed. The list of installed cryptographic providers can be obtained by running 'certutil -csplist' on the target Server."
309+
{
310+
"Name": "ProviderName",
311+
"DisplayName": "Crypto Provider Name",
312+
"Type": "String",
313+
"RequiredWhen": {
314+
"HasPrivateKey": false,
315+
"OnAdd": false,
316+
"OnRemove": false,
317+
"OnReenrollment": false
323318
},
319+
"DependsOn": "",
320+
"DefaultValue": "",
321+
"Options": "",
322+
"Description": "Name of the Windows cryptographic service provider to use when generating and storing private keys. For more information, refer to the section 'Using Crypto Service Providers'"
323+
},
324324
{
325325
"Name": "SAN",
326326
"DisplayName": "SAN",
@@ -441,21 +441,21 @@
441441
},
442442
"Description": "String value specifying the SQL Server instance name to bind the certificate to. Example: 'MSSQLServer' for the default instance or 'Instance1' for a named instance."
443443
},
444-
{
445-
"Name": "ProviderName",
446-
"DisplayName": "Crypto Provider Name",
447-
"Type": "String",
448-
"RequiredWhen": {
449-
"HasPrivateKey": false,
450-
"OnAdd": false,
451-
"OnRemove": false,
452-
"OnReenrollment": false
453-
},
454-
"DependsOn": "",
455-
"DefaultValue": "",
456-
"Options": "",
457-
"Description": "Optional string value specifying the name of the Windows cryptographic provider to use during reenrollment jobs when generating and storing private keys. Example: 'Microsoft Strong Cryptographic Provider'."
444+
{
445+
"Name": "ProviderName",
446+
"DisplayName": "Crypto Provider Name",
447+
"Type": "String",
448+
"RequiredWhen": {
449+
"HasPrivateKey": false,
450+
"OnAdd": false,
451+
"OnRemove": false,
452+
"OnReenrollment": false
458453
},
454+
"DependsOn": "",
455+
"DefaultValue": "",
456+
"Options": "",
457+
"Description": "Name of the Windows cryptographic service provider to use when generating and storing private keys. For more information, refer to the section 'Using Crypto Service Providers'"
458+
},
459459
{
460460
"Name": "SAN",
461461
"DisplayName": "SAN",

0 commit comments

Comments
 (0)