唐三 4 years ago
parent bcf7bef52d
commit 9ab506e659
  1. 50
      app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java
  2. 75
      app/src/main/java/com/github/tvbox/osc/util/AES.java

@ -14,6 +14,7 @@ import com.github.tvbox.osc.bean.LiveChannelItem;
import com.github.tvbox.osc.bean.ParseBean;
import com.github.tvbox.osc.bean.SourceBean;
import com.github.tvbox.osc.server.ControlManager;
import com.github.tvbox.osc.util.AES;
import com.github.tvbox.osc.util.AdBlocker;
import com.github.tvbox.osc.util.DefaultConfig;
import com.github.tvbox.osc.util.HawkConfig;
@ -83,6 +84,32 @@ public class ApiConfig {
return instance;
}
public static String FindResult(String json, String configKey) {
try {
String content = "";
if (AES.isJson(json)) {
return json;
} else if (!json.startsWith("2423")) {
String[] data = json.split("\\*\\*");
content = new String(Base64.decode(data[1], Base64.DEFAULT));
} else {
content = json;
}
if (content.startsWith("2423")) {
String data = content.substring(content.indexOf("2324") + 4, content.length() - 26);
content = new String(AES.toBytes(content)).toLowerCase();
String key = AES.rightPadding(content.substring(content.indexOf("$#") + 2, content.indexOf("#$")), "0", 16);
String iv = AES.rightPadding(content.substring(content.length() - 13), "0", 16);
json = AES.CBC(data, key, iv);
} else {
json = AES.ECB(content, configKey);
}
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
public void loadConfig(boolean useCache, LoadConfigCallback callback, Activity activity) {
String apiUrl = Hawk.get(HawkConfig.API_URL, "");
if (apiUrl.isEmpty()) {
@ -99,13 +126,21 @@ public class ApiConfig {
th.printStackTrace();
}
}
String apiFix = apiUrl;
if (apiUrl.startsWith("clan://")) {
apiFix = clanToAddress(apiUrl);
}else if(!apiUrl.startsWith("http")){
apiFix = "http://" + apiFix;
String TempKey = null, configUrl = "", pk = ";pk;";
if (apiUrl.contains(pk)) {
String[] a = apiUrl.split(pk);
TempKey = a[1];
if (apiUrl.startsWith("clan")) configUrl = clanToAddress(a[0]);
if (apiUrl.startsWith("http")) configUrl = a[0];
} else if (apiUrl.startsWith("clan") && !apiUrl.contains(pk)) {
configUrl = clanToAddress(apiUrl);
} else if (!apiUrl.startsWith("http") && !apiUrl.contains(pk)) {
configUrl = "http://" + configUrl;
} else {
configUrl = apiUrl;
}
OkGo.<String>get(apiFix)
String configKey = TempKey;
OkGo.<String>get(configUrl)
.headers("User-Agent", userAgent)
.headers("Accept", requestAccept)
.execute(new AbsCallback<String>() {
@ -113,7 +148,8 @@ public class ApiConfig {
public void onSuccess(Response<String> response) {
try {
String json = response.body();
parseJson(apiUrl, response.body());
json = FindResult(json, configKey);
parseJson(apiUrl, json);
try {
File cacheDir = cache.getParentFile();
if (!cacheDir.exists())

@ -0,0 +1,75 @@
package com.github.tvbox.osc.util;
import org.json.JSONObject;
import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class AES {
public static String rightPadding(String key, String replace, int Length) {
String strReturn = "";
String strtemp = "";
int curLength = key .trim().length();
if (key != null && curLength > Length) {
strReturn = key .trim().substring(0, Length);
} else if (key != null && curLength == Length) {
strReturn = key .trim();
} else {
for (int i = 0; i < (Length - curLength); i++) {
strtemp = strtemp + replace;
}
strReturn = key .trim() + strtemp;
}
return strReturn;
}
public static String ECB(String data, String key) {
try {
key = rightPadding(key, "0", 16);
byte[] data2 = toBytes(data);
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
cipher.init(Cipher.DECRYPT_MODE, keySpec);
return new String(cipher.doFinal(data2));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String CBC(String data, String key, String iv) {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv.getBytes());
cipher.init(Cipher.DECRYPT_MODE, keySpec, paramSpec);
return new String(cipher.doFinal(toBytes(data)));
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static boolean isJson(String content) {
try {
new JSONObject(content);
return true;
} catch (Exception e) {
return false;
}
}
public static byte[] toBytes(String src) {
int l = src.length() / 2;
byte[] ret = new byte[l];
for (int i = 0; i < l; i++) {
ret[i] = Integer.valueOf(src.substring(i * 2, i * 2 + 2), 16).byteValue();
}
return ret;
}
}
Loading…
Cancel
Save