Search in sources :

Example 41 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

the class KeySetManagerServiceTest method testAddUpgradeKSToPackageDisappear.

/* upgrade from defined keysets w/upgrade to different defined keysets and
     * make sure the previously specified upgrade keyset has been removed. */
public void testAddUpgradeKSToPackageDisappear() {
    /* 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);
    ArraySet<String> upgradeKS = new ArraySet<String>();
    upgradeKS.add("aliasA");
    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, definedKS);
    assertNull(ps.keySetData.getUpgradeKeySets());
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Example 42 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

the class KeySetManagerServiceTest method testRemoveAppKSDataDup.

/* remove package and validate that keysets remain if defined elsewhere but
     * have refcounts decreased. */
public void testRemoveAppKSDataDup() 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 for both packages */
    ArraySet<PublicKey> signingKeys = new ArraySet<PublicKey>();
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    signingKeys.add(keyA);
    mKsms.addSigningKeySetToPackageLPw(ps1, signingKeys);
    mKsms.addSigningKeySetToPackageLPw(ps2, signingKeys);
    /* remove references from first package */
    mKsms.removeAppKeySetDataLPw(ps1.name);
    assertEquals(1, KeySetUtils.getKeySetRefCount(mKsms, 1));
    assertEquals(1, KeySetUtils.getPubKeyRefCount(mKsms, 1));
    LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
    assertEquals(1, ksMapping.size());
    assertEquals(PackageKeySetData.KEYSET_UNASSIGNED, ps1.keySetData.getProperSigningKeySet());
    assertEquals(1, ps2.keySetData.getProperSigningKeySet());
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey)

Example 43 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

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());
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey)

Example 44 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

the class KeySetManagerServiceTest method testAddDefinedKSToPackageDoubleAlias.

/* add 2 defined keysets which refer to same keyset and make sure ref-ct is 2 */
public void testAddDefinedKSToPackageDoubleAlias() 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);
    definedKS.put("aliasA2", keys);
    mKsms.addDefinedKeySetsToPackageLPw(ps, definedKS);
    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)));
    assertNotNull(ps.keySetData.getAliases().get("aliasA"));
    assertEquals(new Long(1), ps.keySetData.getAliases().get("aliasA"));
    assertNotNull(ps.keySetData.getAliases().get("aliasA2"));
    assertEquals(new Long(1), ps.keySetData.getAliases().get("aliasA2"));
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

Example 45 with ArraySet

use of android.util.ArraySet in project platform_frameworks_base by android.

the class KeySetManagerServiceTest method testAddSigningKSToPackageUpgradeDiffSuper.

/*
     * Upgrade an app (same pkgName) with different keyset which contains a public
     * key from the previous keyset.  Verify old keyset removed and pub key ref
     * count is accurate.
     */
public void testAddSigningKSToPackageUpgradeDiffSuper() 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 with additional key */
    PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
    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(1, KeySetUtils.getPubKeyRefCount(mKsms, 3));
    /* the pub key is removed w/prev keyset and may be either 2 or 3 */
    assertTrue(keyA.equals(KeySetUtils.getPubKey(mKsms, 2)) || keyA.equals(KeySetUtils.getPubKey(mKsms, 3)));
    assertTrue(keyB.equals(KeySetUtils.getPubKey(mKsms, 2)) || keyB.equals(KeySetUtils.getPubKey(mKsms, 3)));
    assertFalse(KeySetUtils.getPubKey(mKsms, 2).equals(KeySetUtils.getPubKey(mKsms, 3)));
    LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(mKsms);
    assertEquals(1, ksMapping.size());
    ArraySet<Long> mapping = ksMapping.get(2);
    assertEquals(2, mapping.size());
    assertTrue(mapping.contains(new Long(2)));
    assertTrue(mapping.contains(new Long(3)));
    assertEquals(2, ps.keySetData.getProperSigningKeySet());
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey)

Aggregations

ArraySet (android.util.ArraySet)431 PublicKey (java.security.PublicKey)94 ComponentName (android.content.ComponentName)73 ArrayMap (android.util.ArrayMap)73 ArrayList (java.util.ArrayList)66 Pair (android.util.Pair)47 File (java.io.File)33 SSLContext (javax.net.ssl.SSLContext)32 Intent (android.content.Intent)30 RemoteException (android.os.RemoteException)29 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)28 ResolveInfo (android.content.pm.ResolveInfo)25 Point (android.graphics.Point)24 IOException (java.io.IOException)23 UserInfo (android.content.pm.UserInfo)21 X509Certificate (java.security.cert.X509Certificate)20 ContentResolver (android.content.ContentResolver)16 PackageManager (android.content.pm.PackageManager)15 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 SparseArray (android.util.SparseArray)15