def validate_yubikey_otp(self, params):
vres = {}<EOL>from_key = params["<STR_LIT>"][<NUM_LIT:0>]<EOL>if not re.match(ykotp_valid_input, from_key):<EOL><INDENT>self.log_error("<STR_LIT>" % (from_key))<EOL>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>vres["<STR_LIT>"] = from_key<EOL><DEDENT>if not "<STR_LIT>" in params:<EOL><INDENT>self.log_error("<STR_LIT>" % (from_key))<EOL>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>nonce = params["<STR_LIT>"][<NUM_LIT:0>]<EOL>if len(nonce) < <NUM_LIT:16> or len(nonce) > <NUM_LIT>:<EOL><INDENT>self.log_error("<STR_LIT>" % (from_key, nonce))<EOL>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>vres["<STR_LIT>"] = nonce<EOL><DEDENT><DEDENT>if "<STR_LIT>" in params and not (params["<STR_LIT>"] == "<STR_LIT:100>" or params["<STR_LIT>"] == "<STR_LIT>"):<EOL><INDENT>self.log_error("<STR_LIT>" % (from_key))<EOL>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL><DEDENT>sig, client_key, = check_signature(params)<EOL>if sig != True:<EOL><INDENT>self.log_error("<STR_LIT>" % (from_key))<EOL>if client_key == None:<EOL><INDENT>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL>client_key = chr(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL><DEDENT><DEDENT>if "<STR_LIT:status>" not in vres:<EOL><INDENT>try:<EOL><INDENT>res = pyhsm.yubikey.validate_otp(hsm, from_key)<EOL>vres.update({"<STR_LIT:status>": "<STR_LIT:OK>",<EOL>"<STR_LIT>": str(res.use_ctr), <EOL>"<STR_LIT>": str(res.session_ctr), <EOL>"<STR_LIT>": str((res.ts_high << <NUM_LIT:16> | res.ts_low) / <NUM_LIT:8>)<EOL>}<EOL>)<EOL>if "<STR_LIT>" in params:<EOL><INDENT>vres["<STR_LIT>"] = "<STR_LIT:100>"<EOL>if "<STR_LIT>" in params:<EOL><INDENT>vres["<STR_LIT:t>"] = time.strftime("<STR_LIT>", time.gmtime())<EOL><DEDENT><DEDENT><DEDENT>except pyhsm.exception.YHSM_CommandFailed as e:<EOL><INDENT>if e.status == pyhsm.defines.YSM_ID_NOT_FOUND:<EOL><INDENT>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL><DEDENT>elif e.status == pyhsm.defines.YSM_OTP_REPLAY:<EOL><INDENT>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL><DEDENT>elif e.status == pyhsm.defines.YSM_OTP_INVALID:<EOL><INDENT>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>vres["<STR_LIT:status>"] = "<STR_LIT>"<EOL><DEDENT>self.log_error("<STR_LIT>" % (from_key, pyhsm.defines.status2str(e.status), vres["<STR_LIT:status>"]))<EOL><DEDENT><DEDENT>return make_otp_response(vres, client_key)<EOL>
Validate YubiKey OTP using YubiHSM internal database.