challenge.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:dnsknife 作者: Gandi 项目源码 文件源码
def valid_tokens(domain, secret, validity=86400):
    if isinstance(secret, str):
        secret = secret.encode()

    if isinstance(domain, str):
        domain = domain.encode('idna')

    def token_at(when):
        h = hmac.HMAC(secret, digestmod=hashlib.sha256)
        h.update(domain)
        h.update(str(int(when/validity)).encode())
        return h.hexdigest()

    # We're not totally strict on validity, but want
    # to avoid the worst case where we provided a token
    # that immediately expires. Allow up to three half-validity
    # intervals in the past.

    now = int(time.time())
    validity = int(validity/2)
    past = now - 3*validity

    return [token_at(when) for when in range(past, now, validity)]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号