Search in sources :

Example 41 with Signature

use of android.content.pm.Signature in project android_frameworks_base by AOSPA.

the class NetworkPolicyManager method isUidValidForPolicy.

/**
     * Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
     * usually to protect critical system services.
     */
@Deprecated
public static boolean isUidValidForPolicy(Context context, int uid) {
    // first, quick-reject non-applications
    if (!UserHandle.isApp(uid)) {
        return false;
    }
    if (!ALLOW_PLATFORM_APP_POLICY) {
        final PackageManager pm = context.getPackageManager();
        final HashSet<Signature> systemSignature;
        try {
            systemSignature = Sets.newHashSet(pm.getPackageInfo("android", GET_SIGNATURES).signatures);
        } catch (NameNotFoundException e) {
            throw new RuntimeException("problem finding system signature", e);
        }
        try {
            // reject apps signed with platform cert
            for (String packageName : pm.getPackagesForUid(uid)) {
                final HashSet<Signature> packageSignature = Sets.newHashSet(pm.getPackageInfo(packageName, GET_SIGNATURES).signatures);
                if (packageSignature.containsAll(systemSignature)) {
                    return false;
                }
            }
        } catch (NameNotFoundException e) {
        }
    }
    // nothing found above; we can apply policy to UID
    return true;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Signature(android.content.pm.Signature)

Example 42 with Signature

use of android.content.pm.Signature in project android_frameworks_base by AOSPA.

the class WebViewFactory method signaturesEquals.

/**
     * Returns true if the signatures match, false otherwise
     */
private static boolean signaturesEquals(Signature[] s1, Signature[] s2) {
    if (s1 == null) {
        return s2 == null;
    }
    if (s2 == null)
        return false;
    ArraySet<Signature> set1 = new ArraySet<>();
    for (Signature signature : s1) {
        set1.add(signature);
    }
    ArraySet<Signature> set2 = new ArraySet<>();
    for (Signature signature : s2) {
        set2.add(signature);
    }
    return set1.equals(set2);
}
Also used : ArraySet(android.util.ArraySet) Signature(android.content.pm.Signature)

Example 43 with Signature

use of android.content.pm.Signature in project qksms by moezbhatti.

the class NetworkPolicyManager method isUidValidForPolicy.

/**
 * Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
 * usually to protect critical system services.
 */
@Deprecated
public static boolean isUidValidForPolicy(Context context, int uid) {
    if (!ALLOW_PLATFORM_APP_POLICY) {
        final PackageManager pm = context.getPackageManager();
        final HashSet<Signature> systemSignature;
        try {
            systemSignature = Sets.newHashSet(pm.getPackageInfo("android", GET_SIGNATURES).signatures);
        } catch (NameNotFoundException e) {
            throw new RuntimeException("problem finding system signature", e);
        }
        try {
            // reject apps signed with platform cert
            for (String packageName : pm.getPackagesForUid(uid)) {
                final HashSet<Signature> packageSignature = Sets.newHashSet(pm.getPackageInfo(packageName, GET_SIGNATURES).signatures);
                if (packageSignature.containsAll(systemSignature)) {
                    return false;
                }
            }
        } catch (NameNotFoundException e) {
        }
    }
    // nothing found above; we can apply policy to UID
    return true;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Signature(android.content.pm.Signature)

Example 44 with Signature

use of android.content.pm.Signature in project android_frameworks_base by crdroidandroid.

the class ServiceWatcher method getSignatureSets.

public static ArrayList<HashSet<Signature>> getSignatureSets(Context context, List<String> initialPackageNames) {
    PackageManager pm = context.getPackageManager();
    ArrayList<HashSet<Signature>> sigSets = new ArrayList<HashSet<Signature>>();
    for (int i = 0, size = initialPackageNames.size(); i < size; i++) {
        String pkg = initialPackageNames.get(i);
        try {
            HashSet<Signature> set = new HashSet<Signature>();
            Signature[] sigs = pm.getPackageInfo(pkg, PackageManager.MATCH_SYSTEM_ONLY | PackageManager.GET_SIGNATURES).signatures;
            set.addAll(Arrays.asList(sigs));
            sigSets.add(set);
        } catch (NameNotFoundException e) {
            Log.w("ServiceWatcher", pkg + " not found");
        }
    }
    return sigSets;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) Signature(android.content.pm.Signature) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 45 with Signature

use of android.content.pm.Signature in project android_frameworks_base by DirtyUnicorns.

the class WebViewFactory method signaturesEquals.

/**
     * Returns true if the signatures match, false otherwise
     */
private static boolean signaturesEquals(Signature[] s1, Signature[] s2) {
    if (s1 == null) {
        return s2 == null;
    }
    if (s2 == null)
        return false;
    ArraySet<Signature> set1 = new ArraySet<>();
    for (Signature signature : s1) {
        set1.add(signature);
    }
    ArraySet<Signature> set2 = new ArraySet<>();
    for (Signature signature : s2) {
        set2.add(signature);
    }
    return set1.equals(set2);
}
Also used : ArraySet(android.util.ArraySet) Signature(android.content.pm.Signature)

Aggregations

Signature (android.content.pm.Signature)97 PackageManager (android.content.pm.PackageManager)34 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)31 PackageInfo (android.content.pm.PackageInfo)26 ArrayList (java.util.ArrayList)16 MessageDigest (java.security.MessageDigest)13 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)13 ArraySet (android.util.ArraySet)11 IOException (java.io.IOException)8 PublicKey (java.security.PublicKey)8 File (java.io.File)7 Intent (android.content.Intent)6 CertificateException (java.security.cert.CertificateException)6 HashSet (java.util.HashSet)6 ResolveInfo (android.content.pm.ResolveInfo)5 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)5 IActivityManager (android.app.IActivityManager)4 INotificationManager (android.app.INotificationManager)4 IProcessObserver (android.app.IProcessObserver)4 PackageParser (android.content.pm.PackageParser)4