| 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; | 7 import static org.chromium.webapk.lib.common.WebApkConstants.WEBAPK_PACKAGE_PREF
IX; |
| 8 | 8 |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.Intent; | 10 import android.content.Intent; |
| (...skipping 51 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) | |
| 73 && isValidWebApk(context, info.activityInfo.packageName)) { | 72 && isValidWebApk(context, info.activityInfo.packageName)) { |
| 74 return info.activityInfo.packageName; | 73 return info.activityInfo.packageName; |
| 75 } | 74 } |
| 76 } | 75 } |
| 77 return null; | 76 return null; |
| 78 } | 77 } |
| 79 | 78 |
| 80 /** | 79 /** |
| 81 * Returns whether the provided WebAPK is installed and passes signature che
cks. | 80 * Returns whether the provided WebAPK is installed and passes signature che
cks. |
| 82 * @param context A context | 81 * @param context A context |
| 83 * @param webappPackageName The package name to check | 82 * @param webappPackageName The package name to check |
| 84 * @return true iff the WebAPK is installed and passes security checks | 83 * @return true iff the WebAPK is installed and passes security checks |
| 85 */ | 84 */ |
| 86 private static boolean isValidWebApk(Context context, String webappPackageNa
me) { | 85 public static boolean isValidWebApk(Context context, String webappPackageNam
e) { |
| 87 if (sExpectedSignature == null) { | 86 if (sExpectedSignature == null) { |
| 88 Log.wtf(TAG, "WebApk validation failure - expected signature not set
." | 87 Log.wtf(TAG, "WebApk validation failure - expected signature not set
." |
| 89 + "missing call to WebApkValidator.initWithBrowserHostSignat
ure"); | 88 + "missing call to WebApkValidator.initWithBrowserHostSignat
ure"); |
| 90 } | 89 } |
| 90 if (!webappPackageName.startsWith(WEBAPK_PACKAGE_PREFIX)) { |
| 91 return false; |
| 92 } |
| 91 // check signature | 93 // check signature |
| 92 PackageInfo packageInfo = null; | 94 PackageInfo packageInfo = null; |
| 93 try { | 95 try { |
| 94 packageInfo = context.getPackageManager().getPackageInfo(webappPacka
geName, | 96 packageInfo = context.getPackageManager().getPackageInfo(webappPacka
geName, |
| 95 PackageManager.GET_SIGNATURES); | 97 PackageManager.GET_SIGNATURES); |
| 96 } catch (NameNotFoundException e) { | 98 } catch (NameNotFoundException e) { |
| 97 e.printStackTrace(); | 99 e.printStackTrace(); |
| 98 Log.d(TAG, "WebApk not found"); | 100 Log.d(TAG, "WebApk not found"); |
| 99 return false; | 101 return false; |
| 100 } | 102 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 117 * with for the current host. | 119 * with for the current host. |
| 118 * @param expectedSignature | 120 * @param expectedSignature |
| 119 */ | 121 */ |
| 120 public static void initWithBrowserHostSignature(byte[] expectedSignature) { | 122 public static void initWithBrowserHostSignature(byte[] expectedSignature) { |
| 121 if (sExpectedSignature != null) { | 123 if (sExpectedSignature != null) { |
| 122 return; | 124 return; |
| 123 } | 125 } |
| 124 sExpectedSignature = Arrays.copyOf(expectedSignature, expectedSignature.
length); | 126 sExpectedSignature = Arrays.copyOf(expectedSignature, expectedSignature.
length); |
| 125 } | 127 } |
| 126 } | 128 } |
| OLD | NEW |