Skip to content

Commit

Permalink
microsoft#817 Updating bindings to accept certstore names. defaulting…
Browse files Browse the repository at this point in the history
… to existing MY
  • Loading branch information
Sibsy committed Jun 12, 2024
1 parent 5fc7378 commit dbc93ad
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,20 @@ function Add-SslCert
[string]$hostname,
[string]$sni,
[int]$iisVersion,
[string]$ipAddress
[string]$ipAddress,
[string]$certstore
)

if([string]::IsNullOrWhiteSpace($certhash))
{
Write-Verbose "CertHash is empty. Returning"
return
}
if([string]::IsNullOrWhiteSpace($certstore))
{
Write-Verbose "CertStore is empty. Setting it to MY"
$certstore = "MY"
}

if($ipAddress -eq "All Unassigned" -or $ipAddress -eq "*")
{
Expand All @@ -185,7 +191,7 @@ function Add-SslCert
$result = Invoke-VstsTool -Filename "netsh" -Arguments $showCertCmd
$isItSameBinding = $result.Get(4).Contains([string]::Format("{0}:{1}", $hostname, $port))

$addCertCmd = [string]::Format("http add sslcert hostnameport={0}:{1} certhash={2} appid={{{3}}} certstorename=MY", $hostname, $port, $certhash, [System.Guid]::NewGuid().toString())
$addCertCmd = [string]::Format("http add sslcert hostnameport={0}:{1} certhash={2} appid={{{3}}} certstorename={4}", $hostname, $port, $certhash, [System.Guid]::NewGuid().toString(), $certstore)
}
else
{
Expand All @@ -195,7 +201,7 @@ function Add-SslCert
$result = Invoke-VstsTool -Filename "netsh" -Arguments $showCertCmd
$isItSameBinding = $result.Get(4).Contains([string]::Format("{0}:{1}", $ipAddress, $port))

$addCertCmd = [string]::Format("http add sslcert ipport={0}:{1} certhash={2} appid={{{3}}} certstorename=MY", $ipAddress, $port, $certhash, [System.Guid]::NewGuid().toString())
$addCertCmd = [string]::Format("http add sslcert ipport={0}:{1} certhash={2} appid={{{3}}} certstorename={4}", $ipAddress, $port, $certhash, [System.Guid]::NewGuid().toString(), $certstore)
}

$isItSameCert = $result.Get(5).ToLower().Contains($certhash.ToLower())
Expand Down Expand Up @@ -287,7 +293,7 @@ function Add-WebsiteBindings {
}

if($binding.protocol -eq "https") {
Add-SslCert -ipAddress $binding.ipAddress -port $binding.port -certhash $binding.sslThumbPrint -hostname $binding.hostName -sni $binding.sniFlag -iisVersion $iisVersion
Add-SslCert -ipAddress $binding.ipAddress -port $binding.port -certhash $binding.sslThumbPrint -hostname $binding.hostName -sni $binding.sniFlag -iisVersion $iisVersion -certstore $binding.certStore
Enable-SNI -siteName $siteName -sni $binding.sniFlag -ipAddress $binding.ipAddress -port $binding.port -hostname $binding.hostName
}
}
Expand Down

0 comments on commit dbc93ad

Please sign in to comment.