Clean up security token transport if connection procedure failed

This commit is contained in:
Vincent Breitmoser 2018-07-15 12:29:06 +02:00
parent fbbc77335b
commit a3021bbd83

View file

@ -103,28 +103,33 @@ public class SecurityTokenConnection {
*/
@VisibleForTesting
void connectToDevice(Context context) throws IOException {
// Connect on transport layer
transport.connect();
try {
// Connect on transport layer
transport.connect();
// dummy instance for initial communicate() calls
cardCapabilities = new CardCapabilities();
// dummy instance for initial communicate() calls
cardCapabilities = new CardCapabilities();
determineTokenType();
determineTokenType();
CommandApdu select = commandFactory.createSelectFileOpenPgpCommand();
ResponseApdu response = communicate(select); // activate connection
CommandApdu select = commandFactory.createSelectFileOpenPgpCommand();
ResponseApdu response = communicate(select); // activate connection
if (!response.isSuccess()) {
throw new CardException("Initialization failed!", response.getSw());
if (!response.isSuccess()) {
throw new CardException("Initialization failed!", response.getSw());
}
refreshConnectionCapabilities();
isPw1ValidatedForSignature = false;
isPw1ValidatedForOther = false;
isPw3Validated = false;
smEstablishIfAvailable(context);
} catch (IOException e) {
transport.release();
throw e;
}
refreshConnectionCapabilities();
isPw1ValidatedForSignature = false;
isPw1ValidatedForOther = false;
isPw3Validated = false;
smEstablishIfAvailable(context);
}
@VisibleForTesting