diff options
| author | Sam Chudnick <sam@chudnick.com> | 2022-06-30 04:25:26 -0400 |
|---|---|---|
| committer | Sam Chudnick <sam@chudnick.com> | 2022-06-30 04:25:26 -0400 |
| commit | 01c24eb1f6f6a54bb780940c7665acd280b42aaf (patch) | |
| tree | 75403dc126da5aac507985608148b59a4f5c0484 /client | |
| parent | 570d0da295f3e2fcd7b8c80ae2e6c42fc365abdd (diff) | |
Added support for TOTP
Added TOTP as an MFA option. Also made a couple of of minor changes.
Changed all database connections to use with statement. Read some
options from a config file.
Diffstat (limited to 'client')
| -rwxr-xr-x | client/client.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/client/client.py b/client/client.py index abbc9de..b2429b6 100755 --- a/client/client.py +++ b/client/client.py | |||
| @@ -14,8 +14,10 @@ FORMAT = "utf-8" | |||
| 14 | 14 | ||
| 15 | def parse_arguments(): | 15 | def parse_arguments(): |
| 16 | parser = argparse.ArgumentParser() | 16 | parser = argparse.ArgumentParser() |
| 17 | parser.add_argument("--server",type=str,help="IP of MFA Server",required=True) | 17 | parser.add_argument("--server",type=str,help="IP of MFA Server") |
| 18 | parser.add_argument("--port",type=int,help="Port to connect to",required=True) | 18 | parser.add_argument("--port",type=int,help="Port to connect to") |
| 19 | parser.add_argument("--config",type=str,help="Path to config file",\ | ||
| 20 | default="/etc/mfa/mfa.conf") | ||
| 19 | parser.add_argument("--key",type=str,help="Client connection key",required=True) | 21 | parser.add_argument("--key",type=str,help="Client connection key",required=True) |
| 20 | return parser.parse_args() | 22 | return parser.parse_args() |
| 21 | 23 | ||
| @@ -50,13 +52,34 @@ def init_connection(mfa_server, client_port, client_key): | |||
| 50 | return connection | 52 | return connection |
| 51 | 53 | ||
| 52 | 54 | ||
| 55 | def read_config(config_file): | ||
| 56 | # Read config file for server and port info | ||
| 57 | # Return tuple (server,port) | ||
| 58 | server = "" | ||
| 59 | port = 0 | ||
| 60 | with open(config_file) as conf: | ||
| 61 | line = None | ||
| 62 | while line != "": | ||
| 63 | line = conf.readline() | ||
| 64 | if line.startswith("server ="): | ||
| 65 | server = line.split("=")[1].strip() | ||
| 66 | if line.startswith("port ="): | ||
| 67 | port = int(line.split("=")[1].strip()) | ||
| 68 | return (server,port) | ||
| 69 | |||
| 53 | def main(): | 70 | def main(): |
| 54 | # Get arguments, exit if unable to connect | 71 | # Get arguments, exit if unable to connect |
| 55 | args = parse_arguments() | 72 | args = parse_arguments() |
| 56 | mfa_server = args.server | ||
| 57 | client_port = args.port | ||
| 58 | client_key = args.key | 73 | client_key = args.key |
| 59 | 74 | ||
| 75 | # Read server and port from config file but allow command line options | ||
| 76 | # to override those settings | ||
| 77 | mfa_server, client_port = read_config(args.config) | ||
| 78 | if args.server != None: | ||
| 79 | mfa_server = args.server | ||
| 80 | if args.port != None: | ||
| 81 | client_port = args.port | ||
| 82 | |||
| 60 | # Exit if invalid key is provided | 83 | # Exit if invalid key is provided |
| 61 | if len(client_key) != KEY_LENGTH: | 84 | if len(client_key) != KEY_LENGTH: |
| 62 | print("invalid key") | 85 | print("invalid key") |
