Skip to content

Commit 5a3d162

Browse files
committed
Switch to pyOpenSSL for certificate retrieval
1 parent 8d5c574 commit 5a3d162

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

ssl-cert-parse.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@
22

33

44
import datetime
5-
import ssl
65
import OpenSSL
6+
import socket
77

88

99
def GetCert(SiteName, Port):
1010
'''Connect to the specified host and get the certificate file'''
11-
return ssl.get_server_certificate((SiteName, Port))
11+
Client = socket.socket()
12+
Client.connect((SiteName, Port))
13+
14+
ClientSSL = OpenSSL.SSL.Connection(OpenSSL.SSL.Context(
15+
OpenSSL.SSL.SSLv3_METHOD), Client)
16+
ClientSSL.set_connect_state()
17+
ClientSSL.do_handshake()
18+
19+
CertDataRaw = str(OpenSSL.crypto.dump_certificate(
20+
OpenSSL.crypto.FILETYPE_PEM,
21+
ClientSSL.get_peer_certificate()))[2:-1]
22+
CertData = CertDataRaw.split('\\n')
23+
Cert = ""
24+
25+
for line in CertData:
26+
Cert += line + '\n'
27+
28+
return Cert
1229

1330

1431
def ParseCert(CertRaw):

0 commit comments

Comments
 (0)