Skip to content

Commit 0b2d104

Browse files
authored
Merge pull request #141 from Keyfactor/72207_Binding_Attempted_With_Bad_CSP
AB#72207 Fixed error adding cert to store when CSP was changed by user.
2 parents 8fcca68 + f2b0080 commit 0b2d104

File tree

17 files changed

+249
-445
lines changed

17 files changed

+249
-445
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2.6.2
2+
* Fixed error when attempting to connect to remote computer using UO service account
3+
* Fixed error when connecting to remote computer using HTTPS; was defaulting to HTTP
4+
* Fixed the creation of a certificate when the Cryptographic Service Provider was changed by the user
5+
* Updated logic when getting the CSP. Now supports modern CHG and legacy CAPI APIs. This will allow the CSP to show in the stores inventory.
6+
* Re-factored code to eliminate warnings
7+
* Bumped up he following packages to eliminate .net vulnerabilities and obsolete packages:
8+
* Keyfactor.Orchestrators.IOrchestratorJobExtensions" Version="1.0.0"
9+
* Microsoft.PowerShell.SDK" Version="7.4.10" Condition="'$(TargetFramework)' == 'net8.0'"
10+
* runtime.linux-arm64.runtime.native.System.IO.Ports" Version="9.0.5"
11+
* runtime.osx-arm64.runtime.native.System.IO.Ports" Version="9.0.5"
12+
* System.Formats.Asn1" Version="8.0.2" Condition="'$(TargetFramework)' == 'net6.0'"
13+
* System.Formats.Asn1" Version="9.0.0" Condition="'$(TargetFramework)' == 'net8.0'"
14+
* System.IO.Packaging" Version="6.0.2" Condition="'$(TargetFramework)' == 'net6.0'"
15+
* System.IO.Packaging" Version="8.0.1" Condition="'$(TargetFramework)' == 'net8.0'"
16+
* System.Text.Json" Version="8.0.5"
17+
118
2.6.1
219
* Documentation updates for the 2.6 release
320
* Fix a naming typo in the 2.5 migration SQL script
@@ -11,6 +28,7 @@
1128
* Added the ability to run the extension in a Linux environment. To utilize this change, for each Cert Store Types (WinCert/WinIIS/WinSQL), add ssh to the Custom Field <b>WinRM Protocol</b>. When using ssh as a protocol, make sure to enter the appropriate ssh port number under WinRM Port.
1229
* NOTE: For legacy purposes the Display names WinRM Protocol and WinRM Port are maintained although the type of protocols now includes ssh.
1330
* Moved all inventory and management jobs to external PowerShell script file .\PowerShellScripts\WinCertScripts.ps1
31+
* Changed how IIS Bound certificates are deleted; Certificates are only deleted from the certificate store when the certificate is NOT BOUND to any other sites.
1432
* NOTE: This version was not publicly released.
1533

1634
2.5.1
@@ -19,6 +37,7 @@
1937
2.5.0
2038
* Added the Bindings to the end of the thumbprint to make the alias unique.
2139
* Using new IISWebBindings cmdlet to use additional SSL flags when binding certificate to website.
40+
* NOTE: The property SNIFlag has changed from a multi-select to a string with default of "0". To properly use the new SNI/SSL flags you can delete the SNIFlag from the store type and re-add the field as described in the ReadMe. If you have several existing cert stores, you may can execute the SQL script (IISU Sni Flag 2.5 upgrade script) to update the field type. Consult your Keyfactor Rep for help.
2241
* Added multi-platform support for .Net6 and .Net8.
2342
* Updated various PowerShell scripts to handle both .Net6 and .Net8 differences (specifically the absence of the WebAdministration module in PS SDK 7.4.x+)
2443
* Fixed issue to update multiple websites when using the same cert.

IISU/ClientPSCertStoreReEnrollment.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Ignore Spelling: Keyfactor
15+
// Ignore Spelling: Keyfactor Reenrollment
1616

1717
// 021225 rcp Cleaned up and removed unnecessary code
1818

@@ -40,7 +40,9 @@ internal class ClientPSCertStoreReEnrollment
4040
private readonly IPAMSecretResolver _resolver;
4141

4242
private PSHelper _psHelper;
43+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
4344
private Collection<PSObject>? _results;
45+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
4446

4547
public ClientPSCertStoreReEnrollment(ILogger logger, IPAMSecretResolver resolver)
4648
{

IISU/ImplementedStoreTypes/Win/Inventory.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
// 021225 rcp 2.6.0 Cleaned up and verified code
1616

17+
// Ignore Spelling: Keyfactor
18+
1719
using System;
1820
using System.Collections.Generic;
1921
using System.Collections.ObjectModel;
@@ -31,9 +33,11 @@ public class Inventory : WinCertJobTypeBase, IInventoryJobExtension
3133
{
3234
private ILogger _logger;
3335
public string ExtensionName => "WinCertInventory";
34-
36+
37+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3538
Collection<PSObject>? results = null;
36-
39+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
40+
3741
public Inventory()
3842
{
3943

IISU/ImplementedStoreTypes/Win/Management.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.using Keyfactor.Logging;
1414

15-
// Ignore Spelling: Keyfactor
15+
// Ignore Spelling: Keyfactor crypto
1616

1717
// 021225 rcp 2.6.0 Cleaned up and verified code
1818

@@ -35,7 +35,9 @@ public class Management : WinCertJobTypeBase, IManagementJobExtension
3535
private ILogger _logger;
3636

3737
private PSHelper _psHelper;
38+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3839
private Collection<PSObject>? _results = null;
40+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3941

4042
// Function wide config values
4143
private string _clientMachineName = string.Empty;
@@ -95,7 +97,9 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
9597
{
9698
string certificateContents = config.JobCertificate.Contents;
9799
string privateKeyPassword = config.JobCertificate.PrivateKeyPassword;
100+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
98101
string? cryptoProvider = config.JobProperties["ProviderName"]?.ToString();
102+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
99103

100104
complete = AddCertificate(certificateContents, privateKeyPassword, cryptoProvider);
101105
_logger.LogTrace($"Completed adding the certificate to the store");

IISU/ImplementedStoreTypes/WinIIS/IISBindingInfo.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Ignore Spelling: Keyfactor IISU
15+
// Ignore Spelling: Keyfactor IISU Sni Aliase
1616

1717
// 021225 rcp 2.6.0 Cleaned up and verified code
1818

@@ -29,7 +29,9 @@ public class IISBindingInfo
2929
public string Protocol { get; set; }
3030
public string IPAddress { get; set; }
3131
public string Port { get; set; }
32+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3233
public string? HostName { get; set; }
34+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3335
public string SniFlag { get; set; }
3436
public string Thumbprint { get; private set; }
3537

IISU/ImplementedStoreTypes/WinIIS/Inventory.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
// 021225 rcp 2.6.0 Cleaned up and verified code
1616

17+
// Ignore Spelling: Keyfactor IISU
18+
1719
using Keyfactor.Logging;
1820
using Keyfactor.Orchestrators.Common.Enums;
1921
using Keyfactor.Orchestrators.Extensions;
@@ -30,7 +32,9 @@ namespace Keyfactor.Extensions.Orchestrator.WindowsCertStore.IISU
3032
public class Inventory : WinCertJobTypeBase, IInventoryJobExtension
3133
{
3234
private ILogger _logger;
35+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3336
Collection<PSObject>? results = null;
37+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3438

3539
public string ExtensionName => "WinIISUInventory";
3640

IISU/ImplementedStoreTypes/WinIIS/Management.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Ignore Spelling: Keyfactor IISU Crypto
1516
using System;
1617
using System.Collections.Generic;
1718
using System.Collections.ObjectModel;
@@ -34,7 +35,9 @@ public class Management : WinCertJobTypeBase, IManagementJobExtension
3435
private ILogger _logger;
3536

3637
private PSHelper _psHelper;
38+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3739
private Collection<PSObject>? _results = null;
40+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3841

3942
// Function wide config values
4043
private string _clientMachineName = string.Empty;
@@ -99,11 +102,15 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
99102
{
100103
string certificateContents = config.JobCertificate.Contents;
101104
string privateKeyPassword = config.JobCertificate.PrivateKeyPassword;
105+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
102106
string? cryptoProvider = config.JobProperties["ProviderName"]?.ToString();
107+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
103108

104109
// Add Certificate to Cert Store
105110
try
106111
{
112+
IISBindingInfo bindingInfo = new IISBindingInfo(config.JobProperties);
113+
107114
OrchestratorJobStatusJobResult psResult = OrchestratorJobStatusJobResult.Unknown;
108115
string failureMessage = "";
109116

@@ -112,9 +119,8 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
112119
_logger.LogTrace($"New thumbprint: {newThumbprint}");
113120

114121
// Bind Certificate to IIS Site
115-
if (newThumbprint != null)
122+
if (!string.IsNullOrEmpty(newThumbprint))
116123
{
117-
IISBindingInfo bindingInfo = new IISBindingInfo(config.JobProperties);
118124
_logger.LogTrace("Returned after binding certificate to store");
119125
var results = WinIISBinding.BindCertificate(_psHelper, bindingInfo, newThumbprint, "", _storePath);
120126
if (results != null && results.Count > 0)
@@ -172,6 +178,14 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
172178
FailureMessage = failureMessage
173179
};
174180
}
181+
else
182+
{
183+
complete = new JobResult
184+
{
185+
Result = OrchestratorJobStatusJobResult.Failure,
186+
JobHistoryId = _jobHistoryID,
187+
FailureMessage = $"No thumbprint was returned. Unable to bind certificate to site: {bindingInfo.SiteName}."
188+
}; }
175189
}
176190
catch (Exception ex)
177191
{
@@ -183,7 +197,7 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
183197
};
184198
}
185199

186-
_logger.LogTrace($"Completed adding and binding the certificate to the store");
200+
_logger.LogTrace($"Exiting the Adding of Certificate process.");
187201

188202
break;
189203
}
@@ -284,9 +298,10 @@ public string AddCertificate(string certificateContents, string privateKeyPasswo
284298
catch (Exception ex)
285299
{
286300
var failureMessage = $"Management job {_operationType} failed on Store '{_storePath}' on server '{_clientMachineName}' with error: '{LogHandler.FlattenException(ex)}'";
301+
var niceMessage = $"Management job {_operationType} failed on Store '{_storePath}' on server '{_clientMachineName}' with error: {ex.Message}";
287302
_logger.LogError(failureMessage);
288303

289-
throw new Exception (failureMessage);
304+
throw new Exception (niceMessage);
290305
}
291306
}
292307
public void RemoveIISCertificate(string thumbprint)

IISU/ImplementedStoreTypes/WinIIS/WinIISBinding.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
// 021225 rcp 2.6.0 Cleaned up and verified code
1616

17+
// Ignore Spelling: Keyfactor IISU
18+
1719
using Keyfactor.Logging;
1820
using Microsoft.Extensions.Logging;
1921
using System;
@@ -25,9 +27,9 @@ namespace Keyfactor.Extensions.Orchestrator.WindowsCertStore.IISU
2527
{
2628
public class WinIISBinding
2729
{
28-
private static ILogger _logger;
29-
private static Collection<PSObject>? _results = null;
30-
private static PSHelper _helper;
30+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
31+
private static ILogger? _logger;
32+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3133

3234
public static Collection<PSObject> BindCertificate(PSHelper psHelper, IISBindingInfo bindingInfo, string thumbprint, string renewalThumbprint, string storePath)
3335
{

IISU/ImplementedStoreTypes/WinSQL/Inventory.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public class Inventory : WinCertJobTypeBase, IInventoryJobExtension
3535
private ILogger _logger;
3636
public string ExtensionName => "WinSqlInventory";
3737

38+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3839
Collection<PSObject>? results = null;
40+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3941

4042
public Inventory()
4143
{

IISU/ImplementedStoreTypes/WinSQL/Management.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Ignore Spelling: thumbprint Keyfactor sql
15+
// Ignore Spelling: thumbprint Keyfactor sql crypto
1616

1717
// 021225 rcp 2.6.0 Cleaned up and verified code
1818

@@ -35,7 +35,9 @@ public class Management : WinCertJobTypeBase, IManagementJobExtension
3535
private ILogger _logger;
3636

3737
private PSHelper _psHelper;
38+
#pragma warning disable CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3839
private Collection<PSObject>? _results = null;
40+
#pragma warning restore CS8632 // The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
3941

4042
// Function wide config values
4143
private string _clientMachineName = string.Empty;
@@ -172,8 +174,6 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
172174
// Remove the certificate from the cert store
173175
complete = RemoveCertificate(config.JobCertificate.Alias);
174176
_logger.LogTrace($"Completed removing the certificate from the store");
175-
176-
break;
177177
}
178178
else
179179
{
@@ -184,7 +184,6 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
184184
FailureMessage = "Unable to unbind one or more certificates from the SQL Instances."
185185
};
186186
}
187-
188187
}
189188
catch (Exception ex)
190189
{
@@ -195,10 +194,9 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
195194
FailureMessage = ex.Message
196195
};
197196
}
198-
199-
_logger.LogTrace($"Completed unbinding and removing the certificate from the store");
200-
return complete;
201197
}
198+
_logger.LogTrace($"Completed unbinding and removing the certificate from the store");
199+
return complete;
202200
}
203201
}
204202

0 commit comments

Comments
 (0)