Created
November 7, 2018 21:31
-
-
Save jhorsman/5593fdca1e9b1bb0318ecc09239b8aad to your computer and use it in GitHub Desktop.
Check which SSL/TLS versions are supported by a given hostname
This file contains hidden or 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
function Test-ServerSSLSupport { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | |
[ValidateNotNullOrEmpty()] | |
[string]$HostName, | |
[UInt16]$Port = 443 | |
) | |
process { | |
$RetValue = New-Object psobject -Property @{ | |
Host = $HostName | |
Port = $Port | |
SSLv2 = $false | |
SSLv3 = $false | |
TLSv1_0 = $false | |
TLSv1_1 = $false | |
TLSv1_2 = $false | |
KeyExhange = $null | |
HashAlgorithm = $null | |
} | |
"ssl2", "ssl3", "tls", "tls11", "tls12" | %{ | |
$TcpClient = New-Object Net.Sockets.TcpClient | |
$TcpClient.Connect($RetValue.Host, $RetValue.Port) | |
$SslStream = New-Object Net.Security.SslStream $TcpClient.GetStream() | |
$SslStream.ReadTimeout = 15000 | |
$SslStream.WriteTimeout = 15000 | |
try { | |
$SslStream.AuthenticateAsClient($RetValue.Host,$null,$_,$false) | |
$RetValue.KeyExhange = $SslStream.KeyExchangeAlgorithm | |
$RetValue.HashAlgorithm = $SslStream.HashAlgorithm | |
$status = $true | |
} catch { | |
$status = $false | |
} | |
switch ($_) { | |
"ssl2" {$RetValue.SSLv2 = $status} | |
"ssl3" {$RetValue.SSLv3 = $status} | |
"tls" {$RetValue.TLSv1_0 = $status} | |
"tls11" {$RetValue.TLSv1_1 = $status} | |
"tls12" {$RetValue.TLSv1_2 = $status} | |
} | |
# dispose objects to prevent memory leaks | |
$TcpClient.Dispose() | |
$SslStream.Dispose() | |
} | |
$RetValue | |
} | |
} | |
Test-ServerSSLSupport |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment