Skip to content

Commit 2e53f10

Browse files
committed
Avoid erroring on incoming long AIDs
1 parent 8a7e18a commit 2e53f10

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/java/us/q3q/fido2/FIDO2Applet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4329,7 +4329,7 @@ private boolean streamOutgoingContinuation(APDU apdu, byte[] apduBytes, boolean
43294329
private void handleAppletSelect(APDU apdu) {
43304330
apdu.setIncomingAndReceive();
43314331

4332-
if (Util.arrayCompare(AID, (short) 0,
4332+
if (apdu.getIncomingLength() != AID.length || Util.arrayCompare(AID, (short) 0,
43334333
apdu.getBuffer(), apdu.getOffsetCdata(), apdu.getIncomingLength()) != 0) {
43344334
throwException(ISO7816.SW_FILE_NOT_FOUND);
43354335
}

src/test/java/us/q3q/fido2/AppletBasicTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class AppletBasicTest {
2424
CardSimulator simulator;
2525
AID appletAID = AIDUtil.create("A0000006472F0001");
2626
AID randoAID = AIDUtil.create("F100900001");
27+
AID randoLongAID = AIDUtil.create("F100900001AAAAAAAAAAAA");
2728

2829
@BeforeEach
2930
public void setupApplet() {
@@ -166,4 +167,15 @@ public void checkIgnoreSelectingIncorrectAID() {
166167
assertEquals(ISO7816.SW_FILE_NOT_FOUND, responseAPDU.getSW());
167168
}
168169

170+
@Test
171+
public void checkIgnoreSelectingIncorrectLongAID() {
172+
byte[] resp = simulator.selectAppletWithResult(appletAID);
173+
short recvdStatus = (short) (resp[resp.length - 2] * 256 + resp[resp.length - 1]);
174+
175+
assertEquals(ISO7816.SW_NO_ERROR, recvdStatus);
176+
177+
ResponseAPDU responseAPDU = send(AIDUtil.select(randoLongAID));
178+
assertEquals(ISO7816.SW_FILE_NOT_FOUND, responseAPDU.getSW());
179+
}
180+
169181
}

0 commit comments

Comments
 (0)