Search in sources :

Example 1 with Signature

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

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

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

the class PluginManager method containsPluginPermissionAndSignatures.

private static boolean containsPluginPermissionAndSignatures(PackageInfo pkgInfo) {
    // check if the plugin has the required permissions
    String[] permissions = pkgInfo.requestedPermissions;
    if (permissions == null) {
        return false;
    }
    boolean permissionOk = false;
    for (String permit : permissions) {
        if (PLUGIN_PERMISSION.equals(permit)) {
            permissionOk = true;
            break;
        }
    }
    if (!permissionOk) {
        return false;
    }
    // check to ensure the plugin is properly signed
    Signature[] signatures = pkgInfo.signatures;
    if (signatures == null) {
        return false;
    }
    if (SystemProperties.getBoolean("ro.secure", false)) {
        boolean signatureMatch = false;
        for (Signature signature : signatures) {
            for (int i = 0; i < SIGNATURES.length; i++) {
                if (SIGNATURES[i].equals(signature)) {
                    signatureMatch = true;
                    break;
                }
            }
        }
        if (!signatureMatch) {
            return false;
        }
    }
    return true;
}
Also used : Signature(android.content.pm.Signature)

Example 3 with Signature

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

the class PackageManagerBackupAgent method writeSignatureArray.

private static void writeSignatureArray(DataOutputStream out, Signature[] sigs) throws IOException {
    // write the number of signatures in the array
    out.writeInt(sigs.length);
    // write the signatures themselves, length + flattened buffer
    for (Signature sig : sigs) {
        byte[] flat = sig.toByteArray();
        out.writeInt(flat.length);
        out.write(flat);
    }
}
Also used : Signature(android.content.pm.Signature)

Example 4 with Signature

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

the class PackageManagerBackupAgent method readSignatureArray.

private static Signature[] readSignatureArray(DataInputStream in) {
    try {
        int num;
        try {
            num = in.readInt();
        } catch (EOFException e) {
            // clean termination
            Slog.w(TAG, "Read empty signature block");
            return null;
        }
        if (DEBUG)
            Slog.v(TAG, " ... unflatten read " + num);
        // Sensical?
        if (num > 20) {
            Slog.e(TAG, "Suspiciously large sig count in restore data; aborting");
            throw new IllegalStateException("Bad restore state");
        }
        Signature[] sigs = new Signature[num];
        for (int i = 0; i < num; i++) {
            int len = in.readInt();
            byte[] flatSig = new byte[len];
            in.read(flatSig);
            sigs[i] = new Signature(flatSig);
        }
        return sigs;
    } catch (IOException e) {
        Slog.e(TAG, "Unable to read signatures");
        return null;
    }
}
Also used : Signature(android.content.pm.Signature) EOFException(java.io.EOFException) IOException(java.io.IOException)

Example 5 with Signature

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

the class PackageSignatures method writeXml.

void writeXml(XmlSerializer serializer, String tagName, ArrayList<Signature> pastSignatures) throws IOException {
    if (mSignatures == null) {
        return;
    }
    serializer.startTag(null, tagName);
    serializer.attribute(null, "count", Integer.toString(mSignatures.length));
    for (int i = 0; i < mSignatures.length; i++) {
        serializer.startTag(null, "cert");
        final Signature sig = mSignatures[i];
        final int sigHash = sig.hashCode();
        final int numPast = pastSignatures.size();
        int j;
        for (j = 0; j < numPast; j++) {
            Signature pastSig = pastSignatures.get(j);
            if (pastSig.hashCode() == sigHash && pastSig.equals(sig)) {
                serializer.attribute(null, "index", Integer.toString(j));
                break;
            }
        }
        if (j >= numPast) {
            pastSignatures.add(sig);
            serializer.attribute(null, "index", Integer.toString(numPast));
            serializer.attribute(null, "key", sig.toCharsString());
        }
        serializer.endTag(null, "cert");
    }
    serializer.endTag(null, tagName);
}
Also used : Signature(android.content.pm.Signature)

Aggregations

Signature (android.content.pm.Signature)96 PackageManager (android.content.pm.PackageManager)33 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)30 PackageInfo (android.content.pm.PackageInfo)25 ArrayList (java.util.ArrayList)16 MessageDigest (java.security.MessageDigest)12 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)12 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 HashSet (java.util.HashSet)6 ResolveInfo (android.content.pm.ResolveInfo)5 INetworkManagementEventObserver (android.net.INetworkManagementEventObserver)5 NetworkPolicyManagerService (com.android.server.net.NetworkPolicyManagerService)5 IActivityManager (android.app.IActivityManager)4 INotificationManager (android.app.INotificationManager)4 IProcessObserver (android.app.IProcessObserver)4 PackageParser (android.content.pm.PackageParser)4