Skip to content

Commit 70c0106

Browse files
author
Chirag Pathak
committed
Bug fixes
1 parent dd6ebfe commit 70c0106

File tree

2 files changed

+31
-112
lines changed

2 files changed

+31
-112
lines changed

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

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,8 @@ private void processGetHmacSharingParamCmd(APDU apdu) {
691691
short seed = KMByteBlob.instance((short) 0);
692692
KMHmacSharingParameters.cast(params).setNonce(nonce);
693693
KMHmacSharingParameters.cast(params).setSeed(seed);
694-
print(KMByteBlob.cast(nonce).getBuffer(), KMByteBlob.cast(nonce).getStartOff(),
695-
KMByteBlob.cast(nonce).length());
694+
//print(KMByteBlob.cast(nonce).getBuffer(), KMByteBlob.cast(nonce).getStartOff(),
695+
// KMByteBlob.cast(nonce).length());
696696
// prepare the response
697697
short resp = KMArray.instance((short) 2);
698698
KMArray.cast(resp).add((short) 0, KMInteger.uint_16(KMError.OK));
@@ -771,9 +771,9 @@ private void processComputeSharedHmacCmd(APDU apdu) {
771771
short found = 0;
772772
//tmpVariables[9]
773773
short nonce = repository.getHmacNonce();
774-
print(KMByteBlob.cast(nonce).getBuffer(),
775-
KMByteBlob.cast(nonce).getStartOff(),
776-
KMByteBlob.cast(nonce).length());
774+
//print(KMByteBlob.cast(nonce).getBuffer(),
775+
// KMByteBlob.cast(nonce).getStartOff(),
776+
// KMByteBlob.cast(nonce).length());
777777

778778
while (paramIndex < paramsLen) {
779779
// read HmacSharingParam
@@ -816,11 +816,11 @@ private void processComputeSharedHmacCmd(APDU apdu) {
816816
// Check if the nonce generated here is present in the hmacSharingParameters array.
817817
// Otherwise throw INVALID_ARGUMENT error.
818818
if (found == 1) {
819-
print(repository.getHeap(),
820-
(short) (concateBuffer + bufferIndex),nonceLen);
821-
print(KMByteBlob.cast(nonce).getBuffer(),
822-
KMByteBlob.cast(nonce).getStartOff(),
823-
nonceLen);
819+
//print(repository.getHeap(),
820+
// (short) (concateBuffer + bufferIndex),nonceLen);
821+
//print(KMByteBlob.cast(nonce).getBuffer(),
822+
// KMByteBlob.cast(nonce).getStartOff(),
823+
// nonceLen);
824824
if (0
825825
== Util.arrayCompare(
826826
repository.getHeap(),
@@ -1344,20 +1344,10 @@ protected short getBootKey(byte[] scratchPad){
13441344
short len = seProvider.getVerifiedBootHash(scratchPad,(short)0);
13451345
if(len != VERIFIED_BOOT_KEY_SIZE) {
13461346
KMException.throwIt(KMError.UNKNOWN_ERROR);
1347+
}
13471348
return KMByteBlob.instance(scratchPad,(short)0, VERIFIED_BOOT_KEY_SIZE);
13481349
}
1349-
1350-
private boolean isEmpty(byte[] buf, short offset, short len) {
1351-
boolean empty = true;
1352-
short index = 0;
1353-
while (index < len) {
1354-
if (buf[(short) (index + offset)] != 0) {
1355-
empty = false;
1356-
break;
1357-
}
1358-
index++;
1359-
}
1360-
1350+
13611351
protected short getVerifiedBootHash(byte[] scratchPad){
13621352
Util.arrayFillNonAtomic(scratchPad, (short)0, VERIFIED_BOOT_HASH_SIZE, (byte)0);
13631353
short len = seProvider.getVerifiedBootHash(scratchPad,(short)0);
@@ -3023,6 +3013,18 @@ private void processInitStrongBoxCmd(APDU apdu) {
30233013
setOsVersion(osVersion);
30243014
setOsPatchLevel(osPatchLevel);
30253015
setVendorPatchLevel(vendorPatchLevel);
3016+
System.out.println("============ OS Version et al ==========");
3017+
// print(KMInteger.cast(osVersion).getBuffer(),
3018+
// KMInteger.cast(osVersion).getStartOff(),
3019+
// KMInteger.cast(osVersion).length());
3020+
3021+
// print(KMInteger.cast(osPatchLevel).getBuffer(),
3022+
// KMInteger.cast(osPatchLevel).getStartOff(),
3023+
// KMInteger.cast(osPatchLevel).length());
3024+
3025+
// print(KMInteger.cast(vendorPatchLevel).getBuffer(),
3026+
// KMInteger.cast(vendorPatchLevel).getStartOff(),
3027+
// KMInteger.cast(vendorPatchLevel).length());
30263028
}
30273029

30283030
public void reboot(){
@@ -3052,14 +3054,14 @@ protected void setOsVersion(short version){
30523054
KMInteger.cast(version).length());
30533055
}
30543056

3055-
protected void setVendorPatchLevel(short patch){
3057+
protected void setOsPatchLevel(short patch){
30563058
repository.setOsPatch(
30573059
KMInteger.cast(patch).getBuffer(),
30583060
KMInteger.cast(patch).getStartOff(),
30593061
KMInteger.cast(patch).length());
30603062
}
30613063

3062-
protected void setOsPatchLevel(short patch){
3064+
protected void setVendorPatchLevel(short patch){
30633065
repository.setVendorPatchLevel(
30643066
KMInteger.cast(patch).getBuffer(),
30653067
KMInteger.cast(patch).getStartOff(),
@@ -3129,15 +3131,15 @@ private void processGenerateKey(APDU apdu) {
31293131
KMArray.cast(resp).add((short) 3, data[CERTIFICATE]);
31303132
sendOutgoing(apdu, resp);
31313133
}
3132-
3134+
/*
31333135
private static void print(byte[] buf, short start, short length){
31343136
StringBuilder sb = new StringBuilder(length * 2);
31353137
for(short i = start; i < (start+length); i ++){
31363138
sb.append(String.format("%02x", buf[i]));
31373139
}
31383140
System.out.println( sb.toString());
31393141
}
3140-
3142+
*/
31413143
private void generateAttestation(byte[] scratchPad){
31423144
KMAttestationCert cert = makeCert(scratchPad);
31433145
if(cert == null) {// No certificate
@@ -3155,9 +3157,9 @@ private void generateAttestation(byte[] scratchPad){
31553157
KMByteBlob.cast(certData).setStartOff(cert.getCertStart());
31563158
KMByteBlob.cast(certData).setLength(cert.getCertLength());
31573159

3158-
print(KMByteBlob.cast(certData).getBuffer(),
3159-
KMByteBlob.cast(certData).getStartOff(),
3160-
KMByteBlob.cast(certData).length());
3160+
//print(KMByteBlob.cast(certData).getBuffer(),
3161+
// KMByteBlob.cast(certData).getStartOff(),
3162+
// KMByteBlob.cast(certData).length());
31613163
// Initialize the certificate as array of blob
31623164
data[CERTIFICATE] = KMArray.instance((short)1);
31633165
KMArray.cast(data[CERTIFICATE]).add((short)0, certData);

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

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public class KMRepository implements KMUpgradable {
5959
public static final short DEVICE_LOCK_FLAG_SIZE = 1;
6060

6161
// Class Attributes
62-
// private Object[] operationStateTable;
6362
private byte[] heap;
6463
private short heapIndex;
6564
private byte[] dataTable;
@@ -288,48 +287,6 @@ public short getOsPatch() {
288287
}
289288
}
290289

291-
/*
292-
public void deleteAttIds() {
293-
clearDataEntry(ATT_ID_BRAND);
294-
clearDataEntry(ATT_ID_MEID);
295-
clearDataEntry(ATT_ID_DEVICE);
296-
clearDataEntry(ATT_ID_IMEI);
297-
clearDataEntry(ATT_ID_MODEL);
298-
clearDataEntry(ATT_ID_PRODUCT);
299-
clearDataEntry(ATT_ID_SERIAL);
300-
clearDataEntry(ATT_ID_MANUFACTURER);
301-
}
302-
303-
304-
public short getBootPatchLevel() {
305-
short blob = readData(BOOT_PATCH_LEVEL);
306-
if (blob != 0) {
307-
return KMInteger.uint_32(
308-
KMByteBlob.cast(blob).getBuffer(), KMByteBlob.cast(blob).getStartOff());
309-
} else {
310-
return KMInteger.uint_32(zero, (short) 0);
311-
}
312-
}
313-
314-
public short getVerifiedBootKey() {
315-
return readData(BOOT_VERIFIED_BOOT_KEY);
316-
}
317-
318-
public short getVerifiedBootHash() {
319-
return readData(BOOT_VERIFIED_BOOT_HASH);
320-
}
321-
322-
public boolean getBootLoaderLock() {
323-
short blob = readData(BOOT_DEVICE_LOCKED_STATUS);
324-
return (byte) ((getHeap())[KMByteBlob.cast(blob).getStartOff()] & 0xFE) != 0;
325-
}
326-
327-
public byte getBootState() {
328-
short blob = readData(BOOT_VERIFIED_BOOT_STATE);
329-
return (getHeap())[KMByteBlob.cast(blob).getStartOff()];
330-
}
331-
*/
332-
333290
public boolean getDeviceLock() {
334291
short blob = readData(DEVICE_LOCKED);
335292
return (byte) ((getHeap())[KMByteBlob.cast(blob).getStartOff()] & 0xFE) != 0;
@@ -401,46 +358,6 @@ public void setOsPatch(byte[] buf, short start, short len) {
401358
}
402359
writeDataEntry(BOOT_OS_PATCH, buf, start, len);
403360
}
404-
/*
405-
406-
public void setBootPatchLevel(byte[] buf, short start, short len) {
407-
if (len != BOOT_PATCH_SIZE) {
408-
KMException.throwIt(KMError.INVALID_INPUT_LENGTH);
409-
}
410-
writeDataEntry(BOOT_PATCH_LEVEL, buf, start, len);
411-
}
412-
413-
public void setBootloaderLocked(boolean flag) {
414-
short start = alloc(DEVICE_LOCK_FLAG_SIZE);
415-
if (flag) {
416-
(getHeap())[start] = (byte) ((getHeap())[start] | 0x01);
417-
} else {
418-
(getHeap())[start] = (byte) ((getHeap())[start] & 0xFE);
419-
}
420-
writeDataEntry(BOOT_DEVICE_LOCKED_STATUS, getHeap(), start, DEVICE_LOCK_FLAG_SIZE);
421-
}
422-
423-
public void setVerifiedBootKey(byte[] buf, short start, short len) {
424-
if (len > BOOT_KEY_MAX_SIZE) {
425-
KMException.throwIt(KMError.INVALID_INPUT_LENGTH);
426-
}
427-
writeDataEntry(BOOT_VERIFIED_BOOT_KEY, buf, start, len);
428-
}
429-
430-
431-
public void setVerifiedBootHash(byte[] buf, short start, short len) {
432-
if (len > BOOT_HASH_MAX_SIZE) {
433-
KMException.throwIt(KMError.INVALID_INPUT_LENGTH);
434-
}
435-
writeDataEntry(BOOT_VERIFIED_BOOT_HASH, buf, start, len);
436-
}
437-
438-
public void setBootState(byte state) {
439-
short start = alloc(BOOT_STATE_SIZE);
440-
(getHeap())[start] = state;
441-
writeDataEntry(BOOT_VERIFIED_BOOT_STATE, getHeap(), start, BOOT_STATE_SIZE);
442-
}
443-
*/
444361
@Override
445362
public void onSave(Element ele) {
446363
ele.write(dataIndex);

0 commit comments

Comments
 (0)