コード例 #1
0
ファイル: api_keys.py プロジェクト: numberoverzero/finder_old
def derive_key(keys, key, duration=DERIVED_KEY_LIFETIME):
    if not has_primary_key(keys, key):
        return None, None
    utc_expiration = timeutil.utcnow(seconds=duration)
    expiration = timeutil.utc_asint(utc_expiration)
    derived_key, salt = pbkdf2(key, key_len=DERIVED_KEY_LENGTH)
    key = {'key': derived_key, 'salt': salt, 'type': DERIVED, 'exp': expiration}
    keys.insert(key)
    return derived_key, salt
コード例 #2
0
ファイル: api_keys.py プロジェクト: numberoverzero/finder_old
def validate_key(keys, key):
    key = keys.find_one({'key': key})
    if not key:
        return False
    expiration = key.get('exp', None)
    if not expiration:
        return True
    now = timeutil.utc_asint(timeutil.utcnow())
    if now > expiration:
        keys.remove(key)
        return False
    return True
コード例 #3
0
def validate_key(keys, key):
    key = keys.find_one({'key': key})
    if not key:
        return False
    expiration = key.get('exp', None)
    if not expiration:
        return True
    now = timeutil.utc_asint(timeutil.utcnow())
    if now > expiration:
        keys.remove(key)
        return False
    return True
コード例 #4
0
def derive_key(keys, key, duration=DERIVED_KEY_LIFETIME):
    if not has_primary_key(keys, key):
        return None, None
    utc_expiration = timeutil.utcnow(seconds=duration)
    expiration = timeutil.utc_asint(utc_expiration)
    derived_key, salt = pbkdf2(key, key_len=DERIVED_KEY_LENGTH)
    key = {
        'key': derived_key,
        'salt': salt,
        'type': DERIVED,
        'exp': expiration
    }
    keys.insert(key)
    return derived_key, salt