Search in sources :

Example 36 with ArraySet

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

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

Example 37 with ArraySet

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

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

Example 38 with ArraySet

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

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

Example 39 with ArraySet

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

the class PackageManagerSettingsTests method verifyKeySetMetaData.

private void verifyKeySetMetaData(Settings settings) throws ReflectiveOperationException, IllegalAccessException {
    ArrayMap<String, PackageSetting> packages = settings.mPackages;
    KeySetManagerService ksms = settings.mKeySetManagerService;
    /* verify keyset and public key ref counts */
    assertEquals(2, KeySetUtils.getKeySetRefCount(ksms, 1));
    assertEquals(1, KeySetUtils.getKeySetRefCount(ksms, 2));
    assertEquals(1, KeySetUtils.getKeySetRefCount(ksms, 3));
    assertEquals(1, KeySetUtils.getKeySetRefCount(ksms, 4));
    assertEquals(2, KeySetUtils.getPubKeyRefCount(ksms, 1));
    assertEquals(2, KeySetUtils.getPubKeyRefCount(ksms, 2));
    assertEquals(1, KeySetUtils.getPubKeyRefCount(ksms, 3));
    /* verify public keys properly read */
    PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
    PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
    PublicKey keyC = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
    assertEquals(keyA, KeySetUtils.getPubKey(ksms, 1));
    assertEquals(keyB, KeySetUtils.getPubKey(ksms, 2));
    assertEquals(keyC, KeySetUtils.getPubKey(ksms, 3));
    /* verify mapping is correct (ks -> pub keys) */
    LongSparseArray<ArraySet<Long>> ksMapping = KeySetUtils.getKeySetMapping(ksms);
    ArraySet<Long> mapping = ksMapping.get(1);
    assertEquals(1, mapping.size());
    assertTrue(mapping.contains(new Long(1)));
    mapping = ksMapping.get(2);
    assertEquals(1, mapping.size());
    assertTrue(mapping.contains(new Long(2)));
    mapping = ksMapping.get(3);
    assertEquals(1, mapping.size());
    assertTrue(mapping.contains(new Long(3)));
    mapping = ksMapping.get(4);
    assertEquals(2, mapping.size());
    assertTrue(mapping.contains(new Long(1)));
    assertTrue(mapping.contains(new Long(2)));
    /* verify lastIssuedIds are consistent */
    assertEquals(new Long(3), KeySetUtils.getLastIssuedKeyId(ksms));
    assertEquals(new Long(4), KeySetUtils.getLastIssuedKeySetId(ksms));
    /* verify packages have been given the appropriat information */
    PackageSetting ps = packages.get("com.google.app1");
    assertEquals(1, ps.keySetData.getProperSigningKeySet());
    ps = packages.get("com.google.app2");
    assertEquals(1, ps.keySetData.getProperSigningKeySet());
    assertEquals(new Long(4), ps.keySetData.getAliases().get("AB"));
    ps = packages.get("com.android.app3");
    assertEquals(2, ps.keySetData.getProperSigningKeySet());
    assertEquals(new Long(3), ps.keySetData.getAliases().get("C"));
    assertEquals(1, ps.keySetData.getUpgradeKeySets().length);
    assertEquals(3, ps.keySetData.getUpgradeKeySets()[0]);
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey)

Example 40 with ArraySet

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

the class KeySetManagerServiceTest method testAddUpgradeKSToPackageWrong.

/* add upgrade keyset for non-existing defined and check that it compains */
public void testAddUpgradeKSToPackageWrong() {
    /* create PackageSetting and add to Settings mPackages */
    PackageSetting ps = generateFakePackageSetting("packageA");
    mPackagesMap.put(ps.name, ps);
    /* collect key and add and try to specify bogus upgrade keyset */
    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("aliasB");
    try {
        mKsms.addUpgradeKeySetsToPackageLPw(ps, upgradeKS);
    } catch (IllegalArgumentException e) {
        /* should have been caught in packagemanager, so exception thrown */
        return;
    }
    fail("Expected IllegalArgumentException when adding undefined upgrade keyset!!");
}
Also used : ArraySet(android.util.ArraySet) PublicKey(java.security.PublicKey) ArrayMap(android.util.ArrayMap)

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