-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-WebCertificate.ps1
48 lines (43 loc) · 1.5 KB
/
Get-WebCertificate.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function Get-WebCertificate {
<#
.SYNOPSIS
returns infos about a web certificate
.PARAMETER URI
defines the URI to request
this string parameter is mandatory
.EXAMPLE
Get-WebCertificate -URI 'https://www.google.com'
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$URI
)
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 do simple GET connection for this method to work
Invoke-RestMethod -Uri $URI -Method Get | Out-Null
$endpoint_request = [System.Net.Webrequest]::Create($URI)
# Get Thumbprint + add colons for a valid Thumbprint
$Certificate = $endpoint_request.ServicePoint.Certificate
$Thumbprint = ($endpoint_request.ServicePoint.Certificate.GetCertHashString()) -replace '(..(?!$))','$1:'
$ret = [PSCustomObject]@{
Issuer = $Certificate.Issuer
Subject = $Certificate.Subject
Thumbprint = $Thumbprint
Handle = $Certificate.Handle
}
return $ret
}