diff options
author | dcashman <dcashman@google.com> | 2014-06-09 09:27:54 -0700 |
---|---|---|
committer | dcashman <dcashman@google.com> | 2014-07-14 12:50:51 -0700 |
commit | 9d2f441f9bb2c8dcac1150e2cba1d15a86a4efb1 (patch) | |
tree | 7ddba4a062aac803b3329dfc311b8f474ea5d677 /core/tests/coretests | |
parent | a4ab780877808dbee334f7c7cc4acefa0aa313b2 (diff) | |
download | frameworks_base-9d2f441f9bb2c8dcac1150e2cba1d15a86a4efb1.zip frameworks_base-9d2f441f9bb2c8dcac1150e2cba1d15a86a4efb1.tar.gz frameworks_base-9d2f441f9bb2c8dcac1150e2cba1d15a86a4efb1.tar.bz2 |
Initial KeySet API.
Previously submitted but reverted due to doc-compilation bug.
Bug: 6967056
Change-Id: I9bd7ef299a4c92c4b327f5b5d7e951f0753b4c8a
Diffstat (limited to 'core/tests/coretests')
4 files changed, 214 insertions, 0 deletions
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml index a2cc40c..b524177 100644 --- a/core/tests/coretests/AndroidManifest.xml +++ b/core/tests/coretests/AndroidManifest.xml @@ -1257,4 +1257,11 @@ <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.android.frameworks.coretests" android:label="Frameworks Core Tests" /> + <key-sets> + <key-set android:name="A" > + <public-key android:name="keyA" + android:value="MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJoN1Nsgqf0V4C/bbN8wo8O2X/S5D76+5Mb9mlIsHkUTUTbHCNk+LxHIUYLm89YbP9zImrV0bUHLUAZUyoMUCiMCAwEAAQ=="/> + </key-set> + <upgrade-key-set android:name="A"/> + </key-sets> </manifest> diff --git a/core/tests/coretests/apks/keyset/Android.mk b/core/tests/coretests/apks/keyset/Android.mk index e44ac6c..306dc90 100644 --- a/core/tests/coretests/apks/keyset/Android.mk +++ b/core/tests/coretests/apks/keyset/Android.mk @@ -88,4 +88,21 @@ LOCAL_PACKAGE_NAME := keyset_sau_ub LOCAL_CERTIFICATE := $(LOCAL_PATH)/../../certs/keyset_A LOCAL_ADDITIONAL_CERTIFICATES := $(LOCAL_PATH)/../../certs/keyset_B LOCAL_MANIFEST_FILE := uB/AndroidManifest.xml +include $(FrameworkCoreTests_BUILD_PACKAGE) + +#apks signed by platform only +include $(CLEAR_VARS) +LOCAL_SRC_FILES := $(call all-subdir-java-files) +LOCAL_PACKAGE_NAME := keyset_splat_api +LOCAL_CERTIFICATE := platform +LOCAL_MANIFEST_FILE := api_test/AndroidManifest.xml +include $(FrameworkCoreTests_BUILD_PACKAGE) + +#apks signed by platform and keyset_A +include $(CLEAR_VARS) +LOCAL_SRC_FILES := $(call all-subdir-java-files) +LOCAL_PACKAGE_NAME := keyset_splata_api +LOCAL_CERTIFICATE := platform +LOCAL_ADDITIONAL_CERTIFICATES := $(LOCAL_PATH)/../../certs/keyset_A +LOCAL_MANIFEST_FILE := api_test/AndroidManifest.xml include $(FrameworkCoreTests_BUILD_PACKAGE)
\ No newline at end of file diff --git a/core/tests/coretests/apks/keyset/api_test/AndroidManifest.xml b/core/tests/coretests/apks/keyset/api_test/AndroidManifest.xml new file mode 100644 index 0000000..4c7e968 --- /dev/null +++ b/core/tests/coretests/apks/keyset/api_test/AndroidManifest.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.frameworks.coretests.keysets_api"> + <application android:hasCode="false"> + </application> +</manifest> diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java index 0244425..3a80309 100644 --- a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java +++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java @@ -26,6 +26,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.KeySet; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -33,6 +34,7 @@ import android.content.pm.PackageParser.PackageParserException; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.net.Uri; +import android.os.Binder; import android.os.Bundle; import android.os.Environment; import android.os.FileUtils; @@ -3328,6 +3330,174 @@ public class PackageManagerTests extends AndroidTestCase { } /** + * The following tests are related to testing KeySets-based API + */ + + /* + * testGetSigningKeySetNull - ensure getSigningKeySet() returns null on null + * input and when calling a package other than that which made the call. + */ + public void testGetSigningKeySet() throws Exception { + PackageManager pm = getPm(); + String mPkgName = mContext.getPackageName(); + String otherPkgName = "com.android.frameworks.coretests.keysets_api"; + KeySet ks; + try { + ks = pm.getSigningKeySet(null); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + ks = pm.getSigningKeySet("keysets.test.bogus.package"); + assertTrue(false); // should have thrown + } catch (IllegalArgumentException e) { + } + installFromRawResource("keysetApi.apk", R.raw.keyset_splat_api, + 0, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); + try { + ks = pm.getSigningKeySet(otherPkgName); + assertTrue(false); // should have thrown + } catch (SecurityException e) { + } + cleanUpInstall(otherPkgName); + ks = pm.getSigningKeySet(mContext.getPackageName()); + assertNotNull(ks); + } + + /* + * testGetKeySetByAlias - same as getSigningKeySet, but for keysets defined + * by this package. + */ + public void testGetKeySetByAlias() throws Exception { + PackageManager pm = getPm(); + String mPkgName = mContext.getPackageName(); + String otherPkgName = "com.android.frameworks.coretests.keysets_api"; + KeySet ks; + try { + ks = pm.getKeySetByAlias(null, null); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + ks = pm.getKeySetByAlias(null, "keysetBogus"); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + ks = pm.getKeySetByAlias("keysets.test.bogus.package", null); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + ks = pm.getKeySetByAlias("keysets.test.bogus.package", "A"); + assertTrue(false); // should have thrown + } catch(IllegalArgumentException e) { + } + try { + ks = pm.getKeySetByAlias(mPkgName, "keysetBogus"); + assertTrue(false); // should have thrown + } catch(IllegalArgumentException e) { + } + installFromRawResource("keysetApi.apk", R.raw.keyset_splat_api, + 0, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); + try { + ks = pm.getKeySetByAlias(otherPkgName, "A"); + assertTrue(false); // should have thrown + } catch (SecurityException e) { + } + cleanUpInstall(otherPkgName); + ks = pm.getKeySetByAlias(mPkgName, "A"); + assertNotNull(ks); + } + + public void testIsSignedBy() throws Exception { + PackageManager pm = getPm(); + String mPkgName = mContext.getPackageName(); + String otherPkgName = "com.android.frameworks.coretests.keysets_api"; + KeySet mSigningKS = pm.getSigningKeySet(mPkgName); + KeySet mDefinedKS = pm.getKeySetByAlias(mPkgName, "A"); + + try { + assertFalse(pm.isSignedBy(null, null)); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + assertFalse(pm.isSignedBy(null, mSigningKS)); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + assertFalse(pm.isSignedBy(mPkgName, null)); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + assertFalse(pm.isSignedBy("keysets.test.bogus.package", mDefinedKS)); + } catch(IllegalArgumentException e) { + } + assertFalse(pm.isSignedBy(mPkgName, mDefinedKS)); + assertFalse(pm.isSignedBy(mPkgName, new KeySet(new Binder()))); + assertTrue(pm.isSignedBy(mPkgName, mSigningKS)); + + installFromRawResource("keysetApi.apk", R.raw.keyset_splat_api, + 0, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); + assertFalse(pm.isSignedBy(otherPkgName, mDefinedKS)); + assertTrue(pm.isSignedBy(otherPkgName, mSigningKS)); + cleanUpInstall(otherPkgName); + + installFromRawResource("keysetApi.apk", R.raw.keyset_splata_api, + 0, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); + assertTrue(pm.isSignedBy(otherPkgName, mDefinedKS)); + assertTrue(pm.isSignedBy(otherPkgName, mSigningKS)); + cleanUpInstall(otherPkgName); + } + + public void testIsSignedByExactly() throws Exception { + PackageManager pm = getPm(); + String mPkgName = mContext.getPackageName(); + String otherPkgName = "com.android.frameworks.coretests.keysets_api"; + KeySet mSigningKS = pm.getSigningKeySet(mPkgName); + KeySet mDefinedKS = pm.getKeySetByAlias(mPkgName, "A"); + try { + assertFalse(pm.isSignedBy(null, null)); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + assertFalse(pm.isSignedBy(null, mSigningKS)); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + assertFalse(pm.isSignedBy(mPkgName, null)); + assertTrue(false); // should have thrown + } catch (NullPointerException e) { + } + try { + assertFalse(pm.isSignedByExactly("keysets.test.bogus.package", mDefinedKS)); + } catch(IllegalArgumentException e) { + } + assertFalse(pm.isSignedByExactly(mPkgName, mDefinedKS)); + assertFalse(pm.isSignedByExactly(mPkgName, new KeySet(new Binder()))); + assertTrue(pm.isSignedByExactly(mPkgName, mSigningKS)); + + installFromRawResource("keysetApi.apk", R.raw.keyset_splat_api, + 0, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); + assertFalse(pm.isSignedByExactly(otherPkgName, mDefinedKS)); + assertTrue(pm.isSignedByExactly(otherPkgName, mSigningKS)); + cleanUpInstall(otherPkgName); + + installFromRawResource("keysetApi.apk", R.raw.keyset_splata_api, + 0, false, false, -1, PackageInfo.INSTALL_LOCATION_UNSPECIFIED); + assertFalse(pm.isSignedByExactly(otherPkgName, mDefinedKS)); + assertFalse(pm.isSignedByExactly(otherPkgName, mSigningKS)); + cleanUpInstall(otherPkgName); + } + + + + /** * The following tests are related to testing the checkSignatures api. */ private void checkSignatures(int apk1, int apk2, int expMatchResult) throws Exception { |