-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckcert.ps1
35 lines (27 loc) · 1007 Bytes
/
checkcert.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
# Define the server and port
$server = "registry.fedoraproject.org"
$port = 443
# Create a TCP connection to the server
$tcpClient = New-Object System.Net.Sockets.TcpClient
$tcpClient.Connect($server, $port)
# Get the network stream
$networkStream = $tcpClient.GetStream()
# Create an SSL stream
$sslStream = New-Object System.Net.Security.SslStream($networkStream, $false, ({$true}))
# Authenticate the SSL stream
$sslStream.AuthenticateAsClient($server)
# Get the certificate
$certificate = $sslStream.RemoteCertificate
# Close the streams and TCP connection
$sslStream.Close()
$networkStream.Close()
$tcpClient.Close()
# Display the certificate details
$certificateDetails = New-Object PSObject -Property @{
Subject = $certificate.Subject
Issuer = $certificate.Issuer
Thumbprint = $certificate.Thumbprint
NotBefore = $certificate.GetEffectiveDateString()
NotAfter = $certificate.GetExpirationDateString()
}
$certificateDetails | Format-List