Skip to content

Commit 8a3d611

Browse files
committed
Allow building on JC303_kit
1 parent a80632d commit 8a3d611

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

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

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,11 +1014,7 @@ private void makeCredential(APDU apdu, short lc, byte[] buffer) {
10141014
} catch (Exception e) {
10151015
sendErrorByte(apdu, FIDOConstants.CTAP2_ERR_KEY_STORE_FULL);
10161016
}
1017-
try {
1018-
JCSystem.requestObjectDeletion();
1019-
} catch (Exception e) {
1020-
// Do nothing - waste a tiny amount of memory
1021-
}
1017+
attemptToFreeMemory();
10221018

10231019
// Re-get available mem here, because we used/freed some
10241020
availableMem = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_PERSISTENT);
@@ -1125,11 +1121,7 @@ private void makeCredential(APDU apdu, short lc, byte[] buffer) {
11251121
}
11261122

11271123
if (overwriteExistingCredential) {
1128-
try {
1129-
JCSystem.requestObjectDeletion();
1130-
} catch (Exception e) {
1131-
// No real problem, I guess
1132-
}
1124+
attemptToFreeMemory();
11331125
}
11341126
}
11351127
} else {
@@ -1260,6 +1252,17 @@ private void makeCredential(APDU apdu, short lc, byte[] buffer) {
12601252
doSendResponse(apdu, outputLen);
12611253
}
12621254

1255+
/**
1256+
* Attempts to release no-longer-referenced memory back to the Javacard OS
1257+
*/
1258+
private static void attemptToFreeMemory() {
1259+
try {
1260+
JCSystem.requestObjectDeletion();
1261+
} catch (Exception e) {
1262+
// No real problem, I guess
1263+
}
1264+
}
1265+
12631266

12641267
/**
12651268
* Creates a "good" (32-byte-private-key) EC keypair.
@@ -4877,11 +4880,7 @@ private void handleUserUpdate(APDU apdu, byte[] buffer, short readOffset, short
48774880
JCSystem.abortTransaction();
48784881
}
48794882
}
4880-
try {
4881-
JCSystem.requestObjectDeletion();
4882-
} catch (Exception e) {
4883-
// No real problem, I guess
4884-
}
4883+
attemptToFreeMemory();
48854884
break;
48864885
}
48874886
}
@@ -5004,11 +5003,7 @@ private void handleDeleteCred(APDU apdu, byte[] buffer, short readOffset, short
50045003
if (ok) {
50055004
JCSystem.commitTransaction();
50065005

5007-
try {
5008-
JCSystem.requestObjectDeletion();
5009-
} catch (Exception e) {
5010-
// freed next time we delete a cred?
5011-
}
5006+
attemptToFreeMemory();
50125007
} else {
50135008
JCSystem.abortTransaction();
50145009
}
@@ -5027,11 +5022,7 @@ private void handleDeleteCred(APDU apdu, byte[] buffer, short readOffset, short
50275022
if (ok) {
50285023
JCSystem.commitTransaction();
50295024

5030-
try {
5031-
JCSystem.requestObjectDeletion();
5032-
} catch (Exception e) {
5033-
// freed next time we delete a cred?
5034-
}
5025+
attemptToFreeMemory();
50355026
} else {
50365027
JCSystem.abortTransaction();
50375028
}
@@ -5533,11 +5524,7 @@ private void authenticatorReset(APDU apdu) {
55335524
JCSystem.abortTransaction();
55345525
}
55355526

5536-
try {
5537-
JCSystem.requestObjectDeletion();
5538-
} catch (Exception e) {
5539-
// No problem, really
5540-
}
5527+
attemptToFreeMemory();
55415528

55425529
if (ok) {
55435530
sendErrorByte(apdu, FIDOConstants.CTAP2_OK);
@@ -7266,11 +7253,7 @@ private void initTransientStorage(APDU apdu) {
72667253

72677254
availableMem = JCSystem.getAvailableMemory(JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT);
72687255

7269-
try {
7270-
JCSystem.requestObjectDeletion();
7271-
} catch (Exception e) {
7272-
// Whoops. Wasted some flash, I guess.
7273-
}
7256+
attemptToFreeMemory();
72747257
}
72757258

72767259
short targetMemAmount = 99; // 96+3=99 bytes desired RAM buffer left over, enough room for one 32-byte HMAC

0 commit comments

Comments
 (0)