add 安全秘钥

This commit is contained in:
pc 2024-07-29 17:45:34 +08:00
parent 1618540d17
commit 00fd4b4928
13 changed files with 158 additions and 32 deletions

View File

@ -152,11 +152,7 @@ tasks.getByName("clean", type = Delete::class) {
delete(file(geoFilesDownloadDir + "/geosite.dat"))
}
android {
buildTypes {
getByName("release") {
signingConfig = signingConfigs.getByName("debug")
}
}
defaultConfig {
ndk {
abiFilters.add("arm64-v8a")

View File

@ -43,7 +43,10 @@ import com.yingmao.clash.net.http.HttpStatus
import com.yingmao.clash.net.http.entity.LoginRsp
import com.yingmao.clash.net.http.entity.RegisterRspOld
import com.yingmao.clash.net.http.entity.SubscriptionRsp
import com.yingmao.clash.service.ClashManager
import com.yingmao.clash.service.model.Profile
import com.yingmao.clash.service.remote.IClashManager
import com.yingmao.clash.service.remote.wrap
import com.yingmao.clash.util.AESUtil
import com.yingmao.clash.util.Utils
import com.yingmao.clash.util.withProfile
@ -92,27 +95,45 @@ class SplashActivity : BaseActivity() {
// requestPermissions(mPermissions.toTypedArray(), PERMISSION_REQUEST_CODE)
// }
// }
// Log.e("gg", "Stup.key======================>" + Stup.key())
val routerSet = MMKV.defaultMMKV().decodeStringSet(BZYConstants.MMKV_KEY_ROUTER_HOST)
if (routerSet != null && routerSet.size > 0) {
isNeedRegister()
} else {
if (BuildConfig.productId == "182265") {
isNeedRegister()
} else {
splashAtyVM.getHost(object : AsyncCallback {
override suspend fun suc() {
Log.e("data", "getHost suc")
MainScope().launch {
isNeedRegister()
}
}
override fun err() {
Log.e("data", "getHost err")
var clashBinder = MainApplication.getApp()?.let {
ClashManager(it).wrap() as IClashManager
}
clashBinder?.let { cb ->
var signList =
AESUtil.getSingInfo(this@SplashActivity, BuildConfig.applicationId, AESUtil.SHA256)
if (signList.isNotEmpty()) {
var si = signList[0]
var ss1 = cb.getSS1(si)
var ss2 = cb.getSS2(si)
com.yingmao.clash.common.log.Log.d("si==>${si}, ss1==>${ss1}, ss2==>${ss2}")
AESUtil.KEY2 = ss1
AESUtil.IV2 = ss2
val routerSet =
MMKV.defaultMMKV().decodeStringSet(BZYConstants.MMKV_KEY_ROUTER_HOST)
if (routerSet != null && routerSet.size > 0) {
isNeedRegister()
} else {
if (BuildConfig.productId == "182265") { //太子没有备用域名所以无需调用getHost
isNeedRegister()
} else {
splashAtyVM.getHost(object : AsyncCallback {
override suspend fun suc() {
Log.e("data", "getHost suc")
MainScope().launch {
isNeedRegister()
}
}
override fun err() {
Log.e("data", "getHost err")
}
})
}
})
}
}
}
// val Sgtr= AESUtil.decrypt("DCBF7D3857DB252D9D07265D9EB7F2CF2DD5B6070C6BF6B4EC88A1452B8C30834BBC82465ECD117CAA816E18AF526EBA5749AFA0E504F7EE178912BAFAA308268326299157402233C4C3D7319B1843C680C340F137060762ED370DE8DDB5516A51DE118EE83C6C556B579D2C7B1612D98C64153D11334425298E096461A899DF")

View File

@ -1,11 +1,15 @@
package com.yingmao.clash.util;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.telephony.TelephonyManager;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -19,7 +23,99 @@ import javax.crypto.spec.SecretKeySpec;
public class AESUtil {
public final static String MD5 = "MD5";
public final static String SHA1 = "SHA1";
public final static String SHA256 = "SHA256";
/**
* 返回一个签名的对应类型的字符串
*
* @param context
* @param packageName
* @param type
*
* @return
*/
public static ArrayList<String> getSingInfo(Context context, String packageName, String type)
{
ArrayList<String> result = new ArrayList<String>();
try
{
Signature[] signs = getSignatures(context, packageName);
for (Signature sig : signs)
{
String tmp = "error!";
if (MD5.equals(type))
{
tmp = getSignatureString(sig, MD5);
}
else if (SHA1.equals(type))
{
tmp = getSignatureString(sig, SHA1);
}
else if (SHA256.equals(type))
{
tmp = getSignatureString(sig, SHA256);
}
result.add(tmp);
}
}
catch (Exception e)
{
e.printStackTrace();
}
return result;
}
/**
* 返回对应包的签名信息
*
* @param context
* @param packageName
* @return
*/
public static Signature[] getSignatures(Context context, String packageName) {
PackageInfo packageInfo = null;
try {
packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
return packageInfo.signatures;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return null;
}
/**
* 获取相应的类型的字符串把签名的byte[]信息转换成16进制
*
* @param sig
* @param type
*
* @return
*/
public static String getSignatureString(Signature sig, String type)
{
byte[] hexBytes = sig.toByteArray();
String fingerprint = "error!";
try
{
MessageDigest digest = MessageDigest.getInstance(type);
if (digest != null)
{
byte[] digestBytes = digest.digest(hexBytes);
StringBuilder sb = new StringBuilder();
for (byte digestByte : digestBytes)
{
sb.append((Integer.toHexString((digestByte & 0xFF) | 0x100)).substring(1, 3));
}
fingerprint = sb.toString();
}
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
return fingerprint;
}
/**
* MD5
*
@ -154,9 +250,10 @@ public class AESUtil {
private static final String KEY_ALGORITHM = "AES";
private static final String DEFAULT_CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding";//默认的加密算法
private static final String KEY = "rwb6c4e7fz$6el%0";//默认的加密算法
private static final String IV = "z1b6c3t4e5f6k7w8";//默认的加密算法
// private static final String KEY = "";//默认的加密算法
public static String KEY2 = "";//默认的加密算法
// private static final String IV = "";//默认的加密算法
public static String IV2 = "";//默认的加密算法
/**
* AES 加密操作
*
@ -169,10 +266,10 @@ public class AESUtil {
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
//密码key(超过16字节即128bit的key需要替换jre中的local_policy.jar和US_export_policy.jar否则报错Illegal key size)
SecretKeySpec keySpec = new SecretKeySpec(KEY.getBytes(StandardCharsets.UTF_8), KEY_ALGORITHM);
SecretKeySpec keySpec = new SecretKeySpec(KEY2.getBytes(StandardCharsets.UTF_8), KEY_ALGORITHM);
//向量iv
IvParameterSpec ivParameterSpec = new IvParameterSpec(IV.getBytes(StandardCharsets.UTF_8));
IvParameterSpec ivParameterSpec = new IvParameterSpec(IV2.getBytes(StandardCharsets.UTF_8));
//初始化为加密模式的密码器
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivParameterSpec);
@ -241,10 +338,10 @@ public class AESUtil {
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM);
//密码key
SecretKeySpec keySpec = new SecretKeySpec(KEY.getBytes("utf-8"), KEY_ALGORITHM);
SecretKeySpec keySpec = new SecretKeySpec(KEY2.getBytes("utf-8"), KEY_ALGORITHM);
//向量iv
IvParameterSpec ivParameterSpec = new IvParameterSpec(IV.getBytes("utf-8"));
IvParameterSpec ivParameterSpec = new IvParameterSpec(IV2.getBytes("utf-8"));
//初始化为解密模式的密码器
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParameterSpec);

View File

@ -139,6 +139,8 @@ extern int patchSelector(c_string selector, c_string name);
extern char* queryProviders();
extern void updateProvider(void* completable, c_string pType, c_string name);
extern void suspend(int suspended);
extern char* getSS1(c_string name);
extern char* getSS2(c_string name);
extern char* installSideloadGeoip(void* block, int blockSize);
#ifdef __cplusplus

View File

@ -139,6 +139,8 @@ extern int patchSelector(c_string selector, c_string name);
extern char* queryProviders();
extern void updateProvider(void* completable, c_string pType, c_string name);
extern void suspend(int suspended);
extern char* getSS1(c_string name);
extern char* getSS2(c_string name);
extern char* installSideloadGeoip(void* block, int blockSize);
#ifdef __cplusplus

Binary file not shown.

Binary file not shown.

View File

@ -404,7 +404,7 @@ subprojects {
}
sourceSets {
getByName("182227") {
getByName("9972") {
java.srcDirs("src/foss/java")
}
}
@ -412,6 +412,7 @@ subprojects {
signingConfigs {
val keystore = rootProject.file("signing.properties")
if (keystore.exists()) {
print("keystore exists! ")
create("release") {
val prop = Properties().apply {
keystore.inputStream().use(this::load)
@ -421,6 +422,8 @@ subprojects {
keyAlias = prop.getProperty("key.alias")!!
keyPassword = prop.getProperty("key.password")!!
}
}else{
print("keystore not exists")
}
}
@ -429,13 +432,14 @@ subprojects {
versionNameSuffix = ".release"
// isMinifyEnabled = isApp
// isShrinkResources = isApp
// signingConfig = signingConfigs.findByName("release")
signingConfig = signingConfigs.findByName("release")
// proguardFiles(
// getDefaultProguardFile("proguard-android-optimize.txt"),
// "proguard-rules.pro"
// )
}
named("debug") {
signingConfig = signingConfigs.findByName("release")
versionNameSuffix = ".debug"
}
}

4
signing.properties Normal file
View File

@ -0,0 +1,4 @@
keystore.path=/Users/pc/open_v/v_clash_android/octopus_clash.jks
keystore.password=123456
key.alias=key0
key.password=123456