def provision(p, args): request = vp.generate_request(token_model=args.token_model) response = vp.get_provisioning_response(request) otp_token = vp.get_token_from_response(response.content) otp_secret = vp.decrypt_key(otp_token['iv'], otp_token['cipher']) otp_secret_b64 = base64.b32encode(otp_secret).upper() if not vp.check_token(otp_token['id'], otp_secret): sys.stderr.write("Something went wrong--the token is invalid.\n") sys.exit(1) if args.print: otp_uri = vp.generate_otp_uri(otp_token['id'], otp_secret) print('Credential created successfully:\n\t' + otp_uri) print("This credential expires on this date: " + otp_token['expiry']) print('\nYou will need the ID to register this credential: ' + otp_token['id']) print('\nYou can use oathtool to generate the same OTP codes') print('as would be produced by the official VIP Access apps:\n') print(' oathtool -d6 -b --totp {} # 6-digit code'''.format(otp_secret_b64)) print(' oathtool -d6 -b --totp -v {} # ... with extra information'''.format(otp_secret_b64)) else: os.umask(0o077) # stoken does this too (security) with open(os.path.expanduser(args.dotfile), "wx") as dotfile: dotfile.write('version 1\n') dotfile.write('secret %s\n' % otp_secret_b64) dotfile.write('id %s\n' % otp_token['id']) dotfile.write('expiry %s\n' % otp_token['expiry']) print('Credential created and saved successfully: ' + dotfile.name) print('You will need the ID to register this credential: ' + otp_token['id'])
def provision(p, args): request = vp.generate_request(token_model=args.token_model) response = vp.get_provisioning_response(request) otp_token = vp.get_token_from_response(response.content) otp_secret = vp.decrypt_key(otp_token['iv'], otp_token['cipher']) otp_secret_b32 = base64.b32encode(otp_secret).upper().decode('ascii') if not vp.check_token(otp_token['id'], otp_secret): print("WARNING: Something went wrong--the token could not be validated.", " (check that your system time is set correctly)\n", file=sys.stderr) if args.print: otp_uri = vp.generate_otp_uri(otp_token['id'], otp_secret) print('Credential created successfully:\n\t' + otp_uri) print("This credential expires on this date: " + otp_token['expiry']) print('\nYou will need the ID to register this credential: ' + otp_token['id']) print('\nYou can use oathtool to generate the same OTP codes') print('as would be produced by the official VIP Access apps:\n') print(' oathtool -d6 -b --totp {} # 6-digit code'''.format(otp_secret_b32)) print(' oathtool -d6 -b --totp -v {} # ... with extra information'''.format(otp_secret_b32)) else: os.umask(0o077) # stoken does this too (security) with open(os.path.expanduser(args.dotfile), EXCL_WRITE) as dotfile: dotfile.write('version 1\n') dotfile.write('secret %s\n' % otp_secret_b32) dotfile.write('id %s\n' % otp_token['id']) dotfile.write('expiry %s\n' % otp_token['expiry']) print('Credential created and saved successfully: ' + dotfile.name) print('You will need the ID to register this credential: ' + otp_token['id'])
def provision(p, args): print("Generating request...") request = vp.generate_request(token_model=args.token_model) print("Fetching provisioning response from Symantec server...") session = vp.requests.Session() response = vp.get_provisioning_response(request, session) print("Getting token from response...") otp_token = vp.get_token_from_response(response.content) print("Decrypting token...") otp_secret = vp.decrypt_key(otp_token['iv'], otp_token['cipher']) otp_secret_b32 = base64.b32encode(otp_secret).upper().decode('ascii') print("Checking token against Symantec server...") if not vp.check_token(otp_token, otp_secret, session): p.error( "Something went wrong--the token could not be validated.\n" " (Check your system time; it differs from the server's by %d seconds)\n" % otp_token['timeskew']) elif 'period' in otp_token and otp_token[ 'timeskew'] > otp_token['period'] / 10: p.error( "Your system time differs from the server's by %d seconds;\n" " The offset would be 'baked in' to the newly-created token.\n" " Fix system time and try again." % otp_token['timeskew']) if args.print: otp_uri = vp.generate_otp_uri(otp_token, otp_secret, args.issuer) print('Credential created successfully:\n\t' + otp_uri) print("This credential expires on this date: " + otp_token['expiry']) print('\nYou will need the ID to register this credential: ' + otp_token['id']) if otp_token['period'] is not None and otp_token['counter'] is None: print('\nYou can use oathtool to generate the same OTP codes') print('as would be produced by the official VIP Access apps:\n') d = '-d{} '.format( otp_token['digits']) if otp_token['digits'] != 6 else '' s = '-s{} '.format( otp_token['period']) if otp_token['period'] != 30 else '' print(' oathtool {}{}-b --totp {} # output one code' ''.format(d, s, otp_secret_b32)) print( ' oathtool -v {}{}-b --totp {} # ... with extra information' ''.format(d, s, otp_secret_b32)) elif otp_token['digits'] == 6 and otp_token[ 'algorithm'] == 'sha1' and otp_token['period'] == 30: os.umask(0o077) # stoken does this too (security) with open(os.path.expanduser(args.dotfile), EXCL_WRITE) as dotfile: dotfile.write('version 1\n') dotfile.write('secret %s\n' % otp_secret_b32) dotfile.write('id %s\n' % otp_token['id']) dotfile.write('expiry %s\n' % otp_token['expiry']) print('Credential created and saved successfully: ' + dotfile.name) print('You will need the ID to register this credential: ' + otp_token['id']) else: p.error('Cannot currently save a token of this type (try -p to print)')
def provision(p, args): print("Generating request...") request = vp.generate_request(token_model=args.token_model) print("Fetching provisioning response...") session = vp.requests.Session() response = vp.get_provisioning_response(request, session) print("Getting token from response...") otp_token = vp.get_token_from_response(response.content) print("Decrypting token...") otp_secret = vp.decrypt_key(otp_token['iv'], otp_token['cipher']) otp_secret_b32 = base64.b32encode(otp_secret).upper().decode('ascii') print("Checking token...") if not vp.check_token(otp_token['id'], otp_secret, session): print("WARNING: Something went wrong--the token could not be validated.\n", " (check your system time; it differs from the server's by %d seconds)\n" % otp_token['timeskew'], file=sys.stderr) if args.print: otp_uri = vp.generate_otp_uri(otp_token, otp_secret) print('Credential created successfully:\n\t' + otp_uri) print("This credential expires on this date: " + otp_token['expiry']) print('\nYou will need the ID to register this credential: ' + otp_token['id']) if otp_token['id'].startswith('VSMB'): otp_secret_hex = vp.decode_secret_hex(otp_secret) print('Secret in HEX for Yubikey: '+ otp_secret_hex) else: print('\nYou can use oathtool to generate the same OTP codes') print('as would be produced by the official VIP Access apps:\n') print(' Token is Time based TOTP Token') print(' oathtool -d6 -b --totp {} # 6-digit code'''.format(otp_secret_b32)) print(' oathtool -d6 -b --totp -v {} # ... with extra information'''.format(otp_secret_b32)) print('Generating QR Code') print('File will be saved as: ' + otp_token['id'] + '.jpg') qr_image = vp.generate_qr_code(otp_uri) qr_file = otp_token['id']+'.jpg' qr_image.save(qr_file) else: assert otp_token['digits'] == 6 assert otp_token['algorithm'] == 'sha1' if not otp_token['id'].startswith('VSMB'): assert otp_token['period'] == 30 os.umask(0o077) # stoken does this too (security) with open(os.path.expanduser(args.dotfile), EXCL_WRITE) as dotfile: dotfile.write('version 1\n') dotfile.write('secret %s\n' % otp_secret_b32) dotfile.write('id %s\n' % otp_token['id']) dotfile.write('expiry %s\n' % otp_token['expiry']) if otp_token['id'].startswith('VSMB'): # increase counter because we used 2 to test token dotfile.write('count 2') print('Credential created and saved successfully: ' + dotfile.name) print('You will need the ID to register this credential: ' + otp_token['id'])