Skip to content

Commit 82dda97

Browse files
authored
Merge c3912ab into 084bb01
2 parents 084bb01 + c3912ab commit 82dda97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2418
-342
lines changed

.github/workflows/keyfactor-starter-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
jobs:
1313
call-starter-workflow:
14-
uses: keyfactor/actions/.github/workflows/starter.yml@v2
14+
uses: keyfactor/actions/.github/workflows/starter.yml@dual-platform-without-doctool
1515
secrets:
1616
token: ${{ secrets.V2BUILDTOKEN}}
1717
APPROVE_README_PUSH: ${{ secrets.APPROVE_README_PUSH}}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2.5.0
2+
* Added the Bindings to the end of the thumbprint to make the alias unique.
3+
* Using new IISWebBindings commandlet to use additional SSL flags when binding certificate to website.
4+
* Added multi-platform support for .Net6 and .Net8.
5+
* Updated various PowerShell scripts to handle both .Net6 and .Net8 differences (specifically the absense of the WebAdministration module in PS SDK 7.4.x+)
6+
* Fixed issue to update multiple websites when using the same cert.
7+
* Removed renewal thumbprint logic to update multiple website; each job now updates its own specific certificate.
8+
19
2.4.4
210
* Fix an issue with WinRM parameters when migrating Legacy IIS Stores to the WinCert type
311
* Fix an issue with "Delete" script in the Legacy IIS Migration that did not remove some records from dependent tables

IISU/CertificateStore.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,38 +181,21 @@ public static List<CurrentInventoryItem> GetIISBoundCertificates(Runspace runSpa
181181

182182
if (foundCert == null) continue;
183183

184-
var sniValue = "";
185-
switch (Convert.ToInt16(binding.Properties["sniFlg"]?.Value))
186-
{
187-
case 0:
188-
sniValue = "0 - No SNI";
189-
break;
190-
case 1:
191-
sniValue = "1 - SNI Enabled";
192-
break;
193-
case 2:
194-
sniValue = "2 - Non SNI Binding";
195-
break;
196-
case 3:
197-
sniValue = "3 - SNI Binding";
198-
break;
199-
}
200-
201184
var siteSettingsDict = new Dictionary<string, object>
202185
{
203186
{ "SiteName", binding.Properties["Name"]?.Value },
204187
{ "Port", binding.Properties["Bindings"]?.Value.ToString()?.Split(':')[1] },
205188
{ "IPAddress", binding.Properties["Bindings"]?.Value.ToString()?.Split(':')[0] },
206189
{ "HostName", binding.Properties["Bindings"]?.Value.ToString()?.Split(':')[2] },
207-
{ "SniFlag", sniValue },
190+
{ "SniFlag", binding.Properties["sniFlg"]?.Value },
208191
{ "Protocol", binding.Properties["Protocol"]?.Value }
209192
};
210193

211194
myBoundCerts.Add(
212195
new CurrentInventoryItem
213196
{
214197
Certificates = new[] { foundCert.CertificateData },
215-
Alias = thumbPrint,
198+
Alias = thumbPrint + ":" + binding.Properties["Bindings"]?.Value.ToString(),
216199
PrivateKeyEntry = foundCert.HasPrivateKey,
217200
UseChainLevel = false,
218201
ItemStatus = OrchestratorInventoryItemStatus.Unknown,

IISU/CertificateStoreException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
namespace Keyfactor.Extensions.Orchestrator.WindowsCertStore
1919
{
2020
[Serializable]
21-
internal class CertificateStoreException : Exception
21+
public class CertificateStoreException : Exception
2222
{
2323
public CertificateStoreException()
2424
{

IISU/ClientPSCertStoreInventory.cs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,82 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
using Keyfactor.Extensions.Orchestrator.WindowsCertStore.IISU;
1415
using Keyfactor.Logging;
1516
using Microsoft.Extensions.Logging;
1617
using System;
1718
using System.Collections.Generic;
19+
using System.Collections.ObjectModel;
1820
using System.Management.Automation;
1921
using System.Management.Automation.Runspaces;
22+
using System.Runtime.ConstrainedExecution;
2023
using System.Text;
2124

2225
namespace Keyfactor.Extensions.Orchestrator.WindowsCertStore
2326
{
24-
abstract class ClientPSCertStoreInventory
27+
public abstract class ClientPSCertStoreInventory
2528
{
2629
private ILogger _logger;
30+
31+
protected ClientPSCertStoreInventory()
32+
{
33+
_logger = LogHandler.GetClassLogger<ClientPSCertStoreInventory>();
34+
}
35+
2736
public ClientPSCertStoreInventory(ILogger logger)
2837
{
2938
_logger = logger;
3039
}
3140

41+
public List<Certificate> GetCertificatesFromStore(RemoteSettings settings, string storePath)
42+
{
43+
try
44+
{
45+
ILogger _logger = LogHandler.GetClassLogger(this.GetType());
46+
47+
List<Certificate> myCertificates = new();
48+
49+
_logger.LogTrace("Attempting to establish PowerShell connection.");
50+
using (PSHelper ps = new(settings.Protocol, settings.Port, settings.IncludePortInSPN, settings.ClientMachineName, settings.ServerUserName, settings.ServerPassword))
51+
{
52+
_logger.LogTrace("Initializing connection");
53+
ps.Initialize();
54+
55+
var scriptParameters = new Dictionary<string, object>
56+
{
57+
{ "StoreName", storePath }
58+
};
59+
60+
var results = ps.ExecuteCommand(PSHelper.LoadScript("WinCertInventory.ps1"), scriptParameters);
61+
62+
foreach (var c in results)
63+
{
64+
myCertificates.Add(new Certificate
65+
{
66+
Thumbprint = $"{c.Properties["Thumbprint"]?.Value}",
67+
HasPrivateKey = bool.Parse($"{c.Properties["HasPrivateKey"]?.Value}"),
68+
RawData = (byte[])c.Properties["RawData"]?.Value,
69+
CryptoServiceProvider = $"{c.Properties["CSP"]?.Value}",
70+
SAN = Certificate.Utilities.FormatSAN($"{c.Properties["san"]?.Value}")
71+
});
72+
}
73+
}
74+
75+
_logger.LogTrace($"found: {myCertificates.Count} certificate(s), exiting GetCertificatesFromStore()");
76+
return myCertificates;
77+
78+
}
79+
catch (Exception ex)
80+
{
81+
throw new Exception ("An error occurred while attempting to read the certificates from the store.\n" + ex.Message.ToString());
82+
}
83+
}
84+
85+
// ORIG
3286
public List<Certificate> GetCertificatesFromStore(Runspace runSpace, string storePath)
3387
{
88+
ILogger _logger = LogHandler.GetClassLogger(this.GetType());
89+
3490
List<Certificate> myCertificates = new List<Certificate>();
3591
try
3692
{

IISU/ClientPSCertStoreManager.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace Keyfactor.Extensions.Orchestrator.WindowsCertStore
2929
{
30-
internal class ClientPSCertStoreManager
30+
public class ClientPSCertStoreManager
3131
{
3232
private ILogger _logger;
3333
private Runspace _runspace;
@@ -40,6 +40,11 @@ public X509Certificate2 X509Cert
4040
get { return x509Cert; }
4141
}
4242

43+
public ClientPSCertStoreManager(Runspace runSpace)
44+
{
45+
_logger = LogHandler.GetClassLogger<ClientPSCertStoreManager>();
46+
_runspace = runSpace;
47+
}
4348

4449
public ClientPSCertStoreManager(ILogger logger, Runspace runSpace, long jobNumber)
4550
{
@@ -126,9 +131,9 @@ public JobResult ImportPFXFile(string filePath, string privateKeyPassword, strin
126131
{
127132
ps.Runspace = _runspace;
128133

129-
if (cryptoProviderName == null)
134+
if (string.IsNullOrEmpty(cryptoProviderName))
130135
{
131-
if (privateKeyPassword == null)
136+
if (string.IsNullOrEmpty(privateKeyPassword))
132137
{
133138
// If no private key password is provided, import the pfx file directory to the store using addstore argument
134139
string script = @"
@@ -179,7 +184,7 @@ public JobResult ImportPFXFile(string filePath, string privateKeyPassword, strin
179184
}
180185
else
181186
{
182-
if (privateKeyPassword == null)
187+
if (string.IsNullOrEmpty(privateKeyPassword))
183188
{
184189
string script = @"
185190
param($pfxFilePath, $cspName, $storePath)

IISU/ClientPSCertStoreReEnrollment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public JobResult PerformReEnrollment(ReenrollmentJobConfiguration config, Submit
6565
string storePath = config.CertificateStoreDetails.StorePath;
6666

6767
_logger.LogTrace($"Establishing runspace on client machine: {clientMachineName}");
68-
using var runSpace = PsHelper.GetClientPsRunspace(protocol, clientMachineName, port, IncludePortInSPN, serverUserName, serverPassword);
68+
using var runSpace = PSHelper.GetClientPsRunspace(protocol, clientMachineName, port, IncludePortInSPN, serverUserName, serverPassword);
6969

7070
_logger.LogTrace("Runspace created");
7171
runSpace.Open();

0 commit comments

Comments
 (0)