Skip to content

Commit decb66c

Browse files
Fix for setIncomingAndReceive for T=0 protocol
1 parent deba5a4 commit decb66c

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Applet/AndroidSEProvider/src/com/android/javacard/keymaster/KMAndroidSEApplet.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public void handleDeviceBooted() {
9494
@Override
9595
public void process(APDU apdu) {
9696
try {
97+
receiveLen[0] = apdu.setIncomingAndReceive();
9798
handleDeviceBooted();
9899
// If this is select applet apdu which is selecting this applet then return
99100
if (apdu.isISOInterindustryCLA()) {
@@ -490,7 +491,7 @@ private void processProvisionAttestationKey(APDU apdu) {
490491

491492
private void processProvisionAttestationCertDataCmd(APDU apdu) {
492493
byte[] srcBuffer = apdu.getBuffer();
493-
short recvLen = apdu.setIncomingAndReceive();
494+
short recvLen = receiveLen[0];
494495
short srcOffset = apdu.getOffsetCdata();
495496
short bufferLength = apdu.getIncomingLength();
496497
short bufferStartOffset = repository.allocReclaimableMemory(bufferLength);

Applet/JCardSimProvider/src/com/android/javacard/keymaster/KMJCardSimApplet.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public void handleDeviceBooted() {
8585
@Override
8686
public void process(APDU apdu) {
8787
try {
88+
receiveLen[0] = apdu.setIncomingAndReceive();
8889
handleDeviceBooted();
8990
// If this is select applet apdu which is selecting this applet then return
9091
if (apdu.isISOInterindustryCLA()) {
@@ -486,7 +487,7 @@ private void processProvisionAttestationKey(APDU apdu) {
486487

487488
private void processProvisionAttestationCertDataCmd(APDU apdu) {
488489
byte[] srcBuffer = apdu.getBuffer();
489-
short recvLen = apdu.setIncomingAndReceive();
490+
short recvLen = receiveLen[0];
490491
short srcOffset = apdu.getOffsetCdata();
491492
short bufferLength = apdu.getIncomingLength();
492493
short bufferStartOffset = repository.allocReclaimableMemory(bufferLength);

Applet/src/com/android/javacard/keymaster/KMKeymasterApplet.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ public class KMKeymasterApplet extends Applet implements AppletEvent, ExtendedLe
296296
protected static short[] tmpVariables;
297297
protected static short[] data;
298298
protected static byte[] wrappingKey;
299+
protected static short[] receiveLen;
299300

300301
/**
301302
* Registers this applet.
@@ -311,6 +312,7 @@ protected KMKeymasterApplet(KMSEProvider seImpl) {
311312
tmpVariables =
312313
JCSystem.makeTransientShortArray(TMP_VARIABLE_ARRAY_SIZE, JCSystem.CLEAR_ON_DESELECT);
313314
wrappingKey = JCSystem.makeTransientByteArray((short)(WRAPPING_KEY_SIZE+1), JCSystem.CLEAR_ON_RESET);
315+
receiveLen = JCSystem.makeTransientShortArray((short) 1, JCSystem.CLEAR_ON_RESET);
314316
resetWrappingKey();
315317
opTable = new KMOperationState[MAX_OPERATIONS_COUNT];
316318
short index = 0;
@@ -916,7 +918,7 @@ public void sendOutgoing(APDU apdu, KMAttestationCert cert, short certStart, sho
916918
*/
917919
public static short receiveIncoming(APDU apdu, short reqExp) {
918920
byte[] srcBuffer = apdu.getBuffer();
919-
short recvLen = apdu.setIncomingAndReceive();
921+
short recvLen = receiveLen[0];
920922
short srcOffset = apdu.getOffsetCdata();
921923
// TODO add logic to handle the extended length buffer. In this case the memory can be reused
922924
// from extended buffer.

0 commit comments

Comments
 (0)