mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-16 19:53:50 +03:00
Support secrets longer than 64 bytes.
This commit is contained in:
parent
60494a1db0
commit
f66005266e
@ -27,6 +27,7 @@
|
|||||||
from .exc import CardError, DeviceLockedError
|
from .exc import CardError, DeviceLockedError
|
||||||
from .utils import (der_read, der_pack, hmac_sha1, derive_key, get_random_bytes,
|
from .utils import (der_read, der_pack, hmac_sha1, derive_key, get_random_bytes,
|
||||||
time_challenge, parse_truncated, format_code)
|
time_challenge, parse_truncated, format_code)
|
||||||
|
from hashlib import sha1
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
YKOATH_AID = 'a000000527210101'.decode('hex')
|
YKOATH_AID = 'a000000527210101'.decode('hex')
|
||||||
@ -209,6 +210,8 @@ class YubiOathCcid(object):
|
|||||||
def put(self, name, key, oath_type=TYPE_TOTP, algo=ALG_SHA1, digits=6,
|
def put(self, name, key, oath_type=TYPE_TOTP, algo=ALG_SHA1, digits=6,
|
||||||
imf=0, always_increasing=False):
|
imf=0, always_increasing=False):
|
||||||
ensure_unlocked(self)
|
ensure_unlocked(self)
|
||||||
|
if len(key) > 64: # Keys longer than 64 bytes are hashed, as per HMAC.
|
||||||
|
key = sha1(key).digest()
|
||||||
keydata = chr(oath_type | algo) + chr(digits) + key
|
keydata = chr(oath_type | algo) + chr(digits) + key
|
||||||
data = der_pack(TAG_NAME, name, TAG_KEY, keydata)
|
data = der_pack(TAG_NAME, name, TAG_KEY, keydata)
|
||||||
if always_increasing:
|
if always_increasing:
|
||||||
|
Loading…
Reference in New Issue
Block a user