@@ -218,6 +218,8 @@ public class KMKeymasterApplet extends Applet implements AppletEvent, ExtendedLe
218218 // version number whenever you change anything related to
219219 // KeyBlob (structure, encryption algorithm etc).
220220 public static final short KEYBLOB_CURRENT_VERSION = 2 ;
221+ // KeyBlob Verion 1 constant.
222+ public static final short KEYBLOB_VERSION_1 = 1 ;
221223 // KeyBlob array size constants.
222224 public static final byte SYM_KEY_BLOB_SIZE_V2 = 6 ;
223225 public static final byte ASYM_KEY_BLOB_SIZE_V2 = 7 ;
@@ -3798,7 +3800,7 @@ private static void makeKeyCharacteristics(byte[] scratchPad) {
37983800
37993801 private static void createEncryptedKeyBlob (byte [] scratchPad ) {
38003802 // make root of trust blob
3801- data [ROT ] = readROT (scratchPad );
3803+ data [ROT ] = readROT (scratchPad , KEYBLOB_CURRENT_VERSION );
38023804 if (data [ROT ] == KMType .INVALID_VALUE ) {
38033805 KMException .throwIt (KMError .UNKNOWN_ERROR );
38043806 }
@@ -4016,7 +4018,7 @@ private void processDecryptSecret(short version, short appId, short appData, byt
40164018 private void parseEncryptedKeyBlob (short keyBlob , short appId , short appData ,
40174019 byte [] scratchPad , short version ) {
40184020 // make root of trust blob
4019- data [ROT ] = readROT (scratchPad );
4021+ data [ROT ] = readROT (scratchPad , version );
40204022 if (data [ROT ] == KMType .INVALID_VALUE ) {
40214023 KMException .throwIt (KMError .UNKNOWN_ERROR );
40224024 }
@@ -4029,10 +4031,16 @@ private void parseEncryptedKeyBlob(short keyBlob, short appId, short appData,
40294031 }
40304032
40314033 // Read RoT
4032- public static short readROT (byte [] scratchPad ) {
4034+ public static short readROT (byte [] scratchPad , short version ) {
40334035 Util .arrayFillNonAtomic (scratchPad ,(short )0 , (short )256 ,(byte )0 );
40344036 short len = kmDataStore .getBootKey (scratchPad , (short )0 );
4035- len += kmDataStore .getVerifiedBootHash (scratchPad , (short )len );
4037+ // As per IKeyMintDevice.aidl specification The root of trust
4038+ // consists of verifyBootKey, boot state and device locked.
4039+ if (version <= KEYBLOB_VERSION_1 ) {
4040+ // To parse old keyblobs verified boot hash is included in
4041+ // the root of trust.
4042+ len += kmDataStore .getVerifiedBootHash (scratchPad , (short )len );
4043+ }
40364044 short bootState = kmDataStore .getBootState ();
40374045 len = Util .setShort (scratchPad , len , bootState );
40384046 if (kmDataStore .isDeviceBootLocked ()){
0 commit comments