mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-23 09:56:23 +03:00
add cred: prompt for overwrite
This commit is contained in:
parent
85fce3592f
commit
b5858a46d6
@ -335,15 +335,20 @@ class Controller(object):
|
||||
|
||||
def ccid_add_credential(
|
||||
self, name, secret, issuer, oath_type,
|
||||
algo, digits, period, touch):
|
||||
algo, digits, period, touch, overwrite=False):
|
||||
secret = parse_b32_key(secret)
|
||||
with self._open_oath() as oath_controller:
|
||||
try:
|
||||
self._unlock(oath_controller)
|
||||
oath_controller.put(CredentialData(
|
||||
cred_data = CredentialData(
|
||||
secret, issuer, name, OATH_TYPE[oath_type], ALGO[algo],
|
||||
int(digits), int(period), 0, touch
|
||||
))
|
||||
)
|
||||
if not overwrite:
|
||||
key = cred_data.make_key()
|
||||
if key in [cred.key for cred in oath_controller.list()]:
|
||||
return failure('credential_already_exists')
|
||||
oath_controller.put(cred_data)
|
||||
except APDUError as e:
|
||||
# NEO doesn't return a no space error if full,
|
||||
# but a command aborted error. Assume it's because of
|
||||
|
@ -40,9 +40,15 @@ ScrollView {
|
||||
yubiKey.calculateAll(navigator.goToCredentials)
|
||||
navigator.snackBar(qsTr("Credential added"))
|
||||
} else {
|
||||
navigator.snackBarError(navigator.getErrorMessage(
|
||||
resp.error_id))
|
||||
console.log("addCredential failed:", resp.error_id)
|
||||
if (resp.error_id === 'credential_already_exists') {
|
||||
navigator.confirm(
|
||||
qsTr("Overwrite?"),
|
||||
qsTr("A credential with this name already exists, do you want to overwrite it?"),
|
||||
_ccidAddCredentialOverwrite)
|
||||
} else {
|
||||
navigator.snackBarError(navigator.getErrorMessage(resp.error_id))
|
||||
console.log("addCredential failed:", resp.error_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,6 +58,26 @@ ScrollView {
|
||||
requireTouchCheckBox.checked, callback)
|
||||
}
|
||||
|
||||
function _ccidAddCredential(overwrite) {
|
||||
yubiKey.ccidAddCredential(nameLbl.text, secretKeyLbl.text,
|
||||
issuerLbl.text,
|
||||
oathTypeComboBox.currentText,
|
||||
algoComboBox.currentText,
|
||||
digitsComboBox.currentText,
|
||||
periodLbl.text,
|
||||
requireTouchCheckBox.checked,
|
||||
overwrite,
|
||||
callback)
|
||||
}
|
||||
|
||||
function _ccidAddCredentialOverwrite() {
|
||||
_ccidAddCredential(true)
|
||||
}
|
||||
|
||||
function _ccidAddCredentialNoOverwrite() {
|
||||
_ccidAddCredential(false)
|
||||
}
|
||||
|
||||
if (acceptableInput()) {
|
||||
if (settings.otpMode) {
|
||||
yubiKey.otpSlotStatus(function (resp) {
|
||||
@ -71,13 +97,7 @@ ScrollView {
|
||||
}
|
||||
})
|
||||
} else {
|
||||
yubiKey.ccidAddCredential(nameLbl.text, secretKeyLbl.text,
|
||||
issuerLbl.text,
|
||||
oathTypeComboBox.currentText,
|
||||
algoComboBox.currentText,
|
||||
digitsComboBox.currentText,
|
||||
periodLbl.text,
|
||||
requireTouchCheckBox.checked, callback)
|
||||
_ccidAddCredentialNoOverwrite()
|
||||
}
|
||||
settings.requireTouch = requireTouchCheckBox.checked
|
||||
}
|
||||
|
@ -406,9 +406,9 @@ Python {
|
||||
doCall('yubikey.controller.otp_add_credential', [slot, key, touch], cb)
|
||||
}
|
||||
|
||||
function ccidAddCredential(name, key, issuer, oathType, algo, digits, period, touch, cb) {
|
||||
function ccidAddCredential(name, key, issuer, oathType, algo, digits, period, touch, overwrite, cb) {
|
||||
doCall('yubikey.controller.ccid_add_credential',
|
||||
[name, key, issuer, oathType, algo, digits, period, touch], cb)
|
||||
[name, key, issuer, oathType, algo, digits, period, touch, overwrite], cb)
|
||||
}
|
||||
|
||||
function deleteCredential(credential, cb) {
|
||||
|
Loading…
Reference in New Issue
Block a user