Skip to content

Commit f55412a

Browse files
Merge pull request #80 from divegeek/Javacard_KM_41_AOSP_UPMERGE_0630
Javacard km 41 aosp upmerge 0630
2 parents e3e4bbf + 32850ff commit f55412a

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

Applet/AndroidSEProvider/src/com/android/javacard/keymaster/KMAndroidSEApplet.java

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void onRestore(Element element) {
7171
keymasterState = element.readByte();
7272
repository.onRestore(element, oldPackageVersion, KM_APPLET_PACKAGE_VERSION);
7373
seProvider.onRestore(element, oldPackageVersion, KM_APPLET_PACKAGE_VERSION);
74-
handleDataUpgrade();
74+
handleDataUpgrade(oldPackageVersion);
7575
}
7676

7777
@Override
@@ -99,38 +99,32 @@ public Element onSave() {
9999
}
100100

101101
public boolean isUpgradeAllowed(short oldVersion) {
102-
boolean upgradeAllowed = false;
103-
short oldMajorVersion = (short) ((oldVersion >> 8) & 0x00FF);
104-
short oldMinorVersion = (short) (oldVersion & 0x00FF);
105-
short currentMajorVersion = (short) (KM_APPLET_PACKAGE_VERSION >> 8 & 0x00FF);
106-
short currentMinorVersion = (short) (KM_APPLET_PACKAGE_VERSION & 0x00FF);
107102
// Downgrade of the Applet is not allowed.
108-
// Upgrade is not allowed to a next version which is not immediate.
109-
if ((short) (currentMajorVersion - oldMajorVersion) == 1) {
110-
if (currentMinorVersion == 0) {
111-
upgradeAllowed = true;
112-
}
113-
} else if ((short) (currentMajorVersion - oldMajorVersion) == 0) {
114-
if (currentMinorVersion >= oldMinorVersion) {
115-
upgradeAllowed = true;
116-
}
103+
if (oldVersion > KM_APPLET_PACKAGE_VERSION) {
104+
return false;
117105
}
118-
return upgradeAllowed;
106+
return true;
119107
}
120108

121-
public void handleDataUpgrade() {
122-
// In version 3.0, two new provisionStatus states are introduced
123-
// 1. PROVISION_STATUS_SE_LOCKED - bit 6 of provisionStatus
124-
// 2. PROVISION_STATUS_OEM_PUBLIC_KEY - bit 7 of provisionStatus
125-
// In the process of upgrade from 2.0 to 3.0 OEM PUBLIC Key is provisioned
126-
// in SEProvider.so update the state of the provision status by making
127-
// 7th bit HIGH.
128-
provisionStatus |= PROVISION_STATUS_OEM_ROOT_PUBLIC_KEY;
129-
// Check if the provisioning is already locked. If so update
130-
// the state of the provisionStatus by making 6th bit HIGH.
131-
// Lock the SE Factory provisioning as well.
132-
if ( 0 != (provisionStatus & PROVISION_STATUS_OEM_PROVISIONING_LOCKED)) {
133-
provisionStatus |= PROVISION_STATUS_SE_FACTORY_PROVISIONING_LOCKED;
109+
public void handleDataUpgrade(short oldVersion) {
110+
switch (oldVersion) {
111+
case KM_APPLET_PACKAGE_VERSION_2_0:
112+
// In version 3.0, two new provisionStatus states are introduced
113+
// 1. PROVISION_STATUS_SE_LOCKED - bit 6 of provisionStatus
114+
// 2. PROVISION_STATUS_OEM_PUBLIC_KEY - bit 7 of provisionStatus
115+
// In the process of upgrade from 2.0 to 3.0 OEM PUBLIC Key is provisioned
116+
// in SEProvider.so update the state of the provision status by making
117+
// 7th bit HIGH.
118+
provisionStatus |= PROVISION_STATUS_OEM_ROOT_PUBLIC_KEY;
119+
// Check if the provisioning is already locked. If so update
120+
// the state of the provisionStatus by making 6th bit HIGH.
121+
// Lock the SE Factory provisioning as well.
122+
if (0 != (provisionStatus & PROVISION_STATUS_OEM_PROVISIONING_LOCKED)) {
123+
provisionStatus |= PROVISION_STATUS_SE_FACTORY_PROVISIONING_LOCKED;
124+
}
125+
break;
126+
default:
127+
break;
134128
}
135129
}
136130
}

Applet/AndroidSEProvider/src/com/android/javacard/keymaster/KMAndroidSEProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public class KMAndroidSEProvider implements KMSEProvider {
112112
private static final short HMAC_MAX_OPERATIONS = 8;
113113
private static final short COMPUTED_HMAC_KEY_SIZE = 32;
114114
public static final short INVALID_DATA_VERSION = 0x7FFF;
115+
public static final short KM_APPLET_PACKAGE_VERSION_2_0 = 0x0200; // 2.0
115116

116117
private static final short CERT_CHAIN_OFFSET = 0;
117118
private static final short CERT_ISSUER_OFFSET = KMConfigurations.CERT_CHAIN_MAX_SIZE;
@@ -1305,10 +1306,13 @@ public void onRestore(Element element, short oldVersion, short currentVersion) {
13051306
attestationKey = KMECPrivateKey.onRestore(element);
13061307
preSharedKey = KMHmacKey.onRestore(element);
13071308
computedHmacKey = KMHmacKey.onRestore(element);
1308-
if (oldVersion == 0x200) {
1309+
switch(oldVersion) {
1310+
case KM_APPLET_PACKAGE_VERSION_2_0:
13091311
createOemRootPublicKey();
1310-
} else {
1312+
break;
1313+
default:
13111314
oemRootPublicKey = (byte[]) element.readObject();
1315+
break;
13121316
}
13131317
}
13141318

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class KMKeymasterApplet extends Applet implements AppletEvent, ExtendedLe
4646
// MSB byte is for Major version and LSB byte is for Minor version.
4747
// Whenever there is an applet upgrade change the version.
4848
public static final short KM_APPLET_PACKAGE_VERSION = 0x0300; // 3.0
49+
public static final short KM_APPLET_PACKAGE_VERSION_2_0 = 0x0200; // 2.0
4950

5051
// "Keymaster HMAC Verification" - used for HMAC key verification.
5152
public static final byte[] sharingCheck = {

0 commit comments

Comments
 (0)