mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2025-01-06 02:37:21 +03:00
Support individual calculation of slot credentials
This commit is contained in:
parent
b50b63a94c
commit
1e95b880c8
@ -71,6 +71,11 @@ class Controller(object):
|
||||
def calculate(self, credential, timestamp, password_key):
|
||||
return self._calculate(Credential.from_dict(credential), timestamp, password_key).to_dict()
|
||||
|
||||
def calculate_slot_mode(self, slot, digits, timestamp):
|
||||
dev = self._descriptor.open_device(TRANSPORT.OTP)
|
||||
code = dev.driver.calculate(slot, challenge=timestamp, totp=True, digits=int(digits), wait_for_touch=True)
|
||||
return Credential(self._slot_name(slot), code=code, oath_type='totp', touch=True, algo='SHA1', expiration=self._expiration(timestamp)).to_dict()
|
||||
|
||||
def refresh_slot_credentials(self, slots, digits, timestamp):
|
||||
result = []
|
||||
if slots[0]:
|
||||
@ -84,17 +89,21 @@ class Controller(object):
|
||||
return [c.to_dict() for c in result]
|
||||
|
||||
def _read_slot_cred(self, slot, digits, timestamp):
|
||||
expiration = ((timestamp + 30) // 30) * 30
|
||||
credname = "YubiKey Slot {}".format(slot)
|
||||
dev = self._descriptor.open_device(TRANSPORT.OTP)
|
||||
try:
|
||||
code = dev.driver.calculate(slot, challenge=timestamp, totp=True, digits=int(digits), wait_for_touch=False)
|
||||
return Credential(credname, code=code, oath_type='totp', touch=False, algo='SHA1', expiration=expiration)
|
||||
return Credential(self._slot_name(slot), code=code, oath_type='totp', touch=False, algo='SHA1', expiration=self._expiration(timestamp))
|
||||
except YkpersError as e:
|
||||
if e.errno == 11:
|
||||
return Credential(credname, oath_type='totp', touch=True, algo='SHA1')
|
||||
return Credential(self._slot_name(slot), oath_type='totp', touch=True, algo='SHA1')
|
||||
return None
|
||||
|
||||
def _slot_name(self, slot):
|
||||
return "YubiKey Slot {}".format(slot)
|
||||
|
||||
def _expiration(self, timestamp):
|
||||
return ((timestamp + 30) // 30) * 30
|
||||
|
||||
def needs_validation(self):
|
||||
dev = self._descriptor.open_device(TRANSPORT.CCID)
|
||||
controller = OathController(dev.driver)
|
||||
|
22
qml/Main.qml
22
qml/Main.qml
@ -585,8 +585,13 @@ ApplicationWindow {
|
||||
}
|
||||
|
||||
function calculateCredential(credential) {
|
||||
|
||||
device.calculate(credential)
|
||||
if (settings.slotMode) {
|
||||
var slot = getSlot(credential)
|
||||
var digits = getDigits(slot)
|
||||
device.calculateSlotMode(slot, digits)
|
||||
} else {
|
||||
device.calculate(credential)
|
||||
}
|
||||
if (credential.oath_type === 'hotp') {
|
||||
hotpTouchTimer.restart()
|
||||
}
|
||||
@ -595,6 +600,19 @@ ApplicationWindow {
|
||||
}
|
||||
}
|
||||
|
||||
function getSlot(credential) {
|
||||
if (credential.name.indexOf('1') !== -1) {
|
||||
return 1
|
||||
}
|
||||
if (credential.name.indexOf('2') !== -1) {
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
function getDigits(slot) {
|
||||
return getSlotDigitsSettings()[slot -1]
|
||||
}
|
||||
|
||||
function updateExpiration() {
|
||||
var maxExpiration = 0
|
||||
if (credentials !== null) {
|
||||
|
@ -182,6 +182,12 @@ Python {
|
||||
updateCredential)
|
||||
}
|
||||
|
||||
function calculateSlotMode(slot, digits) {
|
||||
var now = Math.floor(Date.now() / 1000)
|
||||
do_call('yubikey.controller.calculate_slot_mode', [slot, digits, now],
|
||||
updateCredential)
|
||||
}
|
||||
|
||||
function updateCredential(cred) {
|
||||
var result = []
|
||||
for (var i = 0; i < credentials.length; i++) {
|
||||
|
Loading…
Reference in New Issue
Block a user