Skip to content

Commit bf1f2fe

Browse files
committed
Ignore selection of other applets
Fixes #32
1 parent 9581d34 commit bf1f2fe

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fido2[pcsc]==1.1.2
2-
JPype1==1.4.1
2+
JPype1==1.5.0
33
parameterized==0.9.0
44
uhid==0.0.1

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4318,9 +4318,13 @@ private boolean streamOutgoingContinuation(APDU apdu, byte[] apduBytes, boolean
43184318
* @param apdu Request/response context object
43194319
*/
43204320
private void handleAppletSelect(APDU apdu) {
4321-
if (bufferManager == null) {
4322-
apdu.setIncomingAndReceive();
4321+
apdu.setIncomingAndReceive();
4322+
4323+
if (!JCSystem.getAID().equals(apdu.getBuffer(), apdu.getOffsetCdata(), (byte) apdu.getIncomingLength())) {
4324+
throwException(ISO7816.SW_FILE_NOT_FOUND);
4325+
}
43234326

4327+
if (bufferManager == null) {
43244328
// There also might not be enough RAM, quite, if we allocate this during install while the app install
43254329
// parameters array is held in memory...
43264330
initTransientStorage(apdu);
@@ -4358,7 +4362,6 @@ private void handleAppletSelect(APDU apdu) {
43584362
} else {
43594363
sendByteArray(apdu, CannedCBOR.U2F_V2_RESPONSE, (short) CannedCBOR.U2F_V2_RESPONSE.length);
43604364
}
4361-
43624365
}
43634366

43644367
/**

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class AppletBasicTest {
2323

2424
CardSimulator simulator;
2525
AID appletAID = AIDUtil.create("F000000001");
26+
AID randoAID = AIDUtil.create("F100900001");
2627

2728
@BeforeEach
2829
public void setupApplet() {
@@ -42,15 +43,10 @@ private ResponseAPDU sendCTAP(String hexCommand) {
4243
return sendCTAP(bparams);
4344
}
4445

45-
private ResponseAPDU send(int... params) {
46-
byte[] bparams = new byte[params.length];
47-
for (int i = 0; i < params.length; i++) {
48-
bparams[i] = (byte) params[i];
49-
}
46+
private ResponseAPDU send(byte[] bparams) {
5047
CommandAPDU commandAPDU = new CommandAPDU(bparams);
5148
ResponseAPDU response = simulator.transmitCommand(commandAPDU);
5249

53-
5450
ArrayList<ResponseAPDU> prevResponses = new ArrayList<>();
5551
int totalResponseLen = response.getNr();
5652
prevResponses.add(response);
@@ -79,6 +75,15 @@ private ResponseAPDU send(int... params) {
7975
return new ResponseAPDU(combinedBB);
8076
}
8177

78+
private ResponseAPDU send(int... params) {
79+
byte[] bparams = new byte[params.length];
80+
for (int i = 0; i < params.length; i++) {
81+
bparams[i] = (byte) params[i];
82+
}
83+
84+
return send(bparams);
85+
}
86+
8287
private ResponseAPDU sendCTAP(int... vals) {
8388
boolean shortLen = vals.length <= 255;
8489
int[] framedVals = new int[vals.length + (shortLen ? 6 : 7)]; // Hmm, why isn't this 8 for extended length?
@@ -150,4 +155,15 @@ public void checkVersionInSelectionResponse() {
150155
assertEquals("FIDO_2_0", new String(respWithoutStatus));
151156
}
152157

158+
@Test
159+
public void checkIgnoreSelectingIncorrectAID() {
160+
byte[] resp = simulator.selectAppletWithResult(appletAID);
161+
short recvdStatus = (short) (resp[resp.length - 2] * 256 + resp[resp.length - 1]);
162+
163+
assertEquals(ISO7816.SW_NO_ERROR, recvdStatus);
164+
165+
ResponseAPDU responseAPDU = send(AIDUtil.select(randoAID));
166+
assertEquals(ISO7816.SW_FILE_NOT_FOUND, responseAPDU.getSW());
167+
}
168+
153169
}

0 commit comments

Comments
 (0)