added signature check to detect github actions builds and etc

This commit is contained in:
gdlbo
2022-06-16 01:26:07 +03:00
parent fe5616b3f7
commit a7c85a24f2
4 changed files with 74 additions and 13 deletions
@@ -25,6 +25,7 @@ import static ru.vtosters.lite.utils.Preferences.navbar;
import static ru.vtosters.lite.utils.Preferences.offline;
import static ru.vtosters.lite.utils.Preferences.shortinfo;
import static ru.vtosters.lite.utils.Preferences.vkme;
import static ru.vtosters.lite.utils.SignatureChecker.validateAppSignature;
import static ru.vtosters.lite.utils.Themes.applyTheme;
import static ru.vtosters.lite.utils.Themes.getDarkTheme;
import static ru.vtosters.lite.utils.Themes.getImDarkTheme;
@@ -34,6 +35,7 @@ import static ru.vtosters.lite.utils.Themes.setTheme;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -55,6 +57,8 @@ import com.vtosters.lite.fragments.SettingsGeneralFragment;
import com.vtosters.lite.fragments.k.BlacklistFragment;
import com.vtosters.lite.fragments.money.music.control.subscription.MusicSubscriptionControlFragment;
import java.security.NoSuchAlgorithmException;
import ru.vtosters.lite.ui.PreferencesUtil;
import ru.vtosters.lite.ui.dialogs.OTADialog;
import ru.vtosters.lite.ui.fragments.dockbar.DockBarFragment;
@@ -337,20 +341,26 @@ public class VTSettings extends MaterialPreferenceToolbarFragment {
return false;
});
PreferencesUtil.addPreferenceCategory(this, getString("updates"));
try {
if (validateAppSignature()) {
PreferencesUtil.addPreferenceCategory(this, getString("updates"));
PreferencesUtil.addPreference(this, "", getString("checkforupdates"), "", "ic_download_24", preference -> {
OTADialog.checkUpdates(p());
return false;
});
PreferencesUtil.addPreference(this, "", getString("checkforupdates"), "", "ic_download_24", preference -> {
OTADialog.checkUpdates(p());
return false;
});
PreferencesUtil.addMaterialSwitchPreference(this, "checkupdates", getString("checkupdates"), "", "ic_recent_24", true, (preference, o) -> {
boolean value = (boolean) o;
PreferencesUtil.addMaterialSwitchPreference(this, "checkupdates", getString("checkupdates"), "", "ic_recent_24", true, (preference, o) -> {
boolean value = (boolean) o;
edit().putBoolean("checkupdates", value).commit();
edit().putBoolean("checkupdates", value).commit();
return true;
});
return true;
});
}
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
public static String getValAsString(String stringid, Boolean value) {
@@ -46,6 +46,7 @@ import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -63,7 +64,7 @@ public class Globals {
return preferences;
}
public static void MainActivityInit(Activity activity) {
public static void MainActivityInit(Activity activity) throws PackageManager.NameNotFoundException, NoSuchAlgorithmException{
if(checkupdates())
OTADialog.checkUpdates(activity);
Start.alert(activity);
@@ -16,12 +16,14 @@ import static ru.vtosters.lite.utils.Globals.registerActivities;
import static ru.vtosters.lite.utils.Newsfeed.setupFilters;
import static ru.vtosters.lite.utils.OpusLoader.LoadLibrary;
import static ru.vtosters.lite.utils.Proxy.setProxy;
import static ru.vtosters.lite.utils.SignatureChecker.*;
import static ru.vtosters.lite.utils.Themes.systemThemeChanger;
import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -30,6 +32,7 @@ import com.vk.im.engine.models.users.UserSex;
import com.vtosters.lite.data.Users;
import com.vtosters.lite.fragments.SettingsListFragment;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
@@ -361,8 +364,8 @@ public class Preferences {
return getBoolValue("roundedmsgs", false);
}
public static boolean checkupdates() {
return getBoolValue("checkupdates", true);
public static boolean checkupdates() throws PackageManager.NameNotFoundException, NoSuchAlgorithmException{
return getBoolValue("checkupdates", true) && validateAppSignature();
}
public static boolean disableanimstickers() {
@@ -0,0 +1,47 @@
package ru.vtosters.lite.utils;
import static android.content.pm.PackageManager.GET_SIGNATURES;
import static android.content.pm.PackageManager.NameNotFoundException;
import static ru.vtosters.lite.f0x1d.VTVerifications.decode;
import static ru.vtosters.lite.utils.Globals.getContext;
import static ru.vtosters.lite.utils.Globals.getPackageName;
import android.annotation.SuppressLint;
import android.content.pm.PackageInfo;
import android.content.pm.Signature;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class SignatureChecker {
private static final String APP_SIGNATURE = "QzNFQTI3Q0ExNEJENzJFM0U2QUUyMDM0OTdCNDQ0NUFEQUMxRjk0NQ==";
public static String getSHA1(byte[] sig) throws NoSuchAlgorithmException{
MessageDigest digest = MessageDigest.getInstance("SHA1");
digest.update(sig);
byte[] hashtext = digest.digest();
return bytesToHex(hashtext);
}
public static String bytesToHex(byte[] bytes){
final char[] hexArray = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'A', 'B', 'C', 'D', 'E', 'F'};
char[] hexChars = new char[bytes.length * 2];
int v;
for (int j = 0; j < bytes.length; j++) {
v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
}
return new String(hexChars);
}
public static boolean validateAppSignature() throws NameNotFoundException, NoSuchAlgorithmException{
@SuppressLint("PackageManagerGetSignatures") PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getPackageName(), GET_SIGNATURES);
for (Signature signature : packageInfo.signatures) {
String sha1 = getSHA1(signature.toByteArray());
return decode(APP_SIGNATURE).equals(sha1);
}
return false;
}
}