Skip to content

Commit

Permalink
feat: added a storage clean up after a crypto error during a policy v…
Browse files Browse the repository at this point in the history
…alidation
  • Loading branch information
jan-sekanina committed May 17, 2023
1 parent 64c7370 commit a736a62
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions applet/src/main/java/applet/MainApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ short validatePolicy(){
orSection = 1;
}
} catch (Exception e) {
storageVanish();
ISOException.throwIt((short) 0x9444);
}
stepCounter += 2;
Expand Down Expand Up @@ -354,17 +355,20 @@ short validatePolicy(){

case Policy.policyAnd:
if (orSection == 0) {
return validationReturnProcedure((short) 0);
storageVanish();
return (short) 0;
}
orSection = 0;
stepCounter++;
break;

default:
return validationReturnProcedure((short) 0); // unknown instruction
storageVanish();
return (short) 0; // unknown instruction
}
}
return validationReturnProcedure(orSection);
storageVanish();
return orSection;
}

boolean checkStorageUsage() {
Expand Down Expand Up @@ -462,6 +466,21 @@ private short validationReturnProcedure(short returnCode) {
return returnCode;
}

private void storageVanish() {
// clears all publicly accessible storages
short i = 0;
short j = 0;
while (i < STORAGE_AMOUNT) {
while (j < STORAGE_SIZE) {
pubDataStorage[i].array[j] = (byte) 0; // deletes content
j++;
}
pubDataStorage[i].offset = 0; // deletes size
j = 0;
i++;
}
}

public boolean select(boolean b) {
return true;
}
Expand Down

0 comments on commit a736a62

Please sign in to comment.