Browse Source

Check signature

main
M66B 6 years ago
parent
commit
b01cf117c3
4 changed files with 40 additions and 4 deletions
  1. +5
    -1
      app/src/main/java/eu/faircode/email/ActivityView.java
  2. +7
    -3
      app/src/main/java/eu/faircode/email/FragmentAbout.java
  3. +26
    -0
      app/src/main/java/eu/faircode/email/Helper.java
  4. +2
    -0
      app/src/main/res/values/strings.xml

+ 5
- 1
app/src/main/java/eu/faircode/email/ActivityView.java View File

@ -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");


+ 7
- 3
app/src/main/java/eu/faircode/email/FragmentAbout.java View File

@ -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;
}


+ 26
- 0
app/src/main/java/eu/faircode/email/Helper.java View File

@ -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;


+ 2
- 0
app/src/main/res/values/strings.xml View File

@ -302,4 +302,6 @@
<item>@color/grey</item>
<item>@color/dark_grey</item>
</array>
<string name="fingerprint" translatable="false">17BA15C1AF55D925F98B99CEA4375D4CDF4C174B</string>
</resources>

Loading…
Cancel
Save