diff options
author | Sam Chudnick <sam@chudnick.com> | 2023-06-11 08:14:22 -0400 |
---|---|---|
committer | Sam Chudnick <sam@chudnick.com> | 2023-06-11 08:14:22 -0400 |
commit | ceddd0cb74f4404b8d743c3fce011c2c9fda4f32 (patch) | |
tree | c58275596621d7278d5b7c84c514be437a985c43 | |
parent | f8527f77547ef8c2bd1f94633672b674d4920f88 (diff) |
Wrap client loop in try catch block
-rwxr-xr-x | client/client.py | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/client/client.py b/client/client.py index 0388073..bc4da96 100755 --- a/client/client.py +++ b/client/client.py | |||
@@ -166,20 +166,27 @@ def main(): | |||
166 | # Main loop | 166 | # Main loop |
167 | running = True | 167 | running = True |
168 | while running: | 168 | while running: |
169 | # Receive MFA prompt from server | 169 | try: |
170 | header = conn.recv(HEADER_LENGTH).decode(FORMAT) | 170 | # Receive MFA prompt from server |
171 | if header == "": | 171 | header = conn.recv(HEADER_LENGTH).decode(FORMAT) |
172 | die("error: lost connection to server") | 172 | if header == "": |
173 | prompt_len = int(header) | 173 | die("error: lost connection to server") |
174 | prompt = conn.recv(prompt_len).decode(FORMAT) | 174 | prompt_len = int(header) |
175 | # Ask user for response | 175 | prompt = conn.recv(prompt_len).decode(FORMAT) |
176 | answer = prompt_user(prompt) | 176 | # Ask user for response |
177 | # Send answer to MFA server | 177 | answer = prompt_user(prompt) |
178 | answer_length = len(answer) | 178 | # Send answer to MFA server |
179 | length_msg = str(answer_length) | 179 | length_msg = str(len(answer)) |
180 | length_msg += ' ' * (HEADER_LENGTH - len(length_msg)) | 180 | # Handle very large input |
181 | conn.send(length_msg.encode(FORMAT)) | 181 | if len(length_msg) > HEADER_LENGTH: |
182 | conn.send(answer.encode(FORMAT)) | 182 | die("error: response too big") |
183 | length_msg += ' ' * (HEADER_LENGTH - len(length_msg)) | ||
184 | conn.send(length_msg.encode(FORMAT)) | ||
185 | conn.send(answer.encode(FORMAT)) | ||
186 | except KeyboardInterrupt: | ||
187 | #conn.send(DISCONNECT_MESSAGE.encode(FORMAT)) | ||
188 | conn.close() | ||
189 | die("") | ||
183 | 190 | ||
184 | 191 | ||
185 | 192 | ||