77import ssl
88import binascii
99import string
10+ import sys
1011from struct import *
1112import argparse
1213from pathlib import Path
1314from typing import Tuple , Dict
1415from types import FunctionType
15- from sys import exit # it prevents issues if the exit() function is invoked in the executable version
1616
17- VERSION = "1.1.7.3 "
17+ VERSION = "1.2 "
1818
1919
2020def decode_n0 (response_to_decode : bytes , head_len : int ):
@@ -748,17 +748,23 @@ def run_test(ip_addr: str, port: int, host_command: str, proto: str = "tcp", hea
748748 connection .send (message )
749749 # receive data
750750 data = connection .recv (buffer_size )
751+ connection .close ()
751752 elif proto == "tls" :
752753 # creates the TCP TLS socket
754+
755+ context = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
756+ context .load_cert_chain (certfile = args .crtfile , keyfile = args .keyfile )
757+ context .check_hostname = False
758+ context .verify_mode = ssl .CERT_NONE
753759 connection = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
754- ciphers = "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:AES128-GCM-SHA256:AES128-SHA256:HIGH:"
755- ciphers += "!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK"
756- ssl_sock = ssl .wrap_socket (connection , args .keyfile , args .crtfile )
760+ ssl_sock = context .wrap_socket (connection ,server_side = False )
761+
757762 ssl_sock .connect ((ip_addr , port ))
758763 # send message
759764 ssl_sock .send (message )
760765 # receive data
761766 data = ssl_sock .recv (buffer_size )
767+ ssl_sock .close ()
762768 elif proto == "udp" :
763769 # create the UDP socket
764770 connection = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
@@ -938,7 +944,7 @@ def common_parser(response_to_decode: bytes, head_len: int) -> Tuple[str, int, i
938944 command = args .header + 'EI2' + k_len_str + '01#0000'
939945 elif args .key < 320 or args .key > 4096 :
940946 print ("The key length value needs to be between 320 and 4096" )
941- exit ()
947+ sys . exit ()
942948 elif args .nc :
943949 command = args .header + 'NC'
944950 elif args .no :
@@ -978,7 +984,7 @@ def common_parser(response_to_decode: bytes, head_len: int) -> Tuple[str, int, i
978984 # Now we verify if the command variable is empty. In this case we throw an error.
979985 if len (command ) == 0 :
980986 print ("You forgot to specify the action you want to to perform on the payShield" )
981- exit ()
987+ sys . exit ()
982988 if args .proto == 'tls' :
983989 # check that the cert and key files are accessible
984990 if not (args .keyfile .exists () and args .crtfile .exists ()):
@@ -987,7 +993,7 @@ def common_parser(response_to_decode: bytes, head_len: int) -> Tuple[str, int, i
987993 print ("You passed these values:" )
988994 print ("Certificate file:" , args .crtfile )
989995 print ("Key file:" , args .keyfile )
990- exit ()
996+ sys . exit ()
991997 if args .port < 2500 :
992998 print ("WARNING: generally the TLS base port is 2500. You are instead using the port " ,
993999 args .port , " please check that you passed the right value to the "
0 commit comments