Skip to content

Commit

Permalink
Merge pull request #123 from subrahmanyaman/rot_changes
Browse files Browse the repository at this point in the history
Rot changes - remove VerifiedBootHash from the keyBlobs hidden parameters.
  • Loading branch information
mdwivedi authored Apr 29, 2022
2 parents ade6e7e + ae9e180 commit bee6747
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Applet/src/com/android/javacard/keymaster/KMKeymasterApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ public class KMKeymasterApplet extends Applet implements AppletEvent, ExtendedLe
// version number whenever you change anything related to
// KeyBlob (structure, encryption algorithm etc).
public static final short KEYBLOB_CURRENT_VERSION = 2;
// KeyBlob Verion 1 constant.
public static final short KEYBLOB_VERSION_1 = 1;
// KeyBlob array size constants.
public static final byte SYM_KEY_BLOB_SIZE_V2 = 6;
public static final byte ASYM_KEY_BLOB_SIZE_V2 = 7;
Expand Down Expand Up @@ -3798,7 +3800,7 @@ private static void makeKeyCharacteristics(byte[] scratchPad) {

private static void createEncryptedKeyBlob(byte[] scratchPad) {
// make root of trust blob
data[ROT] = readROT(scratchPad);
data[ROT] = readROT(scratchPad, KEYBLOB_CURRENT_VERSION);
if (data[ROT] == KMType.INVALID_VALUE) {
KMException.throwIt(KMError.UNKNOWN_ERROR);
}
Expand Down Expand Up @@ -4016,7 +4018,7 @@ private void processDecryptSecret(short version, short appId, short appData, byt
private void parseEncryptedKeyBlob(short keyBlob, short appId, short appData,
byte[] scratchPad, short version) {
// make root of trust blob
data[ROT] = readROT(scratchPad);
data[ROT] = readROT(scratchPad, version);
if (data[ROT] == KMType.INVALID_VALUE) {
KMException.throwIt(KMError.UNKNOWN_ERROR);
}
Expand All @@ -4029,10 +4031,16 @@ private void parseEncryptedKeyBlob(short keyBlob, short appId, short appData,
}

// Read RoT
public static short readROT(byte[] scratchPad) {
public static short readROT(byte[] scratchPad, short version) {
Util.arrayFillNonAtomic(scratchPad,(short)0, (short)256,(byte)0);
short len = kmDataStore.getBootKey(scratchPad, (short)0);
len += kmDataStore.getVerifiedBootHash(scratchPad, (short)len);
// As per IKeyMintDevice.aidl specification The root of trust
// consists of verifyBootKey, boot state and device locked.
if (version <= KEYBLOB_VERSION_1) {
// To parse old keyblobs verified boot hash is included in
// the root of trust.
len += kmDataStore.getVerifiedBootHash(scratchPad, (short)len);
}
short bootState = kmDataStore.getBootState();
len = Util.setShort(scratchPad, len, bootState);
if(kmDataStore.isDeviceBootLocked()){
Expand Down

0 comments on commit bee6747

Please sign in to comment.