diff options
author | dcashman <dcashman@google.com> | 2014-07-12 13:04:20 -0700 |
---|---|---|
committer | dcashman <dcashman@google.com> | 2014-07-12 13:04:20 -0700 |
commit | 5de7377feca5242fe7127e2d4dc7792d4886d365 (patch) | |
tree | c7ac7801388c9572702b3c2440f0efc60ccc17b3 /services/core/java/com/android/server/pm/KeySetManagerService.java | |
parent | 405912bce074e9e59a246e2357a108e50dffabf8 (diff) | |
download | frameworks_base-5de7377feca5242fe7127e2d4dc7792d4886d365.zip frameworks_base-5de7377feca5242fe7127e2d4dc7792d4886d365.tar.gz frameworks_base-5de7377feca5242fe7127e2d4dc7792d4886d365.tar.bz2 |
Revert "Initial KeySet API."
This reverts commit 9a643fe02bc960e266484547dda5572b094a4c72.
Diffstat (limited to 'services/core/java/com/android/server/pm/KeySetManagerService.java')
-rw-r--r-- | services/core/java/com/android/server/pm/KeySetManagerService.java | 111 |
1 files changed, 46 insertions, 65 deletions
diff --git a/services/core/java/com/android/server/pm/KeySetManagerService.java b/services/core/java/com/android/server/pm/KeySetManagerService.java index 37bedf3..c19951f 100644 --- a/services/core/java/com/android/server/pm/KeySetManagerService.java +++ b/services/core/java/com/android/server/pm/KeySetManagerService.java @@ -16,6 +16,7 @@ package com.android.server.pm; +import android.content.pm.KeySet; import android.content.pm.PackageParser; import android.os.Binder; import android.util.ArraySet; @@ -51,7 +52,7 @@ public class KeySetManagerService { /** Sentinel value returned when public key is not found. */ protected static final long PUBLIC_KEY_NOT_FOUND = -1; - private final LongSparseArray<KeySetHandle> mKeySets; + private final LongSparseArray<KeySet> mKeySets; private final LongSparseArray<PublicKey> mPublicKeys; @@ -64,7 +65,7 @@ public class KeySetManagerService { private static long lastIssuedKeyId = 0; public KeySetManagerService(Map<String, PackageSetting> packages) { - mKeySets = new LongSparseArray<KeySetHandle>(); + mKeySets = new LongSparseArray<KeySet>(); mPublicKeys = new LongSparseArray<PublicKey>(); mKeySetMapping = new LongSparseArray<ArraySet<Long>>(); mPackages = packages; @@ -81,7 +82,7 @@ public class KeySetManagerService { * * Note that this can return true for multiple KeySets. */ - public boolean packageIsSignedByLPr(String packageName, KeySetHandle ks) { + public boolean packageIsSignedByLPr(String packageName, KeySet ks) { PackageSetting pkg = mPackages.get(packageName); if (pkg == null) { throw new NullPointerException("Invalid package name"); @@ -90,42 +91,16 @@ public class KeySetManagerService { throw new NullPointerException("Package has no KeySet data"); } long id = getIdByKeySetLPr(ks); - if (id == KEYSET_NOT_FOUND) { - return false; - } return pkg.keySetData.packageIsSignedBy(id); } /** - * Determine if a package is signed by the given KeySet. - * - * Returns false if the package was not signed by all the - * keys in the KeySet, or if the package was signed by keys - * not in the KeySet. - * - * Note that this can return only for one KeySet. - */ - public boolean packageIsSignedByExactlyLPr(String packageName, KeySetHandle ks) { - PackageSetting pkg = mPackages.get(packageName); - if (pkg == null) { - throw new NullPointerException("Invalid package name"); - } - if (pkg.keySetData == null - || pkg.keySetData.getProperSigningKeySet() - == PackageKeySetData.KEYSET_UNASSIGNED) { - throw new NullPointerException("Package has no KeySet data"); - } - long id = getIdByKeySetLPr(ks); - return pkg.keySetData.getProperSigningKeySet() == id; - } - - /** * This informs the system that the given package has defined a KeySet * in its manifest that a) contains the given keys and b) is named * alias by that package. */ public void addDefinedKeySetToPackageLPw(String packageName, - ArraySet<PublicKey> keys, String alias) { + Set<PublicKey> keys, String alias) { if ((packageName == null) || (keys == null) || (alias == null)) { Slog.w(TAG, "Got null argument for a defined keyset, ignoring!"); return; @@ -135,7 +110,7 @@ public class KeySetManagerService { throw new NullPointerException("Unknown package"); } // Add to KeySets, then to package - KeySetHandle ks = addKeySetLPw(keys); + KeySet ks = addKeySetLPw(keys); long id = getIdByKeySetLPr(ks); pkg.keySetData.addDefinedKeySet(id, alias); } @@ -162,18 +137,19 @@ public class KeySetManagerService { * was signed by the provided KeySet. */ public void addSigningKeySetToPackageLPw(String packageName, - ArraySet<PublicKey> signingKeys) { + Set<PublicKey> signingKeys) { if ((packageName == null) || (signingKeys == null)) { Slog.w(TAG, "Got null argument for a signing keyset, ignoring!"); return; } // add the signing KeySet - KeySetHandle ks = addKeySetLPw(signingKeys); + KeySet ks = addKeySetLPw(signingKeys); long id = getIdByKeySetLPr(ks); - ArraySet<Long> publicKeyIds = mKeySetMapping.get(id); + Set<Long> publicKeyIds = mKeySetMapping.get(id); if (publicKeyIds == null) { throw new NullPointerException("Got invalid KeySet id"); } + // attach it to the package PackageSetting pkg = mPackages.get(packageName); if (pkg == null) { @@ -184,7 +160,7 @@ public class KeySetManagerService { // KeySet id to the package's signing KeySets for (int keySetIndex = 0; keySetIndex < mKeySets.size(); keySetIndex++) { long keySetID = mKeySets.keyAt(keySetIndex); - ArraySet<Long> definedKeys = mKeySetMapping.get(keySetID); + Set<Long> definedKeys = mKeySetMapping.get(keySetID); if (publicKeyIds.containsAll(definedKeys)) { pkg.keySetData.addSigningKeySet(keySetID); } @@ -195,9 +171,9 @@ public class KeySetManagerService { * Fetches the stable identifier associated with the given KeySet. Returns * {@link #KEYSET_NOT_FOUND} if the KeySet... wasn't found. */ - private long getIdByKeySetLPr(KeySetHandle ks) { + private long getIdByKeySetLPr(KeySet ks) { for (int keySetIndex = 0; keySetIndex < mKeySets.size(); keySetIndex++) { - KeySetHandle value = mKeySets.valueAt(keySetIndex); + KeySet value = mKeySets.valueAt(keySetIndex); if (ks.equals(value)) { return mKeySets.keyAt(keySetIndex); } @@ -211,24 +187,25 @@ public class KeySetManagerService { * Returns {@link #KEYSET_NOT_FOUND} if the identifier doesn't * identify a {@link KeySet}. */ - public KeySetHandle getKeySetByIdLPr(long id) { + public KeySet getKeySetByIdLPr(long id) { return mKeySets.get(id); } /** - * Fetches the {@link KeySetHandle} that a given package refers to by the - * provided alias. Returns null if the package is unknown or does not have a - * KeySet corresponding to that alias. + * Fetches the {@link KeySet} that a given package refers to by the provided alias. + * + * @throws IllegalArgumentException if the package has no keyset data. + * @throws NullPointerException if the package is unknown. */ - public KeySetHandle getKeySetByAliasAndPackageNameLPr(String packageName, String alias) { + public KeySet getKeySetByAliasAndPackageNameLPr(String packageName, String alias) { PackageSetting p = mPackages.get(packageName); - if (p == null || p.keySetData == null) { - return null; + if (p == null) { + throw new NullPointerException("Unknown package"); } - Long keySetId = p.keySetData.getAliases().get(alias); - if (keySetId == null) { - throw new IllegalArgumentException("Unknown KeySet alias: " + alias); + if (p.keySetData == null) { + throw new IllegalArgumentException("Package has no keySet data"); } + long keySetId = p.keySetData.getAliases().get(alias); return mKeySets.get(keySetId); } @@ -237,7 +214,7 @@ public class KeySetManagerService { * KeySet id. * * Returns {@code null} if the identifier doesn't - * identify a {@link KeySetHandle}. + * identify a {@link KeySet}. */ public ArraySet<PublicKey> getPublicKeysFromKeySetLPr(long id) { if(mKeySetMapping.get(id) == null) { @@ -251,32 +228,36 @@ public class KeySetManagerService { } /** - * Fetches the proper {@link KeySetHandle KeySet} that signed the given + * Fetches all the known {@link KeySet KeySets} that signed the given * package. * * @throws IllegalArgumentException if the package has no keyset data. * @throws NullPointerException if the package is unknown. */ - public KeySetHandle getSigningKeySetByPackageNameLPr(String packageName) { + public Set<KeySet> getSigningKeySetsByPackageNameLPr(String packageName) { + Set<KeySet> signingKeySets = new ArraySet<KeySet>(); PackageSetting p = mPackages.get(packageName); - if (p == null - || p.keySetData == null - || p.keySetData.getProperSigningKeySet() - == PackageKeySetData.KEYSET_UNASSIGNED) { - return null; + if (p == null) { + throw new NullPointerException("Unknown package"); + } + if (p.keySetData == null || p.keySetData.getSigningKeySets() == null) { + throw new IllegalArgumentException("Package has no keySet data"); + } + for (long l : p.keySetData.getSigningKeySets()) { + signingKeySets.add(mKeySets.get(l)); } - return mKeySets.get(p.keySetData.getProperSigningKeySet()); + return signingKeySets; } /** - * Fetches all the known {@link KeySetHandle KeySets} that may upgrade the given + * Fetches all the known {@link KeySet KeySets} that may upgrade the given * package. * * @throws IllegalArgumentException if the package has no keyset data. * @throws NullPointerException if the package is unknown. */ - public ArraySet<KeySetHandle> getUpgradeKeySetsByPackageNameLPr(String packageName) { - ArraySet<KeySetHandle> upgradeKeySets = new ArraySet<KeySetHandle>(); + public ArraySet<KeySet> getUpgradeKeySetsByPackageNameLPr(String packageName) { + ArraySet<KeySet> upgradeKeySets = new ArraySet<KeySet>(); PackageSetting p = mPackages.get(packageName); if (p == null) { throw new NullPointerException("Unknown package"); @@ -306,7 +287,7 @@ public class KeySetManagerService { * * Throws if the provided set is {@code null}. */ - private KeySetHandle addKeySetLPw(ArraySet<PublicKey> keys) { + private KeySet addKeySetLPw(Set<PublicKey> keys) { if (keys == null) { throw new NullPointerException("Provided keys cannot be null"); } @@ -324,7 +305,7 @@ public class KeySetManagerService { } // create the KeySet object - KeySetHandle ks = new KeySetHandle(); + KeySet ks = new KeySet(new Binder()); // get the first unoccupied slot in mKeySets long id = getFreeKeySetIDLPw(); // add the KeySet object to it @@ -337,7 +318,7 @@ public class KeySetManagerService { if (p.keySetData != null) { long pProperSigning = p.keySetData.getProperSigningKeySet(); if (pProperSigning != PackageKeySetData.KEYSET_UNASSIGNED) { - ArraySet<Long> pSigningKeys = mKeySetMapping.get(pProperSigning); + Set<Long> pSigningKeys = mKeySetMapping.get(pProperSigning); if (pSigningKeys.containsAll(addedKeyIds)) { p.keySetData.addSigningKeySet(id); } @@ -372,7 +353,7 @@ public class KeySetManagerService { */ private long getIdFromKeyIdsLPr(Set<Long> publicKeyIds) { for (int keyMapIndex = 0; keyMapIndex < mKeySetMapping.size(); keyMapIndex++) { - ArraySet<Long> value = mKeySetMapping.valueAt(keyMapIndex); + Set<Long> value = mKeySetMapping.valueAt(keyMapIndex); if (value.equals(publicKeyIds)) { return mKeySetMapping.keyAt(keyMapIndex); } @@ -601,7 +582,7 @@ public class KeySetManagerService { serializer.startTag(null, "keysets"); for (int keySetIndex = 0; keySetIndex < mKeySetMapping.size(); keySetIndex++) { long id = mKeySetMapping.keyAt(keySetIndex); - ArraySet<Long> keys = mKeySetMapping.valueAt(keySetIndex); + Set<Long> keys = mKeySetMapping.valueAt(keySetIndex); serializer.startTag(null, "keyset"); serializer.attribute(null, "identifier", Long.toString(id)); for (long keyId : keys) { @@ -681,7 +662,7 @@ public class KeySetManagerService { final String tagName = parser.getName(); if (tagName.equals("keyset")) { currentKeySetId = readIdentifierLPw(parser); - mKeySets.put(currentKeySetId, new KeySetHandle()); + mKeySets.put(currentKeySetId, new KeySet(new Binder())); mKeySetMapping.put(currentKeySetId, new ArraySet<Long>()); } else if (tagName.equals("key-id")) { long id = readIdentifierLPw(parser); |