From 49e76bd87f65fccd2b765dd51cf0b598efa1d084 Mon Sep 17 00:00:00 2001 From: Andris Raugulis Date: Mon, 9 Apr 2018 17:35:07 +0300 Subject: [PATCH] Allow username, password and TOTP to be entered ineractively. --- gp-okta.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/gp-okta.py b/gp-okta.py index 6442b26..ddb3903 100755 --- a/gp-okta.py +++ b/gp-okta.py @@ -84,7 +84,7 @@ def parse_form(html): def load_conf(cf): conf = {} - keys = ['username', 'password', 'okta_url', 'vpn_url', 'totp_secret'] + keys = ['vpn_url', 'username', 'password', 'okta_url'] with io.open(cf, 'r', encoding='utf-8') as fp: for rline in fp: line = rline.strip() @@ -95,9 +95,16 @@ def load_conf(cf): if re.match('^{0}.*{0}$'.format(q), v): v = v[1:-1] conf[k] = v + if 'username' not in conf: + conf['username'] = raw_input('username: ').strip() + if 'password' not in conf: + conf['password'] = raw_input('password: ').strip() for k in keys: if k not in conf: err('missing configuration key: {0}'.format(k)) + else: + if len(conf[k].strip()) == 0: + err('empty configuration key: {0}'.format(k)) conf['debug'] = conf.get('debug', '').lower() in ['1', 'true'] return conf @@ -174,9 +181,6 @@ def okta_auth(conf, s): return session_token def okta_mfa(conf, s, j): - totp_secret = conf.get('totp_secret', '').strip() - if len(totp_secret) == 0: - err('totp_secret not defined') state_token = j.get('stateToken', '').strip() if len(state_token) == 0: err('empty state token') @@ -198,13 +202,21 @@ def okta_mfa(conf, s, j): dbg(conf.get('debug'), 'factor', factor_id, factor_type, factor_url) if factor_type != 'token:software:totp': err('factor is not totp type') - import pyotp - totp = pyotp.TOTP(totp_secret) - pass_code = totp.now() + + totp_code = None + totp_secret = conf.get('totp_secret', '').strip() + if len(totp_secret) == 0: + totp_code = raw_input('TOTP: ').strip() + if len(totp_code) == 0: + err('empty totp') + if totp_code is None: + import pyotp + totp = pyotp.TOTP(totp_secret) + totp_code = totp.now() data = { 'factorId': factor_id, 'stateToken': state_token, - 'passCode': pass_code, + 'passCode': totp_code, } log('mfa request') r = s.post(factor_url, headers=hdr_json(), data=json.dumps(data))