def validate_oath_hotp(self, params):
from_key = params["<STR_LIT>"][<NUM_LIT:0>]<EOL>if not re.match(hotp_valid_input, from_key):<EOL><INDENT>self.log_error("<STR_LIT>" % (params))<EOL>return "<STR_LIT>"<EOL><DEDENT>uid, otp, = get_oath_hotp_bits(params)<EOL>if not uid or not otp:<EOL><INDENT>self.log_error("<STR_LIT>" % (params, uid, otp))<EOL>return "<STR_LIT>"<EOL><DEDENT>if args.debug:<EOL><INDENT>print("<STR_LIT>" % (uid, otp))<EOL><DEDENT>try:<EOL><INDENT>db = ValOathDb(args.db_file)<EOL>entry = db.get(uid)<EOL><DEDENT>except Exception as e:<EOL><INDENT>self.log_error("<STR_LIT>" % (params, e))<EOL>return "<STR_LIT>"<EOL><DEDENT>nonce = entry.data["<STR_LIT>"].decode('<STR_LIT>')<EOL>aead = entry.data["<STR_LIT>"].decode('<STR_LIT>')<EOL>new_counter = pyhsm.oath_hotp.search_for_oath_code(hsm, entry.data["<STR_LIT>"], nonce, aead,entry.data["<STR_LIT>"], otp, args.look_ahead)<EOL>if args.debug:<EOL><INDENT>print("<STR_LIT>"% (entry.data["<STR_LIT>"], entry.data["<STR_LIT>"] + args.look_ahead, new_counter))<EOL><DEDENT>if type(new_counter) != int:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT>try:<EOL><INDENT>if db.update_oath_hotp_c(entry, new_counter):<EOL><INDENT>return "<STR_LIT>" % (new_counter)<EOL><DEDENT>else:<EOL><INDENT>return "<STR_LIT>"<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>self.log_error("<STR_LIT>" % (params, e))<EOL>return "<STR_LIT>"<EOL><DEDENT>
Validate OATH-HOTP code using YubiHSM HMAC-SHA1 hashing with token keys
secured in AEAD's that we have stored in an SQLite3 database.