Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationDelegateImpl.java

Issue 2167573003: Verify intent signatures. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change return to continue in for loop Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.externalnav; 5 package org.chromium.chrome.browser.externalnav;
6 6
7 import android.Manifest.permission; 7 import android.Manifest.permission;
8 import android.app.Activity; 8 import android.app.Activity;
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.DialogInterface; 10 import android.content.DialogInterface;
11 import android.content.DialogInterface.OnCancelListener; 11 import android.content.DialogInterface.OnCancelListener;
12 import android.content.DialogInterface.OnClickListener; 12 import android.content.DialogInterface.OnClickListener;
13 import android.content.Intent; 13 import android.content.Intent;
14 import android.content.IntentFilter; 14 import android.content.IntentFilter;
15 import android.content.pm.PackageManager; 15 import android.content.pm.PackageManager;
16 import android.content.pm.ResolveInfo; 16 import android.content.pm.ResolveInfo;
17 import android.content.pm.Signature;
17 import android.net.Uri; 18 import android.net.Uri;
18 import android.os.Build; 19 import android.os.Build;
19 import android.os.StrictMode; 20 import android.os.StrictMode;
20 import android.os.TransactionTooLargeException; 21 import android.os.TransactionTooLargeException;
21 import android.provider.Browser; 22 import android.provider.Browser;
22 import android.provider.Telephony; 23 import android.provider.Telephony;
23 import android.support.v7.app.AlertDialog; 24 import android.support.v7.app.AlertDialog;
24 import android.text.TextUtils; 25 import android.text.TextUtils;
25 import android.util.Log; 26 import android.util.Log;
26 import android.webkit.MimeTypeMap; 27 import android.webkit.MimeTypeMap;
(...skipping 15 matching lines...) Expand all
42 import org.chromium.chrome.browser.tab.Tab; 43 import org.chromium.chrome.browser.tab.Tab;
43 import org.chromium.chrome.browser.util.FeatureUtilities; 44 import org.chromium.chrome.browser.util.FeatureUtilities;
44 import org.chromium.chrome.browser.util.UrlUtilities; 45 import org.chromium.chrome.browser.util.UrlUtilities;
45 import org.chromium.content_public.browser.LoadUrlParams; 46 import org.chromium.content_public.browser.LoadUrlParams;
46 import org.chromium.content_public.common.Referrer; 47 import org.chromium.content_public.common.Referrer;
47 import org.chromium.ui.base.PageTransition; 48 import org.chromium.ui.base.PageTransition;
48 import org.chromium.ui.base.WindowAndroid; 49 import org.chromium.ui.base.WindowAndroid;
49 import org.chromium.ui.base.WindowAndroid.PermissionCallback; 50 import org.chromium.ui.base.WindowAndroid.PermissionCallback;
50 import org.chromium.webapk.lib.client.WebApkValidator; 51 import org.chromium.webapk.lib.client.WebApkValidator;
51 52
53 import java.security.MessageDigest;
54 import java.security.NoSuchAlgorithmException;
52 import java.util.ArrayList; 55 import java.util.ArrayList;
56 import java.util.HashSet;
53 import java.util.List; 57 import java.util.List;
58 import java.util.Set;
54 59
55 /** 60 /**
56 * The main implementation of the {@link ExternalNavigationDelegate}. 61 * The main implementation of the {@link ExternalNavigationDelegate}.
57 */ 62 */
58 public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat e { 63 public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat e {
59 private static final String TAG = "ExternalNavigationDelegateImpl"; 64 private static final String TAG = "ExternalNavigationDelegateImpl";
60 private static final String PDF_VIEWER = "com.google.android.apps.docs"; 65 private static final String PDF_VIEWER = "com.google.android.apps.docs";
61 private static final String PDF_MIME = "application/pdf"; 66 private static final String PDF_MIME = "application/pdf";
62 private static final String PDF_SUFFIX = ".pdf"; 67 private static final String PDF_SUFFIX = ".pdf";
63 private static final String PDF_EXTENSION = "pdf"; 68 private static final String PDF_EXTENSION = "pdf";
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 if (TextUtils.isEmpty(fileExtension)) return false; 540 if (TextUtils.isEmpty(fileExtension)) return false;
536 541
537 return PDF_EXTENSION.equals(fileExtension); 542 return PDF_EXTENSION.equals(fileExtension);
538 } 543 }
539 544
540 @Override 545 @Override
541 public void maybeRecordAppHandlersInIntent(Intent intent, List<ResolveInfo> infos) { 546 public void maybeRecordAppHandlersInIntent(Intent intent, List<ResolveInfo> infos) {
542 intent.putExtra(IntentHandler.EXTRA_EXTERNAL_NAV_PACKAGES, 547 intent.putExtra(IntentHandler.EXTRA_EXTERNAL_NAV_PACKAGES,
543 getSpecializedHandlersWithFilter(infos, null)); 548 getSpecializedHandlersWithFilter(infos, null));
544 } 549 }
550
551
552 @Override
553 public Set<String> getPackageSHA256Fingerprints(String pkgName) {
554 PackageManager pm = getAvailableContext().getPackageManager();
555 Signature[] signatures;
556 try {
557 signatures = pm.getPackageInfo(pkgName,
558 PackageManager.GET_SIGNATURES).signatures;
559 } catch (PackageManager.NameNotFoundException e) {
560 return null;
561 }
562 Set<String> fingerPrints = new HashSet<>();
563 for (int i = 0; i < signatures.length; ++i) {
564 String fingerPrint = getSha256(signatures[i].toByteArray());
565 if (fingerPrint == null) {
566 return null;
567 }
568 fingerPrints.add(fingerPrint);
569 }
570 return fingerPrints;
571 }
572
573 /**
574 * Compute sha256 fingerprint from signature using MessageDigest.
575 *
576 * @param signature The signature to process.
577 * @return The hex string for the fingerprint or null on failure.
578 */
579 private String getSha256(byte[] signature) {
580 MessageDigest digester;
581 try {
582 digester = MessageDigest.getInstance("SHA-256");
583 } catch (NoSuchAlgorithmException e) {
584 return null;
585 }
586 digester.update(signature);
587 return byteArrayToHexString(digester.digest());
588 }
589
590 /**
591 * Convert bytes to a hex string.
592 *
593 * @param bytes The bytes to convert into a string.
594 * @return The hex string for the bytes or null on empty bytes.
595 */
596 private String byteArrayToHexString(byte[] bytes) {
597 if (bytes.length == 0) {
598 return null;
599 }
600 StringBuilder hexString = new StringBuilder();
601 for (int i = 0; i < bytes.length; ++i) {
602 hexString.append(Integer.toHexString((bytes[i] >> 4) & 0x0f));
603 hexString.append(Integer.toHexString(bytes[i] & 0x0f));
604 }
605 return hexString.toString().toUpperCase();
606 }
607
545 } 608 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698