Improve CCID error handling

Co-Authored-By: Dennis Fokin <dennis.fokin@yubico.com>
This commit is contained in:
Dag Heyman 2020-03-13 12:01:35 +01:00
parent 29426bf602
commit a19c80ec2b
No known key found for this signature in database
GPG Key ID: 06FC004369E7D338
3 changed files with 11 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import logging
import types import types
import time import time
import ykman.logging_setup import ykman.logging_setup
import smartcard.pcsc.PCSCExceptions
from base64 import b32encode, b64decode from base64 import b32encode, b64decode
from binascii import a2b_hex, b2a_hex from binascii import a2b_hex, b2a_hex
from ykman.descriptor import ( from ykman.descriptor import (
@ -117,6 +118,8 @@ def catch_error(f):
raise raise
except CCIDError: except CCIDError:
return failure('ccid_error') return failure('ccid_error')
except smartcard.pcsc.PCSCExceptions.EstablishContextException:
return failure('no_pcscd')
except Exception as e: except Exception as e:
if str(e) == 'Incorrect padding': if str(e) == 'Incorrect padding':
return failure('incorrect_padding') return failure('incorrect_padding')

View File

@ -126,6 +126,8 @@ StackView {
return qsTr('Failed to read from slots') return qsTr('Failed to read from slots')
case 'failed_to_parse_uri': case 'failed_to_parse_uri':
return qsTr('Failed to read credential from QR code') return qsTr('Failed to read credential from QR code')
case 'no_pcscd':
return qsTr('Is the pcscd/smart card service running?')
default: default:
return qsTr('Unknown error') return qsTr('Unknown error')
} }

View File

@ -239,7 +239,7 @@ Python {
if (!currentDevice || !availableDevices.some(dev => dev.serial === currentDevice.serial)) { if (!currentDevice || !availableDevices.some(dev => dev.serial === currentDevice.serial)) {
// new device is being loaded, clear any old device // new device is being loaded, clear any old device
clearCurrentDeviceAndEntries() clearCurrentDeviceAndEntries()
navigator.goToLoading()
if (availableDevices.some(dev => dev.selectable)) { if (availableDevices.some(dev => dev.selectable)) {
// pick the first selectable device // pick the first selectable device
currentDevice = resp.devices.find(dev => dev.selectable) currentDevice = resp.devices.find(dev => dev.selectable)
@ -309,6 +309,11 @@ Python {
currentDevice.hasPassword = true currentDevice.hasPassword = true
currentDeviceValidated = false currentDeviceValidated = false
navigator.goToEnterPasswordIfNotInSettings() navigator.goToEnterPasswordIfNotInSettings()
} else if (resp.error_id === 'open_device_failed') {
clearCurrentDeviceAndEntries()
yubiKey.availableDevices = []
navigator.snackBarError(navigator.getErrorMessage(resp.error_id))
navigator.goToCredentialsIfNotInSettings()
} else { } else {
clearCurrentDeviceAndEntries() clearCurrentDeviceAndEntries()
console.log("calculateAll failed:", resp.error_id) console.log("calculateAll failed:", resp.error_id)