Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.webapk.lib.client; | 5 package org.chromium.webapk.lib.client; |
| 6 | 6 |
| 7 import static org.chromium.webapk.lib.common.WebApkConstants.WEBAPK_PACKAGE_PREF IX; | |
| 8 | |
| 9 import android.content.Context; | 7 import android.content.Context; |
| 10 import android.content.Intent; | 8 import android.content.Intent; |
| 11 import android.content.pm.PackageInfo; | 9 import android.content.pm.PackageInfo; |
| 12 import android.content.pm.PackageManager; | 10 import android.content.pm.PackageManager; |
| 13 import android.content.pm.PackageManager.NameNotFoundException; | 11 import android.content.pm.PackageManager.NameNotFoundException; |
| 14 import android.content.pm.ResolveInfo; | 12 import android.content.pm.ResolveInfo; |
| 15 import android.content.pm.Signature; | 13 import android.content.pm.Signature; |
| 16 import android.util.Log; | 14 import android.util.Log; |
| 17 | 15 |
| 16 import org.chromium.webapk.lib.common.WebApkConstants; | |
|
Xi Han
2017/01/16 16:56:19
Is this change necessary?
gonzalon
2017/01/16 19:50:44
I could finally figure out what was happening. The
| |
| 17 | |
| 18 import java.util.Arrays; | 18 import java.util.Arrays; |
| 19 import java.util.List; | 19 import java.util.List; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Checks whether a URL belongs to a WebAPK, and whether a WebAPK is signed by t he WebAPK Minting | 22 * Checks whether a URL belongs to a WebAPK, and whether a WebAPK is signed by t he WebAPK Minting |
| 23 * Server. | 23 * Server. |
| 24 */ | 24 */ |
| 25 public class WebApkValidator { | 25 public class WebApkValidator { |
| 26 | 26 |
| 27 private static final String TAG = "WebApkValidator"; | 27 private static final String TAG = "WebApkValidator"; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * @param context The context to use to check whether WebAPK is valid. | 64 * @param context The context to use to check whether WebAPK is valid. |
| 65 * @param infos The ResolveInfos to search. | 65 * @param infos The ResolveInfos to search. |
| 66 * @return Package name of the ResolveInfo which corresponds to a WebAPK. Nu ll if none of the | 66 * @return Package name of the ResolveInfo which corresponds to a WebAPK. Nu ll if none of the |
| 67 * ResolveInfos corresponds to a WebAPK. | 67 * ResolveInfos corresponds to a WebAPK. |
| 68 */ | 68 */ |
| 69 public static String findWebApkPackage(Context context, List<ResolveInfo> in fos) { | 69 public static String findWebApkPackage(Context context, List<ResolveInfo> in fos) { |
| 70 for (ResolveInfo info : infos) { | 70 for (ResolveInfo info : infos) { |
| 71 if (info.activityInfo != null | 71 if (info.activityInfo != null |
| 72 && info.activityInfo.packageName.startsWith(WEBAPK_PACKAGE_P REFIX) | 72 && info.activityInfo.packageName.startsWith( |
| 73 WebApkConstants.WEBAPK_PACKAGE_PREFIX) | |
| 73 && isValidWebApk(context, info.activityInfo.packageName)) { | 74 && isValidWebApk(context, info.activityInfo.packageName)) { |
| 74 return info.activityInfo.packageName; | 75 return info.activityInfo.packageName; |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 return null; | 78 return null; |
| 78 } | 79 } |
| 79 | 80 |
| 80 /** | 81 /** |
| 81 * Returns whether the provided WebAPK is installed and passes signature che cks. | 82 * Returns whether the provided WebAPK is installed and passes signature che cks. |
| 82 * @param context A context | 83 * @param context A context |
| 83 * @param webappPackageName The package name to check | 84 * @param webappPackageName The package name to check |
| 84 * @return true iff the WebAPK is installed and passes security checks | 85 * @return true iff the WebAPK is installed and passes security checks |
| 85 */ | 86 */ |
| 86 private static boolean isValidWebApk(Context context, String webappPackageNa me) { | 87 public static boolean isValidWebApk(Context context, String webappPackageNam e) { |
| 87 if (sExpectedSignature == null) { | 88 if (sExpectedSignature == null) { |
| 88 Log.wtf(TAG, "WebApk validation failure - expected signature not set ." | 89 Log.wtf(TAG, "WebApk validation failure - expected signature not set ." |
| 89 + "missing call to WebApkValidator.initWithBrowserHostSignat ure"); | 90 + "missing call to WebApkValidator.initWithBrowserHostSignat ure"); |
| 90 } | 91 } |
| 91 // check signature | 92 // check signature |
| 92 PackageInfo packageInfo = null; | 93 PackageInfo packageInfo = null; |
| 93 try { | 94 try { |
| 94 packageInfo = context.getPackageManager().getPackageInfo(webappPacka geName, | 95 packageInfo = context.getPackageManager().getPackageInfo(webappPacka geName, |
| 95 PackageManager.GET_SIGNATURES); | 96 PackageManager.GET_SIGNATURES); |
| 96 } catch (NameNotFoundException e) { | 97 } catch (NameNotFoundException e) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 117 * with for the current host. | 118 * with for the current host. |
| 118 * @param expectedSignature | 119 * @param expectedSignature |
| 119 */ | 120 */ |
| 120 public static void initWithBrowserHostSignature(byte[] expectedSignature) { | 121 public static void initWithBrowserHostSignature(byte[] expectedSignature) { |
| 121 if (sExpectedSignature != null) { | 122 if (sExpectedSignature != null) { |
| 122 return; | 123 return; |
| 123 } | 124 } |
| 124 sExpectedSignature = Arrays.copyOf(expectedSignature, expectedSignature. length); | 125 sExpectedSignature = Arrays.copyOf(expectedSignature, expectedSignature. length); |
| 125 } | 126 } |
| 126 } | 127 } |
| OLD | NEW |