Skip to content

Instantly share code, notes, and snippets.

@lamw
Created May 22, 2016 13:37
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save lamw/988e4599c0f88d9fc25c9f2af8b72c92 to your computer and use it in GitHub Desktop.
Save lamw/988e4599c0f88d9fc25c9f2af8b72c92 to your computer and use it in GitHub Desktop.
Powershell snippet to help extract the SSL Thumbprint (SHA1) of a remote system
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
# 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:'
}
# vCenter Server URL
$vcurl = "https://vcenter60-1.primp-industries.com"
# Example output
Get-SSLThumbprint $vcurl
17:96:3C:50:25:C5:7E:30:1A:22:A1:B7:8D:97:39:4E:F4:F3:6A:DE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment