Last active
May 22, 2025 14:50
-
-
Save tcartwright/1cda5676a81a4cad49c1e33c4897c3eb to your computer and use it in GitHub Desktop.
Revisions
-
tcartwright revised this gist
May 22, 2025 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,6 @@ $servicePoint = $req.ServicePoint $props = $cert | Select-Object @{Name="Address"; Expression={$servicePoint.Address}}, Subject, @{Name="ValidFrom"; Expression={$_.NotBefore}}, @{Name="ValidTo"; Expression={$_.NotAfter}}, @{Name="IsValid"; Expression={$_.Verify() -and (Get-Date) -le ([DateTime]::Parse($_.GetExpirationDateString())) }}, -
tcartwright revised this gist
May 22, 2025 . 1 changed file with 46 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ #Requires -Version 7.0 Clear-Host $hostName = "www.microsoft.com" $port = 443 $tcpClient = New-Object System.Net.Sockets.TcpClient try { $tcpClient.Connect($hostName, $port) $sslStream = New-Object System.Net.Security.SslStream($tcpClient.GetStream(), $false, ({ $true })) try { $sslStream.AuthenticateAsClient($hostName) $tlsVersion = $sslStream.SslProtocol } catch { Write-Error "TLS handshake failed: $_" $tcpClient.Close() return } $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($sslStream.RemoteCertificate) $sslStream.Close() $tcpClient.Close() # Parse SAN (DNS names) from extensions $sanExtension = $cert.Extensions | Where-Object { $_.Oid.FriendlyName -eq "Subject Alternative Name" } $dnsNames = if ($sanExtension) { $sanExtension.Format($false) } else { "N/A" } $props = [PSCustomObject]@{ Address = $hostName TlsVersion = $tlsVersion Subject = $cert.Subject ValidFrom = $cert.NotBefore ValidTo = $cert.NotAfter IsValid = $cert.Verify() -and (Get-Date) -le $cert.NotAfter Encryption = $cert.SignatureAlgorithm.FriendlyName DnsNames = $dnsNames Issuer = $cert.Issuer } $props | Format-List } catch { Write-Error "Connection failed: $_" } -
tcartwright revised this gist
May 22, 2025 . 1 changed file with 12 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,10 +4,15 @@ $hostName = "www.microsoft.com" $req = [System.Net.HttpWebRequest]::Create("https://$hostName") $req.GetResponse().Dispose() $servicePoint = $req.ServicePoint [System.Security.Cryptography.X509Certificates.X509Certificate2]$cert = $servicePoint.Certificate # $servicePoint | Format-List * # $cert | Format-List * $props = $cert | Select-Object @{Name="Address"; Expression={$servicePoint.Address}}, Subject, @{Name="TlsVersion"; Expression={$servicePoint.ProtocolVersion}}, @{Name="ValidFrom"; Expression={$_.NotBefore}}, @{Name="ValidTo"; Expression={$_.NotAfter}}, @{Name="IsValid"; Expression={$_.Verify() -and (Get-Date) -le ([DateTime]::Parse($_.GetExpirationDateString())) }}, @@ -16,3 +21,7 @@ $props = $cert | Select-Object Subject, Issuer $props | Out-Host -
tcartwright revised this gist
Feb 20, 2025 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,14 +5,14 @@ $hostName = "www.microsoft.com" $req = [System.Net.HttpWebRequest]::Create("https://$hostName") $req.GetResponse().Dispose() [System.Security.Cryptography.X509Certificates.X509Certificate2]$cert = $req.ServicePoint.Certificate #$cert | Format-List * $props = $cert | Select-Object Subject, @{Name="ValidFrom"; Expression={$_.NotBefore}}, @{Name="ValidTo"; Expression={$_.NotAfter}}, @{Name="IsValid"; Expression={$_.Verify() -and (Get-Date) -le ([DateTime]::Parse($_.GetExpirationDateString())) }}, @{Name="Encryption"; Expression={$_.SignatureAlgorithm.FriendlyName}}, @{Name="DnsNames"; Expression={$_.DnsNameList.Unicode}}, Issuer $props | Out-Host -
tcartwright revised this gist
Feb 20, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ $props = $cert | Select-Object Subject, @{Name="ValidFrom"; Expression={$_.NotBefore}}, @{Name="ValidTo"; Expression={$_.NotAfter}}, @{Name="IsValid"; Expression={$_.Verify() -and (Get-Date) -le ([DateTime]::Parse($_.GetExpirationDateString())) }}, @{Name="Encryption"; Expression={$_.SignatureAlgorithm.FriendlyName}}, Issuer $props | Out-Host -
tcartwright revised this gist
Feb 20, 2025 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,12 @@ $req.GetResponse().Dispose() [System.Security.Cryptography.X509Certificates.X509Certificate2]$cert = $req.ServicePoint.Certificate $props = $cert | Select-Object Subject, @{Name="ValidFrom"; Expression={$_.NotBefore}}, @{Name="ValidTo"; Expression={$_.NotAfter}}, @{Name="IsValid"; Expression={$_.Verify() -and (Get-Date) -le ([DateTime]::Parse($_.GetExpirationDateString())) }}, @{Name="EncryptionLevel"; Expression={$_.SignatureAlgorithm.FriendlyName}}, Issuer $props | Out-Host #$cert | Format-List * -
tcartwright revised this gist
Feb 19, 2025 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,11 +4,12 @@ $hostName = "www.microsoft.com" $req = [System.Net.HttpWebRequest]::Create("https://$hostName") $req.GetResponse().Dispose() [System.Security.Cryptography.X509Certificates.X509Certificate2]$cert = $req.ServicePoint.Certificate $props = $cert | Select-Object Subject, @{Name="ValidFrom"; Expression={$_.GetEffectiveDateString()}}, @{Name="ValidTo"; Expression={$_.GetExpirationDateString()}}, @{Name="IsValid"; Expression={$_.Verify() -and (Get-Date) -le ([DateTime]::Parse($_.GetExpirationDateString())) }}, Issuer $props | Format-Table -
tcartwright created this gist
Feb 19, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ Clear-Host $hostName = "www.microsoft.com" $req = [System.Net.HttpWebRequest]::Create("https://$hostName") $req.GetResponse().Dispose() $cert = $req.ServicePoint.Certificate $props = $cert | Select-Object Subject, @{Name="ValidFrom"; Expression={$_.GetEffectiveDateString()}}, @{Name="ValidTo"; Expression={$_.GetExpirationDateString()}}, Issuer $props | Format-Table