Commit 39c9b8c6 authored by Dominick Ng's avatar Dominick Ng Committed by Commit Bot

Add a debug flag for the WebApkValidator to cut down logcat spam.

BUG=None

Change-Id: Ie6bcdd0b88fd32f8416871f58381cd88f2b6e234
Reviewed-on: https://chromium-review.googlesource.com/c/1364650
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: default avatarXi Han <hanxi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614350}
parent 409e0ff6
...@@ -40,6 +40,7 @@ public class WebApkValidator { ...@@ -40,6 +40,7 @@ public class WebApkValidator {
private static final String MAPSLITE_PACKAGE_NAME = "com.google.android.apps.mapslite"; private static final String MAPSLITE_PACKAGE_NAME = "com.google.android.apps.mapslite";
private static final String MAPSLITE_URL_PREFIX = private static final String MAPSLITE_URL_PREFIX =
"https://www.google.com/maps"; // Matches scope. "https://www.google.com/maps"; // Matches scope.
private static final boolean DEBUG = false;
private static byte[] sExpectedSignature; private static byte[] sExpectedSignature;
private static byte[] sCommentSignedPublicKeyBytes; private static byte[] sCommentSignedPublicKeyBytes;
...@@ -200,22 +201,28 @@ public class WebApkValidator { ...@@ -200,22 +201,28 @@ public class WebApkValidator {
packageInfo = context.getPackageManager().getPackageInfo(webappPackageName, packageInfo = context.getPackageManager().getPackageInfo(webappPackageName,
PackageManager.GET_SIGNATURES | PackageManager.GET_META_DATA); PackageManager.GET_SIGNATURES | PackageManager.GET_META_DATA);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); if (DEBUG) {
Log.d(TAG, "WebApk not found"); e.printStackTrace();
Log.d(TAG, "WebApk not found");
}
return false; return false;
} }
if (isNotWebApkQuick(packageInfo)) { if (isNotWebApkQuick(packageInfo)) {
return false; return false;
} }
if (sOverrideValidationForTesting) { if (sOverrideValidationForTesting) {
Log.d(TAG, "Ok! Looks like a WebApk (has start url) and validation is disabled."); if (DEBUG) {
Log.d(TAG, "Ok! Looks like a WebApk (has start url) and validation is disabled.");
}
return true; return true;
} }
if (verifyV1WebApk(packageInfo, webappPackageName)) { if (verifyV1WebApk(packageInfo, webappPackageName)) {
return true; return true;
} }
if (verifyMapsLite(packageInfo, webappPackageName)) { if (verifyMapsLite(packageInfo, webappPackageName)) {
Log.d(TAG, "Matches Maps Lite"); if (DEBUG) {
Log.d(TAG, "Matches Maps Lite");
}
return true; return true;
} }
return verifyCommentSignedWebApk(packageInfo); return verifyCommentSignedWebApk(packageInfo);
...@@ -239,7 +246,9 @@ public class WebApkValidator { ...@@ -239,7 +246,9 @@ public class WebApkValidator {
} }
for (Signature signature : packageInfo.signatures) { for (Signature signature : packageInfo.signatures) {
if (Arrays.equals(sExpectedSignature, signature.toByteArray())) { if (Arrays.equals(sExpectedSignature, signature.toByteArray())) {
Log.d(TAG, "WebApk valid - signature match!"); if (DEBUG) {
Log.d(TAG, "WebApk valid - signature match!");
}
return true; return true;
} }
} }
...@@ -252,12 +261,16 @@ public class WebApkValidator { ...@@ -252,12 +261,16 @@ public class WebApkValidator {
} }
String startUrl = packageInfo.applicationInfo.metaData.getString(START_URL); String startUrl = packageInfo.applicationInfo.metaData.getString(START_URL);
if (startUrl == null || !startUrl.startsWith(MAPSLITE_URL_PREFIX)) { if (startUrl == null || !startUrl.startsWith(MAPSLITE_URL_PREFIX)) {
Log.d(TAG, "mapslite invalid startUrl prefix"); if (DEBUG) {
Log.d(TAG, "mapslite invalid startUrl prefix");
}
return false; return false;
} }
String scope = packageInfo.applicationInfo.metaData.getString(SCOPE); String scope = packageInfo.applicationInfo.metaData.getString(SCOPE);
if (scope == null || !scope.equals(MAPSLITE_URL_PREFIX)) { if (scope == null || !scope.equals(MAPSLITE_URL_PREFIX)) {
Log.d(TAG, "mapslite invalid scope prefix"); if (DEBUG) {
Log.d(TAG, "mapslite invalid scope prefix");
}
return false; return false;
} }
return true; return true;
...@@ -303,7 +316,9 @@ public class WebApkValidator { ...@@ -303,7 +316,9 @@ public class WebApkValidator {
result = v.verifySignature(commentSignedPublicKey); result = v.verifySignature(commentSignedPublicKey);
// TODO(scottkirkwood): remove this log once well tested. // TODO(scottkirkwood): remove this log once well tested.
Log.d(TAG, "File " + packageFilename + ": " + result); if (DEBUG) {
Log.d(TAG, "File " + packageFilename + ": " + result);
}
return result == WebApkVerifySignature.ERROR_OK; return result == WebApkVerifySignature.ERROR_OK;
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "WebApk file error for file " + packageFilename, e); Log.e(TAG, "WebApk file error for file " + packageFilename, e);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment