add cred: prompt for overwrite

This commit is contained in:
Dag Heyman 2019-09-18 10:48:42 +02:00
parent 85fce3592f
commit b5858a46d6
3 changed files with 40 additions and 15 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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) {