Search in sources :

Example 36 with Signature

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

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

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

the class NetworkPolicyManagerServiceTest method _setUp.

public void _setUp() throws Exception {
    super.setUp();
    setCurrentTimeMillis(TEST_START);
    // intercept various broadcasts, and pretend that uids have packages
    mServiceContext = new BroadcastInterceptingContext(getContext()) {

        @Override
        public PackageManager getPackageManager() {
            return new MockPackageManager() {

                @Override
                public String[] getPackagesForUid(int uid) {
                    return new String[] { "com.example" };
                }

                @Override
                public PackageInfo getPackageInfo(String packageName, int flags) {
                    final PackageInfo info = new PackageInfo();
                    final Signature signature;
                    if ("android".equals(packageName)) {
                        signature = new Signature("F00D");
                    } else {
                        signature = new Signature("DEAD");
                    }
                    info.signatures = new Signature[] { signature };
                    return info;
                }
            };
        }

        @Override
        public void startActivity(Intent intent) {
        // ignored
        }
    };
    mPolicyDir = getContext().getFilesDir();
    if (mPolicyDir.exists()) {
        IoUtils.deleteContents(mPolicyDir);
    }
    mActivityManager = createMock(IActivityManager.class);
    mStatsService = createMock(INetworkStatsService.class);
    mNetworkManager = createMock(INetworkManagementService.class);
    mPolicyListener = createMock(INetworkPolicyListener.class);
    mTime = createMock(TrustedTime.class);
    mConnManager = createMock(IConnectivityManager.class);
    mNotifManager = createMock(INotificationManager.class);
    mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager, mStatsService, mNetworkManager, mTime, mPolicyDir, true);
    mService.bindConnectivityManager(mConnManager);
    mService.bindNotificationManager(mNotifManager);
    // RemoteCallbackList needs a binder to use as key
    expect(mPolicyListener.asBinder()).andReturn(mStubBinder).atLeastOnce();
    replay();
    mService.registerListener(mPolicyListener);
    verifyAndReset();
    // catch IProcessObserver during systemReady()
    final Capture<IProcessObserver> processObserver = new Capture<IProcessObserver>();
    mActivityManager.registerProcessObserver(capture(processObserver));
    expectLastCall().atLeastOnce();
    // catch INetworkManagementEventObserver during systemReady()
    final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
    mNetworkManager.registerObserver(capture(networkObserver));
    expectLastCall().atLeastOnce();
    expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
    expectCurrentTime();
    replay();
    mService.systemReady();
    verifyAndReset();
    mProcessObserver = processObserver.getValue();
    mNetworkObserver = networkObserver.getValue();
}
Also used : PackageInfo(android.content.pm.PackageInfo) TrustedTime(android.util.TrustedTime) INetworkManagementService(android.os.INetworkManagementService) MockPackageManager(android.test.mock.MockPackageManager) Intent(android.content.Intent) INetworkPolicyListener(android.net.INetworkPolicyListener) Capture(org.easymock.Capture) NetworkPolicyManagerService(com.android.server.net.NetworkPolicyManagerService) PackageManager(android.content.pm.PackageManager) MockPackageManager(android.test.mock.MockPackageManager) INotificationManager(android.app.INotificationManager) Signature(android.content.pm.Signature) INetworkStatsService(android.net.INetworkStatsService) INetworkManagementEventObserver(android.net.INetworkManagementEventObserver) IConnectivityManager(android.net.IConnectivityManager) IProcessObserver(android.app.IProcessObserver) IActivityManager(android.app.IActivityManager)

Example 38 with Signature

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

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

use of android.content.pm.Signature in project box-android-sdk by box.

the class OAuthActivity method getBoxAuthApp.

protected Intent getBoxAuthApp() {
    // ensure that the signature of the Box application has an official signature.
    Intent intent = new Intent(BoxConstants.REQUEST_BOX_APP_FOR_AUTH_INTENT_ACTION);
    List<ResolveInfo> infos = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_RESOLVED_FILTER);
    if (infos == null || infos.size() < 1) {
        return null;
    }
    String officialBoxAppString = getResources().getString(R.string.boxsdk_box_app_signature);
    for (ResolveInfo info : infos) {
        try {
            Signature[] signatures = getPackageManager().getPackageInfo(info.activityInfo.packageName, PackageManager.GET_SIGNATURES).signatures;
            if (officialBoxAppString.equals(signatures[0].toCharsString())) {
                intent.setPackage(info.activityInfo.packageName);
                Map<String, BoxAuthenticationInfo> authenticatedMap = BoxAuthentication.getInstance().getStoredAuthInfo(this);
                if (authenticatedMap != null && authenticatedMap.size() > 0) {
                    ArrayList<String> authenticatedUsers = new ArrayList<String>(authenticatedMap.size());
                    for (Map.Entry<String, BoxAuthenticationInfo> set : authenticatedMap.entrySet()) {
                        if (set.getValue().getUser() != null) {
                            authenticatedUsers.add(set.getValue().getUser().toJson());
                        }
                    }
                    if (authenticatedUsers.size() > 0) {
                        intent.putStringArrayListExtra(BoxConstants.KEY_BOX_USERS, authenticatedUsers);
                    }
                }
                return intent;
            }
        } catch (Exception e) {
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) ExecutionException(java.util.concurrent.ExecutionException) BoxException(com.box.androidsdk.content.BoxException) ResolveInfo(android.content.pm.ResolveInfo) BoxAuthenticationInfo(com.box.androidsdk.content.auth.BoxAuthentication.BoxAuthenticationInfo) Signature(android.content.pm.Signature) Map(java.util.Map)

Example 40 with Signature

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

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)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