From b01cf117c3f0d4b230fe9d6db18278b8dd5927b7 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 27 Sep 2018 06:44:02 +0000 Subject: [PATCH] Check signature --- .../java/eu/faircode/email/ActivityView.java | 6 ++++- .../java/eu/faircode/email/FragmentAbout.java | 10 ++++--- .../main/java/eu/faircode/email/Helper.java | 26 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 ++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index 3100b877..8054281e 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -368,7 +368,11 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB sb.append(context.getString(R.string.title_crash_info_remark) + "\n\n\n\n"); - sb.append(String.format("%s: %s\r\n", context.getString(R.string.app_name), BuildConfig.VERSION_NAME)); + sb.append(String.format("%s: %s %s/%s\r\n", + context.getString(R.string.app_name), + BuildConfig.APPLICATION_ID, + BuildConfig.VERSION_NAME, + Helper.hasValidFingerprint(context) ? "1" : "3")); sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT)); sb.append("\r\n"); diff --git a/app/src/main/java/eu/faircode/email/FragmentAbout.java b/app/src/main/java/eu/faircode/email/FragmentAbout.java index bbb560f0..2d3383f3 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAbout.java +++ b/app/src/main/java/eu/faircode/email/FragmentAbout.java @@ -88,7 +88,11 @@ public class FragmentAbout extends FragmentEx { sb.append(context.getString(R.string.title_debug_info_remark) + "\n\n\n\n"); // Get version info - sb.append(String.format("%s: %s\r\n", context.getString(R.string.app_name), BuildConfig.VERSION_NAME)); + sb.append(String.format("%s: %s %s/%s\r\n", + context.getString(R.string.app_name), + BuildConfig.APPLICATION_ID, + BuildConfig.VERSION_NAME, + Helper.hasValidFingerprint(context) ? "1" : "3")); sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT)); sb.append("\r\n"); @@ -250,8 +254,8 @@ public class FragmentAbout extends FragmentEx { }); boolean debug = PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("debug", false); - btnLog.setVisibility(debug ? View.VISIBLE : View.GONE); - btnDebugInfo.setVisibility(debug ? View.VISIBLE : View.GONE); + btnLog.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE); + btnDebugInfo.setVisibility(debug || BuildConfig.DEBUG ? View.VISIBLE : View.GONE); return view; } diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index f15a8149..413dd306 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -23,6 +23,8 @@ import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; import android.content.res.TypedArray; import android.net.Uri; import android.preference.PreferenceManager; @@ -328,6 +330,30 @@ public class Helper { } } + public static String getFingerprint(Context context) { + try { + PackageManager pm = context.getPackageManager(); + String pkg = context.getPackageName(); + PackageInfo info = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES); + byte[] cert = info.signatures[0].toByteArray(); + MessageDigest digest = MessageDigest.getInstance("SHA1"); + byte[] bytes = digest.digest(cert); + StringBuilder sb = new StringBuilder(); + for (byte b : bytes) + sb.append(Integer.toString(b & 0xff, 16).toUpperCase()); + return sb.toString(); + } catch (Throwable ex) { + Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); + return null; + } + } + + public static boolean hasValidFingerprint(Context context) { + String signed = getFingerprint(context); + String expected = context.getString(R.string.fingerprint); + return (signed != null && signed.equals(expected)); + } + static boolean isPro(Context context) { if (false && BuildConfig.DEBUG) return true; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9780a5eb..6e039fcb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -302,4 +302,6 @@ @color/grey @color/dark_grey + + 17BA15C1AF55D925F98B99CEA4375D4CDF4C174B