Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 2.4 to main #103

Merged
merged 24 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4d8e575
Initial changes for creating and importing pfx files to accept specif…
Feb 29, 2024
9be2ad6
Added ReEnrollment jobs to WinSQL
Mar 14, 2024
fc7d525
Update generated README
Mar 18, 2024
5e8ec1a
Updated some documentation.
Mar 26, 2024
56396f1
Added additional exception handleing for SQL Management jobs. Update…
Mar 26, 2024
316e4ec
Changed 'MaxAllowed' back to '5' and documented what that value repre…
Mar 27, 2024
5384f6d
Updated the readme-source documentation
Mar 27, 2024
8fbc6c7
Update generated README
Mar 27, 2024
d9d4417
Modified how runspaces are created for local machines access . Added…
Apr 16, 2024
4b7b26e
Improved some trace log information.
Apr 17, 2024
3eb72af
Added error trapping when attepting to get the last exit code from a …
Apr 17, 2024
e6f2f1f
Corrected some misspelled words in the ReadMe.
Apr 22, 2024
67aff5a
Update generated README
Apr 22, 2024
268c18b
Update generated README
Apr 25, 2024
bfc9fdc
Merge pull request #102 from Keyfactor/TestingBranch
fiddlermikey Apr 30, 2024
13e8533
POC for Macys - do not use for production.
May 29, 2024
3ce27b4
Minor changes
May 29, 2024
1a5353d
Added store path and addstore for certs with no private keys
May 29, 2024
c50a384
Merge branch '58570-Add_Cert_With_No_PW' into MacysPOC
rcpokorny May 29, 2024
6e74572
Merge pull request #104 from Keyfactor/MacysPOC
rcpokorny May 29, 2024
5be3649
#ab58570 Added additional error trapping and logging. Also modified …
May 31, 2024
278fa47
AB#58570 Added additional error trapping and logging. Also modified …
May 31, 2024
ce61ae2
Merge branch '58570-Add_Cert_With_No_PW' of https://github.com/Keyfac…
May 31, 2024
7c35815
Merge pull request #105 from Keyfactor/58570-Add_Cert_With_No_PW
fiddlermikey Jun 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
2.4.1
* Modified the CertUtil logic to use the -addstore argument when no password is sent with the certificate information.
* Added additional error trapping and trace logs

2.4.0
* Changed the way certificates are added to cert stores. CertUtil is now used to import the PFX certificate into the associated store. The CSP is now considered when maintaining certificates, empty CSP values will result in using the machines default CSP.
* Added the Crypto Service Provider and SAN Entry Parameters to be used on Inventory queries, Adding and ReEnrollments for the WinCert, WinSQL and IISU extensions.
* Changed how Client Machine Names are handled when a 'localhost' connection is desiered. The new naming convention is: {machineName}|localmachine. This will eliminate the issue of unqiue naming conflicts.
* Updated the manifest.json to now include WinSQL ReEnrollment.
* Updated the integration-manifest.json file for new fields in cert store types.

2.3.2
* Changed the Open Cert Store access level from a '5' to 'MaxAllowed'

2.3.1
* Added additional error trapping for WinRM connections to allow actual error on failure.

Expand Down
32 changes: 32 additions & 0 deletions IISU/Certificate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.

using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace Keyfactor.Extensions.Orchestrator.WindowsCertStore
{
Expand All @@ -22,5 +24,35 @@ public class Certificate
public byte[] RawData { get; set; }
public bool HasPrivateKey { get; set; }
public string CertificateData => Convert.ToBase64String(RawData);
public string CryptoServiceProvider { get; set; }
public string SAN { get; set; }

public class Utilities
{
public static string FormatSAN(string san)
{
// Use regular expression to extract key-value pairs
var regex = new Regex(@"(?<key>DNS Name|Email|IP Address)=(?<value>[^=,\s]+)");
var matches = regex.Matches(san);

// Format matches into the desired format
string result = string.Join("&", matches.Cast<Match>()
.Select(m => $"{NormalizeKey(m.Groups["key"].Value)}={m.Groups["value"].Value}"));

return result;
}

private static string NormalizeKey(string key)
{
return key.ToLower() switch
{
"dns name" => "dns",
"email" => "email",
"ip address" => "ip",
_ => key.ToLower() // For other types, keep them as-is
};
}

}
}
}
4 changes: 3 additions & 1 deletion IISU/CertificateStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ public void RemoveCertificate(string thumbprint)
{
using var ps = PowerShell.Create();
ps.Runspace = RunSpace;

// Open with value of 5 means: Open existing only (4) + Open ReadWrite (1)
var removeScript = $@"
$ErrorActionPreference = 'Stop'
$certStore = New-Object System.Security.Cryptography.X509Certificates.X509Store('{StorePath}','LocalMachine')
$certStore.Open('MaxAllowed')
$certStore.Open(5)
$certToRemove = $certStore.Certificates.Find(0,'{thumbprint}',$false)
if($certToRemove.Count -gt 0) {{
$certStore.Remove($certToRemove[0])
Expand Down
22 changes: 19 additions & 3 deletions IISU/ClientPSCertStoreInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,37 @@ public List<Certificate> GetCertificatesFromStore(Runspace runSpace, string stor
$certs = $certStore.Certificates
$certStore.Close()
$certStore.Dispose()
foreach ( $cert in $certs){{
$cert | Select-Object -Property Thumbprint, RawData, HasPrivateKey
$certs | ForEach-Object {{
$certDetails = @{{
Subject = $_.Subject
Thumbprint = $_.Thumbprint
HasPrivateKey = $_.HasPrivateKey
RawData = $_.RawData
san = $_.Extensions | Where-Object {{ $_.Oid.FriendlyName -eq ""Subject Alternative Name"" }} | ForEach-Object {{ $_.Format($false) }}
}}

if ($_.HasPrivateKey) {{
$certDetails.CSP = $_.PrivateKey.CspKeyContainerInfo.ProviderName
}}

New-Object PSObject -Property $certDetails
}}";

ps.AddScript(certStoreScript);

var certs = ps.Invoke();

foreach (var c in certs)
{
myCertificates.Add(new Certificate
{
Thumbprint = $"{c.Properties["Thumbprint"]?.Value}",
HasPrivateKey = bool.Parse($"{c.Properties["HasPrivateKey"]?.Value}"),
RawData = (byte[])c.Properties["RawData"]?.Value
RawData = (byte[])c.Properties["RawData"]?.Value,
CryptoServiceProvider = $"{c.Properties["CSP"]?.Value }",
SAN = Certificate.Utilities.FormatSAN($"{c.Properties["san"]?.Value}")
});
}

return myCertificates;
}
Expand Down
Loading
Loading