-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bob Pokorny
committed
Nov 26, 2024
1 parent
60a1a82
commit 8ea49ab
Showing
16 changed files
with
377 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using Keyfactor.Logging; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Keyfactor.Extensions.Orchestrator.WindowsCertStore.IISU | ||
{ | ||
public class WinIISBinding | ||
{ | ||
private static ILogger _logger; | ||
private static Collection<PSObject>? _results = null; | ||
Check warning on line 16 in IISU/ImplementedStoreTypes/WinIIS/WinIISBinding.cs GitHub Actions / call-starter-workflow / call-dotnet-build-and-release-workflow / dotnet-build-and-release
|
||
private static PSHelper _helper; | ||
|
||
public static void BindCertificate(PSHelper psHelper, IISBindingInfo bindingInfo, string thumbprint, string renewalThumbprint, string storePath) | ||
{ | ||
_logger.LogTrace("Attempting to bind and execute PS function (New-KFIISSiteBinding)"); | ||
|
||
// Mandatory parameters | ||
var parameters = new Dictionary<string, object> | ||
{ | ||
{ "Thumbprint", thumbprint }, | ||
{ "WebSite", bindingInfo.SiteName }, | ||
{ "Protocol", bindingInfo.Protocol }, | ||
{ "IPAddress", bindingInfo.IPAddress }, | ||
{ "Port", bindingInfo.Port }, | ||
{ "SNIFlag", bindingInfo.SniFlag }, | ||
{ "StoreName", storePath }, | ||
}; | ||
|
||
// Optional parameters | ||
if (!string.IsNullOrEmpty(bindingInfo.HostName)) { parameters.Add("HostName", bindingInfo.HostName); } | ||
|
||
_results = psHelper.ExecutePowerShell("New-KFIISSiteBinding", parameters); | ||
_logger.LogTrace("Returned from executing PS function (Add-KFCertificateToStore)"); | ||
|
||
// This should return the thumbprint of the certificate | ||
if (_results != null && _results.Count > 0) | ||
{ | ||
_logger.LogTrace($"Bound certificate with the thumbprint: '{thumbprint}' to site: '{bindingInfo.SiteName}'."); | ||
} | ||
else | ||
{ | ||
_logger.LogTrace("No results were returned. There could have been an error while adding the certificate. Look in the trace logs for PowerShell informaiton."); | ||
} | ||
} | ||
|
||
public static bool UnBindCertificate(PSHelper psHelper, IISBindingInfo bindingInfo) | ||
{ | ||
_logger.LogTrace("Attempting to UnBind and execute PS function (Remove-KFIISBinding)"); | ||
|
||
// Mandatory parameters | ||
var parameters = new Dictionary<string, object> | ||
{ | ||
{ "SiteName", bindingInfo.SiteName }, | ||
{ "IPAddress", bindingInfo.IPAddress }, | ||
{ "Port", bindingInfo.Port }, | ||
}; | ||
|
||
// Optional parameters | ||
if (!string.IsNullOrEmpty(bindingInfo.HostName)) { parameters.Add("HostName", bindingInfo.HostName); } | ||
|
||
try | ||
{ | ||
_results = psHelper.ExecutePowerShell("Remove-KFIISBinding", parameters); | ||
_logger.LogTrace("Returned from executing PS function (Remove-KFIISBinding)"); | ||
return true; | ||
} | ||
catch (Exception) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.