Fix auto-migrated code
- Use b'' (byte strings) where appropriate. - Fix indentation. - Replace python2.x references with python3.x.
This commit is contained in:
parent
5f02223ec7
commit
b2a01c15b0
4 changed files with 34 additions and 29 deletions
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
PYTHON = python2.7
|
||||
PYTHON = python3.8
|
||||
|
||||
.PHONY: test pre-clean clean
|
||||
|
||||
|
|
|
@ -658,7 +658,7 @@ def sort_recipients( raw_message, from_addr, to_addrs ):
|
|||
return
|
||||
|
||||
first_payload = first_payload.get_payload(decode=True)
|
||||
if "-----BEGIN PGP MESSAGE-----" in first_payload and "-----END PGP MESSAGE-----" in first_payload:
|
||||
if b"-----BEGIN PGP MESSAGE-----" in first_payload and b"-----END PGP MESSAGE-----" in first_payload:
|
||||
if verbose:
|
||||
log("Message is already encrypted as PGP/INLINE. Encryption aborted.")
|
||||
send_msg(raw_message.as_string(), recipients_left)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/local/bin/python2
|
||||
#!/usr/local/bin/python3.8
|
||||
|
||||
#
|
||||
# gpg-mailgate
|
||||
|
@ -32,7 +32,7 @@ from time import sleep
|
|||
RELAY_SCRIPT = "test/relay.py"
|
||||
CONFIG_FILE = "test/gpg-mailgate.conf"
|
||||
|
||||
PYTHON_BIN = "python2.7"
|
||||
PYTHON_BIN = "python3.8"
|
||||
|
||||
def build_config(config):
|
||||
cp = configparser.ConfigParser()
|
||||
|
@ -55,7 +55,7 @@ def build_config(config):
|
|||
cp.set("enc_keymap", "alice@disposlab", "1CD245308F0963D038E88357973CF4D9387C44D7")
|
||||
cp.set("enc_keymap", "bob@disposlab", "19CF4B47ECC9C47AFA84D4BD96F39FDA0E31BB67")
|
||||
|
||||
logging.debug("Created config with keyhome=%s, cert_path=%s and relay at port %d" %
|
||||
logging.debug("Created config with keyhome=%s, cert_path=%s and relay at port %s" %
|
||||
(config["gpg_keyhome"], config["smime_certpath"], config["port"]))
|
||||
return cp
|
||||
|
||||
|
@ -128,14 +128,14 @@ logging.basicConfig(filename = config.get("tests", "e2e_log"),
|
|||
# Get raw values of log and date formats because they
|
||||
# contain %-sequences and we don't want them to be expanded
|
||||
# by the ConfigParser.
|
||||
format = config.get("tests", "e2e_log_format", True),
|
||||
datefmt = config.get("tests", "e2e_log_datefmt", True),
|
||||
format = config.get("tests", "e2e_log_format", raw=True),
|
||||
datefmt = config.get("tests", "e2e_log_datefmt", raw=True),
|
||||
level = logging.DEBUG)
|
||||
|
||||
config_path = os.getcwd() + "/" + CONFIG_FILE
|
||||
|
||||
write_test_config(config_path,
|
||||
port = config.getint("relay", "port"),
|
||||
port = config.get("relay", "port"),
|
||||
gpg_keyhome = config.get("dirs", "keys"),
|
||||
smime_certpath = config.get("dirs", "certs"),
|
||||
log_file = config.get("tests", "lacre_log"))
|
||||
|
|
|
@ -14,38 +14,43 @@ import socket
|
|||
|
||||
EXIT_UNAVAILABLE = 1
|
||||
|
||||
ENCODING = 'utf-8'
|
||||
|
||||
BUFFER_SIZE = 4096
|
||||
EOM = "\r\n.\r\n"
|
||||
LAST_LINE = -3
|
||||
|
||||
|
||||
def welcome(msg):
|
||||
return "220 %s\r\n" % (msg)
|
||||
return b"220 %b\r\n" % (msg)
|
||||
|
||||
def ok(msg = "OK"):
|
||||
return "250 %s\r\n" % (msg)
|
||||
def ok(msg = b"OK"):
|
||||
return b"250 %b\r\n" % (msg)
|
||||
|
||||
def bye():
|
||||
return "251 Bye"
|
||||
return b"251 Bye"
|
||||
|
||||
def provide_message():
|
||||
return "354 Enter a message, ending it with a '.' on a line by itself\r\n"
|
||||
return b"354 Enter a message, ending it with a '.' on a line by itself\r\n"
|
||||
|
||||
def receive_and_confirm(session):
|
||||
session.recv(BUFFER_SIZE)
|
||||
session.sendall(ok())
|
||||
|
||||
def localhost_at(port):
|
||||
return ('127.0.0.1', port)
|
||||
|
||||
def serve(port):
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
s.bind(('', port))
|
||||
s.bind(localhost_at(port))
|
||||
s.listen(1)
|
||||
except socket.error as e:
|
||||
print("Cannot connect", e)
|
||||
sys.exit(EXIT_UNAVAILABLE)
|
||||
|
||||
(conn, addr) = s.accept()
|
||||
conn.sendall(welcome("TEST SERVER"))
|
||||
conn.sendall(welcome(b"TEST SERVER"))
|
||||
|
||||
receive_and_confirm(conn) # Ignore HELO/EHLO
|
||||
receive_and_confirm(conn) # Ignore sender address
|
||||
|
@ -57,8 +62,8 @@ def serve(port):
|
|||
# Consume until we get <CR><LF>.<CR><LF>, the end-of-message marker.
|
||||
message = ''
|
||||
while not message.endswith(EOM):
|
||||
message += conn.recv(BUFFER_SIZE)
|
||||
conn.sendall(ok("OK, id=test"))
|
||||
message += conn.recv(BUFFER_SIZE).decode(ENCODING)
|
||||
conn.sendall(ok(b"OK, id=test"))
|
||||
|
||||
conn.recv(BUFFER_SIZE)
|
||||
conn.sendall(bye())
|
||||
|
@ -68,13 +73,13 @@ def serve(port):
|
|||
# Trim EOM marker as we're only interested in the message body.
|
||||
return message[:-len(EOM)]
|
||||
|
||||
def error(msg):
|
||||
def error(msg, exit_code):
|
||||
print("ERROR: %s" % (msg))
|
||||
sys.exit(1)
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
error("Usage: relay.py PORT_NUMBER")
|
||||
error("Usage: relay.py PORT_NUMBER", EXIT_UNAVAILABLE)
|
||||
|
||||
port = int(sys.argv[1])
|
||||
body = serve(port)
|
||||
|
|
Loading…
Reference in a new issue