diff options
author | dcashman <dcashman@google.com> | 2015-06-16 21:52:56 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-06-16 21:52:58 +0000 |
commit | 2f902959245f1cae57827025b8711a059faaf782 (patch) | |
tree | 928a728b1b997a0307703a2552dd737c370ef91e | |
parent | 52ca020722e8db42f9240de6959567d734f3ac6f (diff) | |
parent | 87f794f0bf8b53d6c983968f398c4bde4cb6a014 (diff) | |
download | frameworks_base-2f902959245f1cae57827025b8711a059faaf782.zip frameworks_base-2f902959245f1cae57827025b8711a059faaf782.tar.gz frameworks_base-2f902959245f1cae57827025b8711a059faaf782.tar.bz2 |
Merge "Make keysetmgrservice gurantees explicit." into mnc-dev
3 files changed, 156 insertions, 75 deletions
diff --git a/services/core/java/com/android/server/pm/KeySetManagerService.java b/services/core/java/com/android/server/pm/KeySetManagerService.java index 1ee07a5..0de0c92 100644 --- a/services/core/java/com/android/server/pm/KeySetManagerService.java +++ b/services/core/java/com/android/server/pm/KeySetManagerService.java @@ -16,6 +16,9 @@ package com.android.server.pm; +import static android.content.pm.PackageManager.INSTALL_FAILED_INVALID_APK; + +import com.android.internal.util.Preconditions; import android.content.pm.PackageParser; import android.util.ArrayMap; import android.util.ArraySet; @@ -98,6 +101,7 @@ public class KeySetManagerService { mRefCount++; return; } + public long decrRefCountLPw() { mRefCount--; return mRefCount; @@ -168,25 +172,82 @@ public class KeySetManagerService { } /** + * addScannedPackageLPw directly modifies the package metadata in pm.Settings + * at a point of no-return. We need to make sure that the scanned package does + * not contain bad keyset meta-data that could generate an incorrect + * PackageSetting. Verify that there is a signing keyset, there are no issues + * with null objects, and the upgrade and defined keysets match. + * + * Returns true if the package can safely be added to the keyset metadata. + */ + public void assertScannedPackageValid(PackageParser.Package pkg) + throws PackageManagerException { + if (pkg == null || pkg.packageName == null) { + throw new PackageManagerException(INSTALL_FAILED_INVALID_APK, + "Passed invalid package to keyset validation."); + } + ArraySet<PublicKey> signingKeys = pkg.mSigningKeys; + if (signingKeys == null || !(signingKeys.size() > 0) || signingKeys.contains(null)) { + throw new PackageManagerException(INSTALL_FAILED_INVALID_APK, + "Package has invalid signing-key-set."); + } + ArrayMap<String, ArraySet<PublicKey>> definedMapping = pkg.mKeySetMapping; + if (definedMapping != null) { + if (definedMapping.containsKey(null) || definedMapping.containsValue(null)) { + throw new PackageManagerException(INSTALL_FAILED_INVALID_APK, + "Package has null defined key set."); + } + int defMapSize = definedMapping.size(); + for (int i = 0; i < defMapSize; i++) { + if (!(definedMapping.valueAt(i).size() > 0) + || definedMapping.valueAt(i).contains(null)) { + throw new PackageManagerException(INSTALL_FAILED_INVALID_APK, + "Package has null/no public keys for defined key-sets."); + } + } + } + ArraySet<String> upgradeAliases = pkg.mUpgradeKeySets; + if (upgradeAliases != null) { + if (definedMapping == null || !(definedMapping.keySet().containsAll(upgradeAliases))) { + throw new PackageManagerException(INSTALL_FAILED_INVALID_APK, + "Package has upgrade-key-sets without corresponding definitions."); + } + } + } + + public void addScannedPackageLPw(PackageParser.Package pkg) { + Preconditions.checkNotNull(pkg, "Attempted to add null pkg to ksms."); + Preconditions.checkNotNull(pkg.packageName, "Attempted to add null pkg to ksms."); + PackageSetting ps = mPackages.get(pkg.packageName); + Preconditions.checkNotNull(ps, "pkg: " + pkg.packageName + + "does not have a corresponding entry in mPackages."); + addSigningKeySetToPackageLPw(ps, pkg.mSigningKeys); + if (pkg.mKeySetMapping != null) { + addDefinedKeySetsToPackageLPw(ps, pkg.mKeySetMapping); + if (pkg.mUpgradeKeySets != null) { + addUpgradeKeySetsToPackageLPw(ps, pkg.mUpgradeKeySets); + } + } + } + + /** * Informs the system that the given package was signed by the provided KeySet. */ - public void addSigningKeySetToPackageLPw(String packageName, + void addSigningKeySetToPackageLPw(PackageSetting pkg, ArraySet<PublicKey> signingKeys) { /* check existing keyset for reuse or removal */ - PackageSetting pkg = mPackages.get(packageName); long signingKeySetId = pkg.keySetData.getProperSigningKeySet(); if (signingKeySetId != PackageKeySetData.KEYSET_UNASSIGNED) { ArraySet<PublicKey> existingKeys = getPublicKeysFromKeySetLPr(signingKeySetId); - if (existingKeys.equals(signingKeys)) { + if (existingKeys != null && existingKeys.equals(signingKeys)) { /* no change in signing keys, leave PackageSetting alone */ return; } else { /* old keyset no longer valid, remove ref */ - KeySetHandle ksh = mKeySets.get(signingKeySetId); decrementKeySetLPw(signingKeySetId); } } @@ -212,13 +273,12 @@ public class KeySetManagerService { return KEYSET_NOT_FOUND; } - /* + /** * Inform the system that the given package defines the given KeySets. * Remove any KeySets the package no longer defines. */ - public void addDefinedKeySetsToPackageLPw(String packageName, + void addDefinedKeySetsToPackageLPw(PackageSetting pkg, ArrayMap<String, ArraySet<PublicKey>> definedMapping) { - PackageSetting pkg = mPackages.get(packageName); ArrayMap<String, Long> prevDefinedKeySets = pkg.keySetData.getAliases(); /* add all of the newly defined KeySets */ @@ -227,7 +287,7 @@ public class KeySetManagerService { for (int i = 0; i < defMapSize; i++) { String alias = definedMapping.keyAt(i); ArraySet<PublicKey> pubKeys = definedMapping.valueAt(i); - if (alias != null && pubKeys != null && pubKeys.size() > 0) { + if (alias != null && pubKeys != null || pubKeys.size() > 0) { KeySetHandle ks = addKeySetLPw(pubKeys); newKeySetAliases.put(alias, ks.getId()); } @@ -250,9 +310,8 @@ public class KeySetManagerService { * alias in its manifest to be an upgradeKeySet. This must be called * after all of the defined KeySets have been added. */ - public void addUpgradeKeySetsToPackageLPw(String packageName, - ArraySet<String> upgradeAliases) { - PackageSetting pkg = mPackages.get(packageName); + void addUpgradeKeySetsToPackageLPw(PackageSetting pkg, + ArraySet<String> upgradeAliases) { final int uaSize = upgradeAliases.size(); for (int i = 0; i < uaSize; i++) { pkg.keySetData.addUpgradeKeySet(upgradeAliases.valueAt(i)); @@ -290,11 +349,11 @@ public class KeySetManagerService { * identify a {@link KeySetHandle}. */ public ArraySet<PublicKey> getPublicKeysFromKeySetLPr(long id) { - if(mKeySetMapping.get(id) == null) { + ArraySet<Long> pkIds = mKeySetMapping.get(id); + if (pkIds == null) { return null; } ArraySet<PublicKey> mPubKeys = new ArraySet<PublicKey>(); - ArraySet<Long> pkIds = mKeySetMapping.get(id); final int pkSize = pkIds.size(); for (int i = 0; i < pkSize; i++) { mPubKeys.add(mPublicKeys.get(pkIds.valueAt(i)).getKey()); @@ -376,6 +435,10 @@ public class KeySetManagerService { */ private void decrementKeySetLPw(long id) { KeySetHandle ks = mKeySets.get(id); + if (ks == null) { + /* nothing to do */ + return; + } if (ks.decrRefCountLPw() <= 0) { ArraySet<Long> pubKeys = mKeySetMapping.get(id); final int pkSize = pubKeys.size(); @@ -385,7 +448,6 @@ public class KeySetManagerService { mKeySets.delete(id); mKeySetMapping.delete(id); } - return; } /* @@ -394,16 +456,20 @@ public class KeySetManagerService { */ private void decrementPublicKeyLPw(long id) { PublicKeyHandle pk = mPublicKeys.get(id); + if (pk == null) { + /* nothing to do */ + return; + } if (pk.decrRefCountLPw() <= 0) { mPublicKeys.delete(id); } - return; } /** * Adds the given PublicKey to the system, deduping as it goes. */ private long addPublicKeyLPw(PublicKey key) { + Preconditions.checkNotNull(key, "Cannot add null public key!"); long id = getIdForPublicKeyLPr(key); if (id != PUBLIC_KEY_NOT_FOUND) { @@ -473,6 +539,8 @@ public class KeySetManagerService { /* remove refs from common keysets and public keys */ PackageSetting pkg = mPackages.get(packageName); + Preconditions.checkNotNull(pkg, "pkg name: " + packageName + + "does not have a corresponding entry in mPackages."); long signingKeySetId = pkg.keySetData.getProperSigningKeySet(); decrementKeySetLPw(signingKeySetId); ArrayMap<String, Long> definedKeySets = pkg.keySetData.getAliases(); @@ -715,16 +783,36 @@ public class KeySetManagerService { final int numRefCounts = keySetRefCounts.size(); for (int i = 0; i < numRefCounts; i++) { KeySetHandle ks = mKeySets.get(keySetRefCounts.keyAt(i)); + if (ks == null) { + /* something went terribly wrong and we have references to a non-existent key-set */ + Slog.wtf(TAG, "Encountered non-existent key-set reference when reading settings"); + continue; + } ks.setRefCountLPw(keySetRefCounts.valueAt(i)); } + /* + * In case something went terribly wrong and we have keysets with no associated packges + * that refer to them, record the orphaned keyset ids, and remove them using + * decrementKeySetLPw() after all keyset references have been set so that the associtaed + * public keys have the appropriate references from all keysets. + */ + ArraySet<Long> orphanedKeySets = new ArraySet<Long>(); final int numKeySets = mKeySets.size(); for (int i = 0; i < numKeySets; i++) { + if (mKeySets.valueAt(i).getRefCountLPr() == 0) { + Slog.wtf(TAG, "Encountered key-set w/out package references when reading settings"); + orphanedKeySets.add(mKeySets.keyAt(i)); + } ArraySet<Long> pubKeys = mKeySetMapping.valueAt(i); final int pkSize = pubKeys.size(); for (int j = 0; j < pkSize; j++) { mPublicKeys.get(pubKeys.valueAt(j)).incrRefCountLPw(); } } + final int numOrphans = orphanedKeySets.size(); + for (int i = 0; i < numOrphans; i++) { + decrementKeySetLPw(orphanedKeySets.valueAt(i)); + } } } diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 548d93c..5b7dd70 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -5109,16 +5109,18 @@ public class PackageManagerService extends IPackageManager.Stub { && !isCompatSignatureUpdateNeeded(pkg) && !isRecoverSignatureUpdateNeeded(pkg)) { long mSigningKeySetId = ps.keySetData.getProperSigningKeySet(); + KeySetManagerService ksms = mSettings.mKeySetManagerService; + ArraySet<PublicKey> signingKs; + synchronized (mPackages) { + signingKs = ksms.getPublicKeysFromKeySetLPr(mSigningKeySetId); + } if (ps.signatures.mSignatures != null && ps.signatures.mSignatures.length != 0 - && mSigningKeySetId != PackageKeySetData.KEYSET_UNASSIGNED) { + && signingKs != null) { // Optimization: reuse the existing cached certificates // if the package appears to be unchanged. pkg.mSignatures = ps.signatures.mSignatures; - KeySetManagerService ksms = mSettings.mKeySetManagerService; - synchronized (mPackages) { - pkg.mSigningKeys = ksms.getPublicKeysFromKeySetLPr(mSigningKeySetId); - } + pkg.mSigningKeys = signingKs; return; } @@ -6590,6 +6592,10 @@ public class PackageManagerService extends IPackageManager.Stub { } } + // Make sure we're not adding any bogus keyset info + KeySetManagerService ksms = mSettings.mKeySetManagerService; + ksms.assertScannedPackageValid(pkg); + // writer synchronized (mPackages) { // We don't expect installation to fail beyond this point @@ -6626,20 +6632,7 @@ public class PackageManagerService extends IPackageManager.Stub { } // Add the package's KeySets to the global KeySetManagerService - KeySetManagerService ksms = mSettings.mKeySetManagerService; - try { - ksms.addSigningKeySetToPackageLPw(pkg.packageName, pkg.mSigningKeys); - if (pkg.mKeySetMapping != null) { - ksms.addDefinedKeySetsToPackageLPw(pkg.packageName, pkg.mKeySetMapping); - if (pkg.mUpgradeKeySets != null) { - ksms.addUpgradeKeySetsToPackageLPw(pkg.packageName, pkg.mUpgradeKeySets); - } - } - } catch (NullPointerException e) { - Slog.e(TAG, "Could not add KeySet to " + pkg.packageName, e); - } catch (IllegalArgumentException e) { - Slog.e(TAG, "Could not add KeySet to malformed package" + pkg.packageName, e); - } + ksms.addScannedPackageLPw(pkg); int N = pkg.providers.size(); StringBuilder r = null; @@ -11188,7 +11181,7 @@ public class PackageManagerService extends IPackageManager.Stub { KeySetManagerService ksms = mSettings.mKeySetManagerService; for (int i = 0; i < upgradeKeySets.length; i++) { Set<PublicKey> upgradeSet = ksms.getPublicKeysFromKeySetLPr(upgradeKeySets[i]); - if (newPkg.mSigningKeys.containsAll(upgradeSet)) { + if (upgradeSet != null && newPkg.mSigningKeys.containsAll(upgradeSet)) { return true; } } diff --git a/services/tests/servicestests/src/com/android/server/pm/KeySetManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/pm/KeySetManagerServiceTest.java index 2557974..7f9a0de 100644 --- a/services/tests/servicestests/src/com/android/server/pm/KeySetManagerServiceTest.java +++ b/services/tests/servicestests/src/com/android/server/pm/KeySetManagerServiceTest.java @@ -118,7 +118,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps, signingKeys); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 1)); @@ -145,10 +145,10 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps, signingKeys); /* add again, to represent upgrade of package */ - mKsms.addSigningKeySetToPackageLPw(ps.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps, signingKeys); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 1)); @@ -175,13 +175,13 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps, signingKeys); /* now upgrade with new key */ PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB); signingKeys.removeAt(0); signingKeys.add(keyB); - mKsms.addSigningKeySetToPackageLPw(ps.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps, signingKeys); assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2)); @@ -212,14 +212,14 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps1.name, signingKeys); - mKsms.addSigningKeySetToPackageLPw(ps2.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys); /* now upgrade with new key */ PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB); signingKeys.removeAt(0); signingKeys.add(keyB); - mKsms.addSigningKeySetToPackageLPw(ps1.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2)); @@ -255,13 +255,13 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys1 = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys1.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps1.name, signingKeys1); + mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys1); /* collect second signing key and add */ ArraySet<PublicKey> signingKeys2 = new ArraySet<PublicKey>(); PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB); signingKeys2.add(keyB); - mKsms.addSigningKeySetToPackageLPw(ps2.name, signingKeys2); + mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys2); /* verify first is unchanged */ assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 1)); @@ -300,10 +300,10 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps1.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys); /* add again for second package */ - mKsms.addSigningKeySetToPackageLPw(ps2.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys); assertEquals(2, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 1)); @@ -333,12 +333,12 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps1.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys); /* give ps2 a superset (add keyB) */ PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB); signingKeys.add(keyB); - mKsms.addSigningKeySetToPackageLPw(ps2.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2)); @@ -374,12 +374,12 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps, signingKeys); /* now with additional key */ PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB); signingKeys.add(keyB); - mKsms.addSigningKeySetToPackageLPw(ps.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps, signingKeys); assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2)); @@ -413,7 +413,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase { PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); keys.add(keyA); definedKS.put("aliasA", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 1)); @@ -441,7 +441,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase { keys.add(keyA); definedKS.put("aliasA", keys); definedKS.put("aliasA2", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); assertEquals(2, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 1)); @@ -470,7 +470,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase { PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); keys.add(keyA); definedKS.put("aliasA", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); /* now upgrade to different defined key-set */ keys = new ArraySet<PublicKey>(); @@ -478,7 +478,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase { keys.add(keyB); definedKS.remove("aliasA"); definedKS.put("aliasB", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1)); @@ -510,14 +510,14 @@ public class KeySetManagerServiceTest extends AndroidTestCase { PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); keys.add(keyA); definedKS.put("aliasA", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); /* now upgrade to different set w/same alias as before */ keys = new ArraySet<PublicKey>(); PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB); keys.add(keyB); definedKS.put("aliasA", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1)); @@ -551,7 +551,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase { keys2.add(keyB); definedKS.put("aliasA", keys1); definedKS.put("aliasB", keys2); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); /* now upgrade to different set (B, C) */ keys1 = new ArraySet<PublicKey>(); @@ -559,7 +559,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase { keys1.add(keyC); definedKS.remove("aliasA"); definedKS.put("aliasC", keys1); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 3)); assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 3)); @@ -612,7 +612,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase { PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); keys1.add(keyA); definedKS.put("aliasA", keys1); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); /* now upgrade to different set */ ArraySet<PublicKey> keys2 = new ArraySet<PublicKey>(); @@ -620,12 +620,12 @@ public class KeySetManagerServiceTest extends AndroidTestCase { keys2.add(keyB); definedKS.remove("aliasA"); definedKS.put("aliasB", keys2); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); /* upgrade back to original */ definedKS.remove("aliasB"); definedKS.put("aliasA", keys1); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1)); assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 2)); @@ -655,10 +655,10 @@ public class KeySetManagerServiceTest extends AndroidTestCase { PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); keys.add(keyA); definedKS.put("aliasA", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); ArraySet<String> upgradeKS = new ArraySet<String>(); upgradeKS.add("aliasA"); - mKsms.addUpgradeKeySetsToPackageLPw(ps.name, upgradeKS); + mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS); assertEquals(1, ps.keySetData.getUpgradeKeySets().length); assertEquals(1, ps.keySetData.getUpgradeKeySets()[0]); @@ -677,11 +677,11 @@ public class KeySetManagerServiceTest extends AndroidTestCase { PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); keys.add(keyA); definedKS.put("aliasA", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); ArraySet<String> upgradeKS = new ArraySet<String>(); upgradeKS.add("aliasB"); try { - mKsms.addUpgradeKeySetsToPackageLPw(ps.name, upgradeKS); + mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS); } catch (IllegalArgumentException e) { /* should have been caught in packagemanager, so exception thrown */ @@ -704,17 +704,17 @@ public class KeySetManagerServiceTest extends AndroidTestCase { PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); keys.add(keyA); definedKS.put("aliasA", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); ArraySet<String> upgradeKS = new ArraySet<String>(); upgradeKS.add("aliasA"); - mKsms.addUpgradeKeySetsToPackageLPw(ps.name, upgradeKS); + mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS); keys = new ArraySet<PublicKey>(); PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB); keys.add(keyB); definedKS.remove("aliasA"); definedKS.put("aliasB", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); assertNull(ps.keySetData.getUpgradeKeySets()); } @@ -729,7 +729,7 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps, signingKeys); /* remove its references */ mKsms.removeAppKeySetDataLPw(ps.name); @@ -754,8 +754,8 @@ public class KeySetManagerServiceTest extends AndroidTestCase { ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>(); PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA); signingKeys.add(keyA); - mKsms.addSigningKeySetToPackageLPw(ps1.name, signingKeys); - mKsms.addSigningKeySetToPackageLPw(ps2.name, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys); + mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys); /* remove references from first package */ mKsms.removeAppKeySetDataLPw(ps1.name); @@ -784,13 +784,13 @@ public class KeySetManagerServiceTest extends AndroidTestCase { /* removal requires signing keyset to be specified (since all apps are * assumed to have it). We skipped this in the defined tests, but can't * here. */ - mKsms.addSigningKeySetToPackageLPw(ps.name, keys); + mKsms.addSigningKeySetToPackageLPw(ps, keys); definedKS.put("aliasA", keys); - mKsms.addDefinedKeySetsToPackageLPw(ps.name, definedKS); + mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS); ArraySet<String> upgradeKS = new ArraySet<String>(); upgradeKS.add("aliasA"); - mKsms.addUpgradeKeySetsToPackageLPw(ps.name, upgradeKS); + mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS); mKsms.removeAppKeySetDataLPw(ps.name); assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1)); |