use of java.security.PublicKey in project android_frameworks_base by ResurrectionRemix.
the class KeySetManagerServiceTest method testAddSigningKSToPackageNewOrtho.
/*
* Add orthoganal keyset info to system and ensure previous keysets are
* unmodified.
*/
public void testAddSigningKSToPackageNewOrtho() throws ReflectiveOperationException {
/* create PackageSettings and add to Settings mPackages */
PackageSetting ps1 = generateFakePackageSetting("packageA");
mPackagesMap.put(ps1.name, ps1);
PackageSetting ps2 = generateFakePackageSetting("packageB");
mPackagesMap.put(ps2.name, ps2);
/* collect signing key and add */
ArraySet<PublicKey> signingKeys1 = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys1.add(keyA);
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, signingKeys2);
/* verify first is unchanged */
assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 1));
assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 1));
assertEquals(keyA, KeySetUtils.getPubKey(mKsms, 1));
LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
assertEquals(2, ksMapping.size());
ArraySet<Long> mapping = ksMapping.get(1);
assertEquals(1, mapping.size());
assertTrue(mapping.contains(new Long(1)));
assertEquals(1, ps1.keySetData.getProperSigningKeySet());
/* verify second */
assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2));
assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 2));
assertEquals(keyB, KeySetUtils.getPubKey(mKsms, 2));
mapping = ksMapping.get(2);
assertEquals(1, mapping.size());
assertTrue(mapping.contains(new Long(2)));
assertEquals(2, ps2.keySetData.getProperSigningKeySet());
}
use of java.security.PublicKey in project android_frameworks_base by ResurrectionRemix.
the class KeySetManagerServiceTest method testAddSigningKSToPackageUpgradeDiff.
/*
* upgrade an app (same packagename) with different unique keyset and verify
* that the old was removed.
*/
public void testAddSigningKSToPackageUpgradeDiff() throws ReflectiveOperationException {
/* create PackageSetting and add to Settings mPackages */
PackageSetting ps = generateFakePackageSetting("packageA");
mPackagesMap.put(ps.name, ps);
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps, signingKeys);
/* now upgrade with new key */
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
signingKeys.removeAt(0);
signingKeys.add(keyB);
mKsms.addSigningKeySetToPackageLPw(ps, signingKeys);
assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1));
assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2));
assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1));
assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 2));
assertEquals(keyB, KeySetUtils.getPubKey(mKsms, 2));
LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
assertEquals(1, ksMapping.size());
ArraySet<Long> mapping = ksMapping.get(2);
assertEquals(1, mapping.size());
assertTrue(mapping.contains(new Long(2)));
assertEquals(2, ps.keySetData.getProperSigningKeySet());
}
use of java.security.PublicKey in project android_frameworks_base by ResurrectionRemix.
the class KeySetManagerServiceTest method testAddSigningKSToPackageNewSame.
/*
* Add identical keyset info to system via new package and ensure previous
* keysets has reference count incremented
*/
public void testAddSigningKSToPackageNewSame() throws ReflectiveOperationException {
/* create PackageSettings and add to Settings mPackages */
PackageSetting ps1 = generateFakePackageSetting("packageA");
mPackagesMap.put(ps1.name, ps1);
PackageSetting ps2 = generateFakePackageSetting("packageB");
mPackagesMap.put(ps2.name, ps2);
/* collect signing key and add */
ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
signingKeys.add(keyA);
mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys);
/* add again for second package */
mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys);
assertEquals(2, KeySetUtils.getKeySetRefCount(mKsms, 1));
assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 1));
assertEquals(keyA, KeySetUtils.getPubKey(mKsms, 1));
LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
assertEquals(1, ksMapping.size());
ArraySet<Long> mapping = ksMapping.get(1);
assertEquals(1, mapping.size());
assertTrue(mapping.contains(new Long(1)));
assertEquals(1, ps1.keySetData.getProperSigningKeySet());
assertEquals(1, ps2.keySetData.getProperSigningKeySet());
}
use of java.security.PublicKey in project android_frameworks_base by ResurrectionRemix.
the class KeySetManagerServiceTest method testRemoveAppKSDataDefined.
/* remove package which used defined and upgrade keysets and ensure removed */
public void testRemoveAppKSDataDefined() throws ReflectiveOperationException {
/* create PackageSetting and add to Settings mPackages */
PackageSetting ps = generateFakePackageSetting("packageA");
mPackagesMap.put(ps.name, ps);
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
/* 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, keys);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
ArraySet<String> upgradeKS = new ArraySet<String>();
upgradeKS.add("aliasA");
mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS);
mKsms.removeAppKeySetDataLPw(ps.name);
assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1));
assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1));
LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
assertEquals(0, ksMapping.size());
assertEquals(PackageKeySetData.KEYSET_UNASSIGNED, ps.keySetData.getProperSigningKeySet());
assertEquals(0, ps.keySetData.getAliases().size());
assertNull(ps.keySetData.getUpgradeKeySets());
}
use of java.security.PublicKey in project android_frameworks_base by ResurrectionRemix.
the class KeySetManagerServiceTest method testAddDefinedKSToPackageOrthoUpgr.
/* upgrd defined keyset ortho (make sure previous is removed for pkg) */
public void testAddDefinedKSToPackageOrthoUpgr() throws ReflectiveOperationException {
/* create PackageSetting and add to Settings mPackages */
PackageSetting ps = generateFakePackageSetting("packageA");
mPackagesMap.put(ps.name, ps);
/* collect key and add */
ArrayMap<String, ArraySet<PublicKey>> definedKS = new ArrayMap<String, ArraySet<PublicKey>>();
ArraySet<PublicKey> keys = new ArraySet<PublicKey>();
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
keys.add(keyA);
definedKS.put("aliasA", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
/* now upgrade to different defined key-set */
keys = new ArraySet<PublicKey>();
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
keys.add(keyB);
definedKS.remove("aliasA");
definedKS.put("aliasB", keys);
mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
assertEquals(0, KeySetUtils.getKeySetRefCount(mKsms, 1));
assertEquals(0, KeySetUtils.getPubKeyRefCount(mKsms, 1));
assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 2));
assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 2));
assertEquals(keyB, KeySetUtils.getPubKey(mKsms, 2));
LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
assertEquals(1, ksMapping.size());
ArraySet<Long> mapping = ksMapping.get(2);
assertEquals(1, mapping.size());
assertTrue(mapping.contains(new Long(2)));
assertNull(ps.keySetData.getAliases().get("aliasA"));
assertNotNull(ps.keySetData.getAliases().get("aliasB"));
assertEquals(new Long(2), ps.keySetData.getAliases().get("aliasB"));
}
Aggregations