Skip to content

Commit

Permalink
Restructure function
Browse files Browse the repository at this point in the history
  • Loading branch information
narbehaj committed Oct 3, 2023
1 parent 817f66e commit 86fd438
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions ssl_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,14 @@ class SSLChecker:
total_failed = 0
total_warning = 0

def get_cert(self, host, port, user_args):
def get_cert(self, host, port, socks_host=None, socks_port=None):
"""Connection to the host."""
if user_args.socks:
if socks_host:
import socks
if user_args.verbose:
print('{}Socks proxy enabled{}\n'.format(Clr.YELLOW, Clr.RST))

socks_host, socks_port = self.filter_hostname(user_args.socks)
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, socks_host, int(socks_port), True)
socket.socket = socks.socksocket

if user_args.verbose:
print('{}Connecting to socket{}\n'.format(Clr.YELLOW, Clr.RST))

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
osobj = SSL.Context(SSL.TLSv1_2_METHOD)
sock.connect((host, int(port)))
Expand All @@ -55,8 +49,6 @@ def get_cert(self, host, port, user_args):
oscon.do_handshake()
cert = oscon.get_peer_certificate()
sock.close()
if user_args.verbose:
print('{}Closing socket{}\n'.format(Clr.YELLOW, Clr.RST))

return cert

Expand Down Expand Up @@ -235,7 +227,16 @@ def show_result(self, user_args):
continue

try:
cert = self.get_cert(host, port, user_args)
# Check if socks should be used
if user_args.socks:
if user_args.verbose:
print('{}Socks proxy enabled, connecting via proxy{}\n'.format(Clr.YELLOW, Clr.RST))

socks_host, socks_port = self.filter_hostname(user_args.socks)
cert = self.get_cert(host, port, socks_host, socks_port)
else:
cert = self.get_cert(host, port)

context[host] = self.get_cert_info(host, cert)
context[host]['tcp_port'] = int(port)

Expand Down

0 comments on commit 86fd438

Please sign in to comment.