Skip to content

Commit

Permalink
Increase timeout for NFC transactions to two seconds
Browse files Browse the repository at this point in the history
According to brush701/yubichallenge#4 and PhilippC/keepass2android#444 it seems that for some device/YubiKey combinations a higher-than-default value is required to make things work. On my OnePlus 5, the default timeout is set to 618 ms, so two seconds seem reasonable.
  • Loading branch information
pp3345 committed Jul 16, 2018
1 parent 704c06d commit cfe8281
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/net/pp3345/ykdroid/yubikey/NfcYubiKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ public NfcYubiKey(final IsoDep tag) {
this.tag = tag;
}

private void ensureConnected() throws IOException {
if (!this.tag.isConnected()) {
this.tag.connect();
this.tag.setTimeout(2000);
}
}

@Override
public byte[] challengeResponse(final Slot slot, final byte[] challenge) throws YubiKeyException {
slot.ensureChallengeResponseSlot();

try {
if (!this.tag.isConnected())
this.tag.connect();
this.ensureConnected();

final SelectFileApdu selectFileApdu = new SelectFileApdu(SelectFileApdu.SelectionControl.DF_NAME_DIRECT, SelectFileApdu.RecordOffset.FIRST_RECORD, CHALLENGE_AID);
if (!selectFileApdu.parseResponse(this.tag.transceive(selectFileApdu.build())).isSuccess()) {
Expand Down

0 comments on commit cfe8281

Please sign in to comment.