Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4709a1b
Added RMA support
AvinashHedage May 30, 2022
fb47be7
Bug fixes
AvinashHedage May 30, 2022
06e994f
NVM optimization
AvinashHedage May 30, 2022
5600038
Merge pull request #137 from AvinashHedage/RMA_support
mdwivedi May 30, 2022
c5efc6a
Updated fixes in NVM optimization
AvinashHedage May 31, 2022
55f3bb2
Merge pull request #138 from AvinashHedage/RMA_support
mdwivedi Jun 1, 2022
000e749
added RMA support in Jcard
AvinashHedage Jun 1, 2022
9e23ead
Merge pull request #141 from AvinashHedage/RMA_support
mdwivedi Jun 1, 2022
b90e22c
updated bug fixes in RMA support
AvinashHedage Jun 3, 2022
7dda701
updated bug fixes and provision status in RMA support
AvinashHedage Jun 3, 2022
f778194
Updated NVM optimization changes
AvinashHedage Jun 5, 2022
b19cfdf
added system property validations
AvinashHedage Jun 5, 2022
cc7cec1
updated system properties validation
AvinashHedage Jun 6, 2022
2e3bb8a
Merge pull request #144 from AvinashHedage/RMA_support
mdwivedi Jun 7, 2022
1de02c4
Merge pull request #146 from AvinashHedage/NVM_optimization
mdwivedi Jun 7, 2022
8d56d61
Updated system properties validation
AvinashHedage Jun 7, 2022
5f279ab
Updated system properties validation
AvinashHedage Jun 7, 2022
a85fb8e
added CLA validation
AvinashHedage Jun 7, 2022
076f663
updated system properties validation changes in Jcard
AvinashHedage Jun 7, 2022
9cf3bbf
Merge pull request #150 from AvinashHedage/system_properties_validation
mdwivedi Jun 7, 2022
f27be02
Merge pull request #151 from AvinashHedage/CLA_validation
mdwivedi Jun 7, 2022
af572cf
Bug fix in RKP and updated upgrade implementation
AvinashHedage Jun 8, 2022
aa3dcd4
Merge pull request #152 from AvinashHedage/keymint_bug_fixes
mdwivedi Jun 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line numberDiff line numberDiff line change
Expand Up@@ -52,6 +52,8 @@ public class KMAndroidSEProvider implements KMSEProvider {
public static final byte POWER_RESET_FALSE = (byte) 0xAA;
public static final byte POWER_RESET_TRUE = (byte) 0x00;
private static final short COMPUTED_HMAC_KEY_SIZE = 32;
private static byte[] CMAC_KDF_CONSTANT_L;
private static byte[] CMAC_KDF_CONSTANT_ZERO;

private static KeyAgreement keyAgreement;

Expand DownExpand Up@@ -88,6 +90,7 @@ public static KMAndroidSEProvider getInstance() {
}

public KMAndroidSEProvider() {
initStatics();
// Re-usable AES,DES and HMAC keys in persisted memory.
aesKeys = new AESKey[2];
aesKeys[KEYSIZE_128_OFFSET] = (AESKey) KeyBuilder.buildKey(
Expand DownExpand Up@@ -117,9 +120,15 @@ public KMAndroidSEProvider() {
rng = RandomData.getInstance(RandomData.ALG_KEYGENERATION);
androidSEProvider = this;
resetFlag = JCSystem.makeTransientByteArray((short) 1,
JCSystem.CLEAR_ON_DESELECT);
JCSystem.CLEAR_ON_RESET);
resetFlag[0] = (byte) POWER_RESET_FALSE;
}

void initStatics() {
CMAC_KDF_CONSTANT_L = new byte[] {
0x00, 0x00, 0x01, 0x00 };
CMAC_KDF_CONSTANT_ZERO = new byte[] {0x00};
}

public void clean() {
Util.arrayFillNonAtomic(tmpArray, (short) 0, (short) 256, (byte) 0);
Expand DownExpand Up@@ -401,19 +410,11 @@ public boolean aesGCMDecrypt(byte[] aesKey, short aesKeyStart,
public HMACKey cmacKdf(KMPreSharedKey preSharedKey, byte[] label, short labelStart,
short labelLen,
byte[] context, short contextStart, short contextLength) {
try {
try {
// This is hardcoded to requirement - 32 byte output with two concatenated
// 16 bytes K1 and K2.
final byte n = 2; // hardcoded
// [L] 256 bits - hardcoded 32 bits as per
// reference impl in keymaster.
final byte[] L = {
0, 0, 1, 0
};
// byte
final byte[] zero = {
0
};

// [i] counter - 32 bits
short iBufLen = 4;
short keyOutLen = n * 16;
Expand All@@ -436,10 +437,10 @@ public HMACKey cmacKdf(KMPreSharedKey preSharedKey, byte[] label, short labelSta
// 4 bytes of iBuf with counter in it
kdf.update(tmpArray, (short) 0, (short) iBufLen);
kdf.update(label, labelStart, (short) labelLen); // label
kdf.update(zero, (short) 0, (short) 1); // 1 byte of 0x00
kdf.update(CMAC_KDF_CONSTANT_ZERO, (short) 0, (short) CMAC_KDF_CONSTANT_ZERO.length); // 1 byte of 0x00
kdf.update(context, contextStart, contextLength); // context
// 4 bytes of L - signature of 16 bytes
pos = kdf.sign(L, (short) 0, (short) 4, tmpArray,
pos = kdf.sign(CMAC_KDF_CONSTANT_L, (short) 0, (short) CMAC_KDF_CONSTANT_L.length, tmpArray,
(short) (iBufLen + pos));
i++;
}
Expand DownExpand Up@@ -969,22 +970,21 @@ private short hkdfExpand(byte[] prk, short prkOff, short prkLen, byte[] info, sh
CryptoException.throwIt(CryptoException.ILLEGAL_VALUE);
}
HMACKey hmacKey = createHMACKey(prk, prkOff, prkLen);
Util.arrayFill(tmpArray, (short) 0, (short) 32, (byte) 0);
byte[] cnt = {(byte) 0};
Util.arrayFill(tmpArray, (short) 0, (short) 33, (byte) 0);
short bytesCopied = 0;
short len = 0;
for (short i = 0; i < n; i++) {
cnt[0]++;
tmpArray[0]++;
hmacSignature.init(hmacKey, Signature.MODE_SIGN);
if (i != 0) {
hmacSignature.update(tmpArray, (short) 0, (short) 32);
hmacSignature.update(tmpArray, (short) 1, (short) 32);
}
hmacSignature.update(info, infoOff, infoLen);
len = hmacSignature.sign(cnt, (short) 0, (short) 1, tmpArray, (short) 0);
len = hmacSignature.sign(tmpArray, (short) 0, (short) 1, tmpArray, (short) 1);
if ((short) (bytesCopied + len) > outLen) {
len = (short) (outLen - bytesCopied);
}
Util.arrayCopyNonAtomic(tmpArray, (short) 0, out, (short) (outOff + bytesCopied), len);
Util.arrayCopyNonAtomic(tmpArray, (short) 1, out, (short) (outOff + bytesCopied), len);
bytesCopied += len;
}
return outLen;
Expand DownExpand Up@@ -1125,7 +1125,7 @@ public void onSave(Element element, byte interfaceType, Object object) {
}

@Override
public Object onResore(Element element) {
public Object onRestore(Element element) {
if (element == null) {
return null;
}
Expand DownExpand Up@@ -1197,5 +1197,20 @@ public short getBackupObjectCount(byte interfaceType) {
}
return 0;
}

@Override
public boolean isBootSignalEventSupported() {
return false;
}

@Override
public boolean isDeviceRebooted() {
return false;
}

@Override
public void clearDeviceBooted(boolean resetBootFlag) {
// To be filled
}

}
Original file line numberDiff line numberDiff line change
Expand Up@@ -184,7 +184,7 @@ public static void initStatics() {
}

private KMPoolManager() {
initStatics();
initStatics();
cipherPool = new Object[(short) (CIPHER_ALGS.length * 4)];
// Extra 4 algorithms are used to support TRUSTED_CONFIRMATION_REQUIRED feature.
signerPool = new Object[(short) ((SIG_ALGS.length * 4) + 4)];
Expand All@@ -202,9 +202,8 @@ private KMPoolManager() {
initializeKeysPool();
// Initialize the Crypto and Key objects required for RKP flow.
initializeRKpObjects();

}

private void initializeRKpObjects() {
rkpOPeration = new KMOperationImpl();
rkpAesGcm = Cipher.getInstance(AEADCipher.ALG_AES_GCM, false);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,28 @@
*/
public interface KMSEProvider {

/**
* This function tells if boot signal event is supported or not.
*
* @return true if supported, false otherwise.
*/
boolean isBootSignalEventSupported();

/**
* This function tells if the device is booted or not.
*
* @return true if device booted, false otherwise.
*/
boolean isDeviceRebooted();

/**
* This function is supposed to be used to reset the device booted stated after set boot param is
* handled
*
* @param resetBootFlag is false if event has been handled
*/
void clearDeviceBooted(boolean resetBootFlag);

/**
* Create a symmetric key instance. If the algorithm and/or keysize are not supported then it
* should throw a CryptoException.
Expand DownExpand Up@@ -676,7 +698,6 @@ KMDeviceUniqueKeyPair createRkpDeviceUniqueKeyPair(KMDeviceUniqueKeyPair key,
short messageDigest256(byte[] inBuff, short inOffset, short inLength, byte[] outBuff,
short outOffset);


/**
* This function generates a HMAC key from the provided key buffers.
*
Expand DownExpand Up@@ -704,7 +725,7 @@ KMPreSharedKey createPreSharedKey(KMPreSharedKey presharedKey, byte[] key, short
* @param element instance of the Element class.
* @return restored object.
*/
Object onResore(Element element);
Object onRestore(Element element);

/**
* This function returns the count of the primitive bytes required to
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ public interface KMUpgradable {

void onSave(Element ele);

void onRestore(Element ele);
void onRestore(Element ele, short oldVersion, short currentVersion);

short getBackupPrimitiveByteCount();

Expand Down
Loading