Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save oledid/4114469a1119ec17e4f8de4a4037e1e7 to your computer and use it in GitHub Desktop.
Save oledid/4114469a1119ec17e4f8de4a4037e1e7 to your computer and use it in GitHub Desktop.
Get thumbprint of invalid SSL cert using old powershell
$myUrl = "https://my-url-with-invalid-cert"
Function Get-SSLThumbprint {
param(
[Parameter(
Position=0,
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)
]
[Alias('FullName')]
[String]$URL
)
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class IDontCarePolicy : ICertificatePolicy {
public IDontCarePolicy() {}
public bool CheckValidationResult(
ServicePoint sPoint, X509Certificate cert,
WebRequest wRequest, int certProb) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = new-object IDontCarePolicy
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Need to connect using simple GET operation for this to work
Invoke-RestMethod -Uri $URL -Method Get | Out-Null
$ENDPOINT_REQUEST = [System.Net.Webrequest]::Create("$URL")
$SSL_THUMBPRINT = $ENDPOINT_REQUEST.ServicePoint.Certificate.GetCertHashString()
return $SSL_THUMBPRINT -replace '(..(?!$))','$1:'
}
# Example output
Get-SSLThumbprint $myUrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment