Skip to content

Commit 757fa9c

Browse files
committed
v2.2.3
1 parent 4abe350 commit 757fa9c

31 files changed

+560
-182
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.4.0'
8+
classpath 'com.android.tools.build:gradle:3.4.1'
99
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.17"
1010
classpath 'digital.wup:android-maven-publish:3.6.2'
1111
}
@@ -22,5 +22,5 @@ ext {
2222
compileSdkVersion = 28
2323
hwSdkIncludeAsSubmodule = false
2424
hwSdkVersionCode = 8
25-
hwSdkVersionName = '2.0.0-alpha03'
25+
hwSdkVersionName = '2.2.3'
2626
}

hwsecurity-fido/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ dependencies {
99
api project(':hwsecurity')
1010
}
1111

12-
implementation 'androidx.appcompat:appcompat:1.0.2'
13-
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
14-
15-
implementation 'com.google.android.material:material:1.0.0'
16-
1712
implementation 'de.cotech:nfc-sweetspot:1.1'
1813

1914
implementation 'com.jakewharton.timber:timber:4.7.0'
2015

16+
implementation 'com.google.android.material:material:1.0.0'
17+
18+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
19+
implementation 'androidx.appcompat:appcompat:1.0.2'
20+
2121
api 'com.google.auto.value:auto-value-annotations:1.6.2'
2222
annotationProcessor 'com.google.auto.value:auto-value:1.6.2'
2323
annotationProcessor 'com.ryanharter.auto.value:auto-value-parcel:0.2.6'

hwsecurity-fido/src/main/java/de/cotech/hw/fido/FidoSecurityKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
@SuppressWarnings({ "unused", "WeakerAccess" }) // All methods are public API
5252
public class FidoSecurityKey extends SecurityKey {
53-
private static final int USER_PRESENCE_CHECK_DELAY_MS = 1000;
53+
private static final int USER_PRESENCE_CHECK_DELAY_MS = 250;
5454

5555
private final FidoU2fAppletConnection fidoU2fAppletConnection;
5656
private final FidoAsyncOperationManager fidoAsyncOperationManager;

hwsecurity-fido/src/main/java/de/cotech/hw/fido/internal/FidoU2fAppletConnection.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@
3535
import androidx.annotation.RestrictTo;
3636
import androidx.annotation.RestrictTo.Scope;
3737
import de.cotech.hw.SecurityKeyException;
38-
import de.cotech.hw.exceptions.ClaNotSupportedException;
39-
import de.cotech.hw.exceptions.InsNotSupportedException;
40-
import de.cotech.hw.exceptions.SelectAppletException;
41-
import de.cotech.hw.exceptions.WrongRequestLengthException;
38+
import de.cotech.hw.exceptions.*;
4239
import de.cotech.hw.fido.exceptions.FidoPresenceRequiredException;
4340
import de.cotech.hw.fido.exceptions.FidoWrongKeyHandleException;
4441
import de.cotech.hw.internal.iso7816.CommandApdu;
@@ -58,6 +55,8 @@ public class FidoU2fAppletConnection {
5855
// see to "FIDO U2F NFC protocol", Section 5. Applet selection
5956
// https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-nfc-protocol-v1.2-ps-20170411.html
6057
Hex.decodeHexOrFail("A0000006472F0001"),
58+
// Workaround for Solokey: https://github.com/solokeys/solo/issues/213
59+
Hex.decodeHexOrFail("A0000006472F000100"),
6160
// old Yubico demo applet AID
6261
Hex.decodeHexOrFail("A0000005271002")
6362
);
@@ -129,16 +128,17 @@ private void checkVersionOrThrow(byte[] versionBytes) throws IOException {
129128

130129
private byte[] selectFileOrFail(byte[] fileAid) throws IOException {
131130
CommandApdu select = commandFactory.createSelectFileCommand(fileAid);
132-
ResponseApdu response = communicate(select);
133131

134-
if (response.isSuccess()) {
132+
try {
133+
ResponseApdu response = communicateOrThrow(select);
134+
135135
// "FIDO authenticator SHALL reply with its version string in the successful response"
136136
// https://fidoalliance.org/specs/fido-u2f-v1.2-ps-20170411/fido-u2f-nfc-protocol-v1.2-ps-20170411.html
137137
checkVersionOrThrow(response.getData());
138138
return fileAid;
139+
} catch (AppletFileNotFoundException e) {
140+
return null;
139141
}
140-
141-
return null;
142142
}
143143

144144
// endregion
@@ -173,6 +173,8 @@ public ResponseApdu communicateOrThrow(CommandApdu commandApdu) throws IOExcepti
173173
throw new FidoPresenceRequiredException();
174174
case FidoWrongKeyHandleException.SW_WRONG_KEY_HANDLE:
175175
throw new FidoWrongKeyHandleException();
176+
case AppletFileNotFoundException.SW_FILE_NOT_FOUND:
177+
throw new AppletFileNotFoundException();
176178
case ClaNotSupportedException.SW_CLA_NOT_SUPPORTED:
177179
throw new ClaNotSupportedException();
178180
case InsNotSupportedException.SW_INS_NOT_SUPPORTED:
@@ -200,7 +202,13 @@ private ResponseApdu transceiveWithChaining(CommandApdu commandApdu) throws IOEx
200202
*/
201203
if (transport.isExtendedLengthSupported() && commandFactory.isSuitableForExtendedApdu(commandApdu)) {
202204
CommandApdu extendedLengthApdu = commandApdu.withNe(65536);
203-
return transport.transceive(extendedLengthApdu);
205+
ResponseApdu response = transport.transceive(extendedLengthApdu);
206+
if (response.getSw() == WrongRequestLengthException.SW_WRONG_REQUEST_LENGTH) {
207+
Timber.d("Received WRONG_REQUEST_LENGTH error. Retrying with compatibility workaround");
208+
CommandApdu shortApdu = commandFactory.createShortApdu(commandApdu);
209+
return transport.transceive(shortApdu);
210+
}
211+
return response;
204212
}
205213

206214
if (commandFactory.isSuitableForShortApdu(commandApdu)) {

hwsecurity-fido/src/main/java/de/cotech/hw/fido/internal/async/FidoOperationThread.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
import androidx.lifecycle.Lifecycle.Event;
3737
import androidx.lifecycle.LifecycleObserver;
3838
import androidx.lifecycle.OnLifecycleEvent;
39+
import de.cotech.hw.exceptions.TransportGoneException;
3940
import de.cotech.hw.fido.exceptions.FidoPresenceRequiredException;
4041
import de.cotech.hw.fido.internal.FidoU2fAppletConnection;
42+
import timber.log.Timber;
4143

4244

4345
@RestrictTo(Scope.LIBRARY_GROUP)
@@ -80,6 +82,10 @@ public void run() {
8082
postToHandler(() -> deliverResponse(response));
8183
break;
8284
} catch (InterruptedException e) {
85+
Timber.e("Fido operation was interrupted");
86+
break;
87+
} catch (TransportGoneException e) {
88+
Timber.e("Transport gone during fido operation");
8389
break;
8490
} catch (FidoPresenceRequiredException e) {
8591
try {
@@ -88,6 +94,10 @@ public void run() {
8894
break;
8995
}
9096
} catch (IOException e) {
97+
if (e.getCause() instanceof InterruptedException) {
98+
Timber.e("Fido operation was interrupted");
99+
break;
100+
}
91101
postToHandler(() -> deliverIoException(e));
92102
break;
93103
}
@@ -106,7 +116,7 @@ private void postToHandler(Runnable runnable) {
106116
});
107117
}
108118

109-
@OnLifecycleEvent(Event.ON_DESTROY)
119+
@OnLifecycleEvent(Event.ON_STOP)
110120
public void onDestroy() {
111121
if (isAlive() && !isInterrupted()) {
112122
fidoAsyncOperationManager.clearAsyncOperation(true, this);

hwsecurity-fido/src/main/java/de/cotech/hw/fido/internal/jsapi/U2fResponse.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
package de.cotech.hw.fido.internal.jsapi;
2626

2727

28-
import java.nio.charset.StandardCharsets;
29-
3028
import androidx.annotation.Nullable;
29+
3130
import com.google.auto.value.AutoValue;
3231

32+
import java.nio.charset.Charset;
33+
3334

3435
@AutoValue
3536
public abstract class U2fResponse {
@@ -46,7 +47,7 @@ public abstract class U2fResponse {
4647

4748
public static U2fResponse createRegisterResponse(Long requestId, String clientData, byte[] registrationData) {
4849
RegisterResponseData responseData = new AutoValue_U2fResponse_RegisterResponseData(
49-
REGISTER_RESPONSE_VERSION, registrationData, clientData.getBytes(StandardCharsets.UTF_8)
50+
REGISTER_RESPONSE_VERSION, registrationData, clientData.getBytes(Charset.forName("UTF-8"))
5051
);
5152

5253
return new AutoValue_U2fResponse(REGISTER_RESPONSE_TYPE, responseData, requestId);
@@ -55,7 +56,7 @@ public static U2fResponse createRegisterResponse(Long requestId, String clientDa
5556
public static U2fResponse createAuthenticateResponse(Long requestId, String clientData,
5657
byte[] keyHandle, byte[] signatureData) {
5758
SignResponseData reseponseData = new AutoValue_U2fResponse_SignResponseData(
58-
keyHandle, signatureData, clientData.getBytes(StandardCharsets.UTF_8)
59+
keyHandle, signatureData, clientData.getBytes(Charset.forName("UTF-8"))
5960
);
6061

6162
return new AutoValue_U2fResponse(AUTHENTICATE_RESPONSE_TYPE, reseponseData, requestId);

hwsecurity-fido/src/main/java/de/cotech/hw/fido/internal/operations/AuthenticateOp.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ public byte[] authenticate(byte[] challengeParam, byte[] applicationParam, byte[
8181
CommandApdu command = connection.getCommandFactory().createAuthenticationCommand(data);
8282
ResponseApdu response = connection.communicateOrThrow(command);
8383

84-
if (!response.isSuccess()) {
85-
throw new AssertionError("communicateOrThrow returned unsuccessful ResponseApdu!");
86-
}
87-
8884
return response.getData();
8985
}
9086

hwsecurity-fido/src/main/java/de/cotech/hw/fido/internal/operations/RegisterOp.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ public byte[] register(byte[] challengeParam, byte[] applicationParam)
7676
CommandApdu command = connection.getCommandFactory().createRegistrationCommand(data);
7777
ResponseApdu response = connection.communicateOrThrow(command);
7878

79-
if (!response.isSuccess()) {
80-
throw new AssertionError("communicateOrThrow returned unsuccessful ResponseApdu!");
81-
}
82-
8379
return response.getData();
8480
}
8581

0 commit comments

Comments
 (0)