Skip to content

Commit f2c7bb1

Browse files
mszeuMarco Simone Zuppone
andauthored
Dev (#22)
* new branch * Using the new and reccomendend SSLContext * fixed exit() importing the full sys library and calling explicitly sys.exit() * socket explicitly closed after connection. README.md updated * README.md updated * Update README.md * Update README.md * README.md updated --------- Co-authored-by: Marco Simone Zuppone <m.zuppone@computer.org>
1 parent 0afe043 commit f2c7bb1

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ It requires **Python 3**. It was tested on **Python 3.7**, **3.8** and **3.9** u
1818

1919
## Version
2020

21-
**1.1.7.2**
21+
**1.2**
2222

2323
## Usage
2424

@@ -68,7 +68,9 @@ Use the parameters **--ecc-curve**, **--key-use** and **--key-exportability** to
6868

6969
**--proto** specifies the protocol to use, **tcp**, **udp** or **tls**, if omitted the default value **tcp**
7070
is used.
71-
If **tls** is used you might specify the path of the client key file and the certificate using the parameters **--keyfile** and **--crtfile**.
71+
If **tls** is used you might specify the path of the client key file and the certificate using the parameters
72+
**--keyfile** and **--crtfile**.
73+
No verifications are performed about the validity of certificates.
7274

7375
**--keyfile** the path of the client key file, if is not specified the default value is **client.key**.
7476
It's only considered if the protocol is **tls**.
@@ -109,7 +111,7 @@ The possible choices are:
109111

110112
C:\Test>python pressureTest.py 192.168.0.36 --nc --times 2
111113

112-
PayShield stress utility, version 1.1.5, by Marco S. Zuppone - msz@msz.eu - https://msz.eu
114+
PayShield stress utility, version 1.2, by Marco S. Zuppone - msz@msz.eu - https://msz.eu
113115
To get more info about the usage invoke it with the -h option This software is open source, and it is under the Affero
114116
AGPL 3.0 license
115117

@@ -144,7 +146,7 @@ Depending on the firmware version the functionality may require a license and/or
144146
Please refer to the **LICENSE** file that is part of this project.
145147
The license is **[AGPL 3.0](https://www.gnu.org/licenses/agpl-3.0.en.html)**
146148

147-
Copyright(C) 2020-2021 **Marco S. Zuppone** - **msz@msz.eu** - [https://msz.eu](https://msz.eu)
149+
Copyright(C) 2020-2023 **Marco S. Zuppone** - **msz@msz.eu** - [https://msz.eu](https://msz.eu)
148150

149151
This program is free software: you can redistribute it and/or modify
150152
it under the terms of the GNU Affero General Public License as

pressureTest.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
import ssl
88
import binascii
99
import string
10+
import sys
1011
from struct import *
1112
import argparse
1213
from pathlib import Path
1314
from typing import Tuple, Dict
1415
from 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

2020
def 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

Comments
 (0)