Skip to content

Commit 12411d0

Browse files
author
Bob Pokorny
committed
AB#72207 Fixed error adding cert to store when CSP was changed by user.
1 parent 8fcca68 commit 12411d0

File tree

5 files changed

+155
-410
lines changed

5 files changed

+155
-410
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.6.2
2+
* Fixed error when attempting to connect to remote computer using UO service account
3+
* Fixed the creation of a certificate when the Cryptographic Service Provider was changed by the user
4+
* 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.
5+
16
2.6.1
27
* Documentation updates for the 2.6 release
38
* Fix a naming typo in the 2.5 migration SQL script

IISU/ImplementedStoreTypes/WinIIS/Management.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
104104
// Add Certificate to Cert Store
105105
try
106106
{
107+
IISBindingInfo bindingInfo = new IISBindingInfo(config.JobProperties);
108+
107109
OrchestratorJobStatusJobResult psResult = OrchestratorJobStatusJobResult.Unknown;
108110
string failureMessage = "";
109111

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

114116
// Bind Certificate to IIS Site
115-
if (newThumbprint != null)
117+
if (!string.IsNullOrEmpty(newThumbprint))
116118
{
117-
IISBindingInfo bindingInfo = new IISBindingInfo(config.JobProperties);
118119
_logger.LogTrace("Returned after binding certificate to store");
119120
var results = WinIISBinding.BindCertificate(_psHelper, bindingInfo, newThumbprint, "", _storePath);
120121
if (results != null && results.Count > 0)
@@ -172,6 +173,14 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
172173
FailureMessage = failureMessage
173174
};
174175
}
176+
else
177+
{
178+
complete = new JobResult
179+
{
180+
Result = OrchestratorJobStatusJobResult.Failure,
181+
JobHistoryId = _jobHistoryID,
182+
FailureMessage = $"No thumbprint was returned. Unable to bind certificate to site: {bindingInfo.SiteName}."
183+
}; }
175184
}
176185
catch (Exception ex)
177186
{
@@ -183,7 +192,7 @@ public JobResult ProcessJob(ManagementJobConfiguration config)
183192
};
184193
}
185194

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

188197
break;
189198
}

IISU/PSHelper.cs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ private void InitializeRemoteSession()
185185
_logger.LogTrace("Initializing WinRM connection");
186186
try
187187
{
188-
var pw = new NetworkCredential(serverUserName, serverPassword).SecurePassword;
189-
PSCredential myCreds = new PSCredential(serverUserName, pw);
190-
191188
// Create the PSSessionOption object
192189
var sessionOption = new PSSessionOption
193190
{
@@ -197,8 +194,16 @@ private void InitializeRemoteSession()
197194
PS.AddCommand("New-PSSession")
198195
.AddParameter("ComputerName", ClientMachineName)
199196
.AddParameter("Port", port)
200-
.AddParameter("Credential", myCreds)
201197
.AddParameter("SessionOption", sessionOption);
198+
199+
if (!string.IsNullOrEmpty(serverUserName))
200+
{
201+
var pw = new NetworkCredential(serverUserName, serverPassword).SecurePassword;
202+
PSCredential myCreds = new PSCredential(serverUserName, pw);
203+
204+
PS.AddParameter("Credential", myCreds);
205+
}
206+
202207
}
203208
catch (Exception)
204209
{
@@ -235,20 +240,19 @@ private void InitializeRemoteSession()
235240

236241
private void InitializeLocalSession()
237242
{
243+
_logger.LogTrace("Creating out-of-process Powershell Runspace.");
244+
PowerShellProcessInstance psInstance = new PowerShellProcessInstance(new Version(5, 1), null, null, false);
245+
Runspace rs = RunspaceFactory.CreateOutOfProcessRunspace(new TypeTable(Array.Empty<string>()), psInstance);
246+
rs.Open();
247+
PS.Runspace = rs;
248+
238249
_logger.LogTrace("Setting Execution Policy to Unrestricted");
239250
PS.AddScript("Set-ExecutionPolicy Unrestricted -Scope Process -Force");
240251
PS.Invoke(); // Ensure the script is invoked and loaded
241252
CheckErrors();
242253

243254
PS.Commands.Clear(); // Clear commands after loading functions
244255

245-
// Trying this to get IISAdministration loaded!!
246-
PowerShellProcessInstance psInstance = new PowerShellProcessInstance(new Version(5, 1), null, null, false);
247-
Runspace rs = RunspaceFactory.CreateOutOfProcessRunspace(new TypeTable(Array.Empty<string>()), psInstance);
248-
rs.Open();
249-
250-
PS.Runspace = rs;
251-
252256
_logger.LogTrace("Setting script file into memory");
253257
PS.AddScript(". '" + scriptFileLocation + "'");
254258
PS.Invoke(); // Ensure the script is invoked and loaded

0 commit comments

Comments
 (0)