def getInitDetail(self, params , user=None): ''' to complete the token normalisation, the response of the initialiastion should be build by the token specific method, the getInitDetails ''' response_detail = {} info = self.getInfo() response_detail.update(info) response_detail['serial'] = self.getSerial() tok_type = self.type.lower() otpkey = None if 'otpkey' in info: otpkey = info.get('otpkey') if otpkey != None: response_detail["otpkey"] = { "order" : '1', "description": _("OTP seed"), "value" : "seed://%s" % otpkey, "img" : create_img(otpkey, width=200), } try: p = {} p.update(params) p['otpkey'] = otpkey p['serial'] = self.getSerial() # label goo_url = create_google_authenticator(p, user=user, context=self.context) response_detail["googleurl"] = { "order" : '0', "description": _("OTPAuth Url"), "value" : goo_url, "img" : create_img(goo_url, width=250) } except NoOtpAuthTokenException as exx: log.warning("%r" % exx) if user is not None: try: oath_url = create_oathtoken_url(user.login, user.realm, otpkey, tok_type, serial=self.getSerial(), context=self.context) response_detail["oathurl"] = { "order" : '2', "description" : _("URL for OATH token"), "value" : oath_url, "img" : create_img(oath_url, width=250) } except Exception as ex: log.info('failed to set oath or google url: %r' % ex) return response_detail
def getInitDetail(self, params, user=None): ''' to complete the token normalisation, the response of the initialiastion should be build by the token specific method, the getInitDetails ''' response_detail = {} info = self.getInfo() response_detail.update(info) response_detail['serial'] = self.getSerial() tok_type = self.type.lower() otpkey = None if 'otpkey' in info: otpkey = info.get('otpkey') if otpkey != None: response_detail["otpkey"] = { "order": '1', "description": _("OTP seed"), "value": "seed://%s" % otpkey, "img": create_img(otpkey, width=200), } try: p = {} p.update(params) p['otpkey'] = otpkey p['serial'] = self.getSerial() # label goo_url = create_google_authenticator(p, user=user) response_detail["googleurl"] = { "order": '0', "description": _("OTPAuth Url"), "value": goo_url, "img": create_img(goo_url, width=250) } except NoOtpAuthTokenException as exx: log.warning("%r" % exx) if user is not None: try: oath_url = create_oathtoken_url(user.login, user.realm, otpkey, tok_type, serial=self.getSerial()) response_detail["oathurl"] = { "order": '2', "description": _("URL for OATH token"), "value": oath_url, "img": create_img(oath_url, width=250) } except Exception as ex: log.info('failed to set oath or google url: %r' % ex) return response_detail
def test_token_label_issuer_policy(self, mock__get_client, mock_has_client_policy, mock_get_action_value): """Google Authenticator url with issuer and label policy set with this empty setting - the tokenissuer should become 'LinOTP' and - the tokenlabel should become the serial """ mock__get_client.return_value = "localhost" mock_has_client_policy.return_value = {} mock_get_action_value.return_value = "<d>.<r>.<u>.<s>" param = { "hashlib": "SHA1", "otpkey": "cc5bad98a76279171a08a5d18fd400e748945c2b", "serial": "TOTP1234", "otplen": "6", "type": "totp", "timeStep": "30", } url = create_google_authenticator(param=param) assert url.startswith("otpauth://totp/...TOTP1234:...TOTP1234?") # verify that the totp / hotp defaults are not in the url assert "SHA1" not in url assert "period" not in url assert "digits" not in url param["user.login"] = "******" url = create_google_authenticator(param=param) msg = "otpauth://totp/..hugo.TOTP1234:..hugo.TOTP1234?" assert url.startswith(msg) param["user.realm"] = "realm" url = create_google_authenticator(param=param) msg = "otpauth://totp/.realm.hugo.TOTP1234:.realm.hugo.TOTP1234?" assert url.startswith(msg) param["description"] = "descr:ption" url = create_google_authenticator(param=param) msg = ("otpauth://totp/descr%3Aption.realm.hugo.TOTP1234:" "descr%3Aption.realm.hugo.TOTP1234?") assert url.startswith(msg)
def test_token_label_issuer_default(self, mock__get_client, mock_has_client_policy, mock_get_action_value): """Google Authenticator url with default issuer and label with this empty setting - the tokenissuer should become 'LinOTP' and - the tokenlabel should become the serial using hmac non defaults: SHA256, 8 digits """ mock__get_client.return_value = "localhost" mock_has_client_policy.return_value = {} mock_get_action_value.return_value = "" param = { "hashlib": "SHA256", "otpkey": "cc5bad98a76279171a08a5d18fd400e748945c2b", "serial": "HOTP1234", "otplen": "8", "type": "hmac", } url = create_google_authenticator(param=param) assert url.startswith("otpauth://hotp/LinOTP:HOTP1234?") assert "counter=0" in url assert "digits=8" in url assert "algorithm=SHA256" in url param["user.login"] = "******" url = create_google_authenticator(param=param) assert url.startswith("otpauth://hotp/LinOTP:hugo?") param["user.realm"] = "realm" url = create_google_authenticator(param=param) assert url.startswith("otpauth://hotp/LinOTP:hugo?") param["description"] = "description" url = create_google_authenticator(param=param) assert url.startswith("otpauth://hotp/LinOTP:hugo?")
def getInitDetail(self, params, user=None): """ to complete the token normalisation, the response of the initialiastion should be build by the token specific method, the getInitDetails """ response_detail = {} info = self.getInfo() response_detail.update(info) response_detail["serial"] = self.getSerial() tok_type = self.type.lower() otpkey = None if "otpkey" in info: otpkey = info.get("otpkey") if otpkey is not None: response_detail["otpkey"] = { "order": "1", "description": _("OTP seed"), "value": "seed://%s" % otpkey, "img": create_img(otpkey, width=200), } try: p = {} p.update(params) p["otpkey"] = otpkey p["serial"] = self.getSerial() # label goo_url = create_google_authenticator(p, user=user) response_detail["googleurl"] = { "order": "0", "description": _("OTPAuth Url"), "value": goo_url, "img": create_img(goo_url, width=250), } except NoOtpAuthTokenException as exx: log.warning(exx) oath_support = getFromConfig("OATHTokenSupport", "False") == "True" if oath_support: if user is not None: try: oath_url = create_oathtoken_url( user.login, user.realm, otpkey, tok_type, serial=self.getSerial(), ) response_detail["oathurl"] = { "order": "2", "description": _("URL for OATH token"), "value": oath_url, "img": create_img(oath_url, width=250), } except Exception as ex: log.info("failed to set oath or google url: %r", ex) return response_detail