summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Chudnick <sam@chudnick.com>2022-07-03 05:45:04 -0400
committerSam Chudnick <sam@chudnick.com>2022-07-03 05:45:04 -0400
commit41132171e065081736c82ee283c64309e30baa9b (patch)
tree419b4a74f8f800e0e7c4c9882d21bfbdb17df6f1
parent2e580433e66fd785508ab739e7fec188ba3a0761 (diff)
Better error handling if server disconnects
-rwxr-xr-xclient/client.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/client/client.py b/client/client.py
index 1c7e155..70d85a0 100755
--- a/client/client.py
+++ b/client/client.py
@@ -14,6 +14,10 @@ DISCONNECT_MESSAGE = "BYE"
14FORMAT = "utf-8" 14FORMAT = "utf-8"
15import configparser 15import configparser
16 16
17def die(msg):
18 print(msg)
19 sys.exit(1)
20
17def parse_arguments(): 21def parse_arguments():
18 parser = argparse.ArgumentParser() 22 parser = argparse.ArgumentParser()
19 parser.add_argument("--server",type=str,help="IP of MFA Server") 23 parser.add_argument("--server",type=str,help="IP of MFA Server")
@@ -113,7 +117,10 @@ def main():
113 running = True 117 running = True
114 while running: 118 while running:
115 # Receive MFA prompt from server 119 # Receive MFA prompt from server
116 prompt_len = int(conn.recv(HEADER_LENGTH).decode(FORMAT)) 120 header = conn.recv(HEADER_LENGTH).decode(FORMAT)
121 if header == "":
122 die("error: lost connection to server")
123 prompt_len = int(header)
117 prompt = conn.recv(prompt_len).decode(FORMAT) 124 prompt = conn.recv(prompt_len).decode(FORMAT)
118 # Ask user for response 125 # Ask user for response
119 answer = prompt_user(prompt) 126 answer = prompt_user(prompt)