Search in sources :

Example 76 with Signature

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

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 77 with Signature

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

the class Utils method getCertFingerprintsFromPackageManager.

/**
     * Returns the normalized sha-256 fingerprints of a given package according to the Android
     * package manager.
     */
public static List<String> getCertFingerprintsFromPackageManager(String packageName, Context context) throws NameNotFoundException {
    Signature[] signatures = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures;
    ArrayList<String> result = new ArrayList<String>(signatures.length);
    for (Signature sig : signatures) {
        result.add(computeNormalizedSha256Fingerprint(sig.toByteArray()));
    }
    return result;
}
Also used : Signature(android.content.pm.Signature) ArrayList(java.util.ArrayList)

Example 78 with Signature

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

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 79 with Signature

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

the class AccountManagerService method calculatePackageSignatureDigest.

private byte[] calculatePackageSignatureDigest(String callerPkg) {
    MessageDigest digester;
    try {
        digester = MessageDigest.getInstance("SHA-256");
        PackageInfo pkgInfo = mPackageManager.getPackageInfo(callerPkg, PackageManager.GET_SIGNATURES);
        for (Signature sig : pkgInfo.signatures) {
            digester.update(sig.toByteArray());
        }
    } catch (NoSuchAlgorithmException x) {
        Log.wtf(TAG, "SHA-256 should be available", x);
        digester = null;
    } catch (NameNotFoundException e) {
        Log.w(TAG, "Could not find packageinfo for: " + callerPkg);
        digester = null;
    }
    return (digester == null) ? null : digester.digest();
}
Also used : NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Signature(android.content.pm.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

Example 80 with Signature

use of android.content.pm.Signature in project weiciyuan by qii.

the class Utility method isCertificateFingerprintCorrect.

//if app's certificate md5 is correct, enable Crashlytics crash log platform, you should not modify those md5 values
public static boolean isCertificateFingerprintCorrect(Context context) {
    try {
        PackageManager pm = context.getPackageManager();
        String packageName = context.getPackageName();
        int flags = PackageManager.GET_SIGNATURES;
        PackageInfo packageInfo = pm.getPackageInfo(packageName, flags);
        Signature[] signatures = packageInfo.signatures;
        byte[] cert = signatures[0].toByteArray();
        String strResult = "";
        MessageDigest md;
        md = MessageDigest.getInstance("MD5");
        md.update(cert);
        for (byte b : md.digest()) {
            strResult += Integer.toString(b & 0xff, 16);
        }
        strResult = strResult.toUpperCase();
        //debug
        if ("DE421D82D4BBF9042886E72AA31FE22".toUpperCase().equals(strResult)) {
            return false;
        }
        //relaease
        if ("C96155C3DAD4CA1069808FBAC813A69".toUpperCase().equals(strResult)) {
            return true;
        }
        AppLogger.e(strResult);
    } catch (NoSuchAlgorithmException ex) {
        ex.printStackTrace();
    } catch (PackageManager.NameNotFoundException ex) {
        ex.printStackTrace();
    }
    return false;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) Signature(android.content.pm.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest)

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