def generate_twofactor_code_for_time(shared_secret, timestamp): """Generate Steam 2FA code for timestamp :param shared_secret: authenticator shared secret :type shared_secret: bytes :param timestamp: timestamp to use, if left out uses current time :type timestamp: int :return: steam two factor code :rtype: str """ hmac = hmac_sha1(bytes(shared_secret), struct.pack('>Q', int(timestamp) // 30)) # this will NOT stop working in 2038 start = ord(hmac[19:20]) & 0xF codeint = struct.unpack('>I', hmac[start:start + 4])[0] & 0x7fffffff charset = '23456789BCDFGHJKMNPQRTVWXY' code = '' for _ in range(5): codeint, i = divmod(codeint, len(charset)) code += charset[i] return code
def generate_confirmation_key(identity_secret, tag, timestamp): """Generate confirmation key for trades. Can only be used once. :param identity_secret: authenticator identity secret :type identity_secret: bytes :param tag: tag identifies what the request, see list below :type tag: str :param timestamp: timestamp to use for generating key :type timestamp: int :return: confirmation key :rtype: bytes Tag choices: * ``conf`` to load the confirmations page * ``details`` to load details about a trade * ``allow`` to confirm a trade * ``cancel`` to cancel a trade """ data = struct.pack('>Q', int(timestamp)) + tag.encode('ascii') # this will NOT stop working in 2038 return hmac_sha1(bytes(identity_secret), data)
def generate_twofactor_code_for_time(shared_secret, timestamp): """Generate Steam 2FA code for timestamp :param shared_secret: authenticator shared secret :type shared_secret: bytes :param timestamp: timestamp to use, if left out uses current time :type timestamp: int :return: steam two factor code :rtype: str """ hmac = hmac_sha1(bytes(shared_secret), struct.pack('>Q', int(timestamp)//30)) # this will NOT stop working in 2038 start = ord(hmac[19:20]) & 0xF codeint = struct.unpack('>I', hmac[start:start+4])[0] & 0x7fffffff charset = '23456789BCDFGHJKMNPQRTVWXY' code = '' for _ in range(5): codeint, i = divmod(codeint, len(charset)) code += charset[i] return code