万能钥匙.apk(点击下载) / WkServerPBWrapper.java


package com.lantern.core;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
import com.appara.feed.constant.TTParam;
import com.bluefay.a.d;
import com.bluefay.b.c;
import com.bluefay.b.e;
import com.d.a.a.a.a.a.a;
import com.d.a.a.a.a.a.a.a;
import com.d.a.a.a.b.a.a;
import com.d.a.a.a.b.a.b;
import com.d.b.a.a.a.a;
import com.d.b.a.a.a.c;
import com.lantern.core.model.WkUserInfo;
import com.lantern.core.protobuf.PBResponse;
import com.lantern.core.protobuf.PBUtils;
import com.linksure.browser.BrowserApp;
import com.linksure.browser.analytics.b;
import com.meizu.cloud.pushsdk.notification.model.NotifyType;
import java.util.HashMap;
import java.util.Iterator;
import org.json.JSONObject;

public class WkServerPBWrapper {
    private static String INIT_HOST_NAME = "http://init2.y5en.com";
    private static String REST_INIT_PB = "/alps/fcompb.pgs";
    private Context mContext;
    private Object userSynLock = new Object();
    private WkServer wkServer;

    public void checkLowVersionData() {
    }

    public WkServerPBWrapper(Context context, WkServer wkServer2) {
        this.wkServer = wkServer2;
        this.mContext = context;
    }

    @Deprecated
    public String ensureDHID(String str) {
        return ensureDHID(str, "");
    }

    @Deprecated
    public synchronized String ensureDHID(String str, String str2) {
        int i;
        boolean z = true;
        if (!TextUtils.isEmpty(str2)) {
            e.a("olddhid ensureDHID  bad olddhdh is ".concat(String.valueOf(str2)), new Object[0]);
            i = syncInitDevPB(str2);
        } else if (this.wkServer.mDHID == null || this.wkServer.mDHID.length() <= 0) {
            if (WkSettings.isFirstLaunch(this.mContext)) {
                checkLowVersionData();
                if (this.wkServer.mDHID != null && this.wkServer.mDHID.length() > 0) {
                    return this.wkServer.mDHID;
                }
            }
            d.setBooleanValuePrivate("feed_sexDetect", true);
            i = syncInitDevPB(str2);
        } else {
            return this.wkServer.mDHID;
        }
        reportGetDhidResEvent(i == 1);
        StringBuilder sb = new StringBuilder("report get dhid res ");
        if (i != 1) {
            z = false;
        }
        sb.append(z);
        e.a(sb.toString(), new Object[0]);
        return this.wkServer.mDHID;
    }

    private void reportGetDhidResEvent(boolean z) {
        HashMap hashMap = new HashMap();
        hashMap.put(TTParam.KEY_res, z ? "dhid" : "no_dhid");
        b.b("lsbr_init_app", hashMap);
    }

    public boolean ensureDHID(String str, boolean z) {
        if (z) {
            return ensureSeckey(str);
        }
        String ensureDHID = ensureDHID(str, "");
        return (ensureDHID == null || ensureDHID.length() == 0) ? false : true;
    }

    private synchronized boolean ensureSeckey(String str) {
        if (WkBrowserSecretKeyNativeNew.s1(this.mContext)) {
            return true;
        }
        if (syncInitDevSecPB() == 1) {
            return true;
        }
        return false;
    }

    private int syncInitDevSecPB() {
        String initUrl = getInitUrl();
        byte[] request = PBUtils.getRequest(true, true, "r", "00200003", getInitDevParamSec(this.mContext, "00200003"));
        byte[] post = WkHttp.post(initUrl, request);
        if (post == null || post.length == 0) {
            return 10;
        }
        e.a(c.a(post), new Object[0]);
        try {
            PBResponse response = getResponse("00200003", post, request);
            e.a("response:".concat(String.valueOf(response)), new Object[0]);
            if (!response.isSuccess()) {
                return 31;
            }
            byte[] serverData = response.getServerData();
            if (serverData == null) {
                return 32;
            }
            a.C0095a a2 = a.C0095a.a(serverData);
            String str = a2.f3844b;
            boolean z = a2.c;
            e.a("dhid:".concat(String.valueOf(str)), new Object[0]);
            if (this.wkServer.mDHID == null || this.wkServer.mDHID.length() == 0 || z) {
                setDHID(str, true);
            }
            boolean s9 = WkBrowserSecretKeyNativeNew.s9(a2.f3843a, this.mContext);
            boolean s1 = WkBrowserSecretKeyNativeNew.s1(this.mContext);
            if (!s9 || !s1) {
                return 33;
            }
            return 1;
        } catch (Exception e) {
            e.a(e);
            return 30;
        }
    }

    public void setDHID(String str, boolean z) {
        e.a("dhid:".concat(String.valueOf(str)), new Object[0]);
        if (str != null) {
            this.wkServer.mDHID = str;
            WkSettings.setDHID(this.mContext, str);
            WkSettings.setSDDHID(str, z);
        }
    }

    public void setDHID(String str) {
        e.a("dhid:".concat(String.valueOf(str)), new Object[0]);
        if (str != null) {
            this.wkServer.mDHID = str;
            WkSettings.setDHID(this.mContext, str);
            WkSettings.setSDDHID(str);
        }
    }

    public PBResponse getResponse(String str, byte[] bArr, byte[] bArr2) {
        e.a("getResponse pid:%s", str);
        if (bArr == null) {
            return null;
        }
        return PBUtils.getResponse(bArr, bArr2);
    }

    public PBResponse getResponse(String str, byte[] bArr, boolean z, byte[] bArr2) {
        e.a("getResponse pid:%s", str);
        return PBUtils.getResponse(bArr, z, bArr2);
    }

    private byte[] getInitDevParamSec(Context context, String str) {
        String simSerialNumber = WkPlatform.getSimSerialNumber(context);
        a.C0093a.C0094a a2 = a.C0093a.a();
        if (simSerialNumber == null) {
            simSerialNumber = "";
        }
        a2.a(simSerialNumber);
        a2.b(WkPlatform.getOS());
        a2.c(WkPlatform.getOSVersion());
        a2.d(String.valueOf(WkPlatform.getAndroidVersionCode()));
        a2.e(WkPlatform.getAppVersionName(context));
        a2.f(String.valueOf(WkPlatform.getScreenHeightPixels(context)));
        a2.g(String.valueOf(WkPlatform.getScreenWidthPixels(context)));
        a2.h(WkPlatform.getDeviceFingerprint());
        a2.i(WkPlatform.getDeviceManufacturer());
        a2.j(WkPlatform.getDeviceModel());
        a2.k(WkPlatform.getAndroidID(context));
        a2.l("2.1");
        try {
            String s7 = WkBrowserSecretKeyNativeNew.s7(this.mContext);
            e.a(s7, new Object[0]);
            JSONObject jSONObject = new JSONObject(s7);
            Iterator<String> keys = jSONObject.keys();
            while (keys.hasNext()) {
                String next = keys.next();
                Object obj = jSONObject.get(next);
                if (obj instanceof String) {
                    a2.a(next, (String) obj);
                }
            }
        } catch (Exception e) {
            e.a(e);
        }
        return ((a.C0093a) a2.build()).toByteArray();
    }

    public String getInitUrl() {
        if (com.linksure.browser.preference.a.a().K()) {
            INIT_HOST_NAME = "http://wifi30.51y5.net";
            REST_INIT_PB = "/device/fcompb.pgs";
            return String.format("%s%s", INIT_HOST_NAME, REST_INIT_PB);
        }
        return String.format("%s%s", WkLocalConfig.getInstance().getString("inithost", INIT_HOST_NAME), WkLocalConfig.getInstance().getString("inithostpb", REST_INIT_PB));
    }

    public void setUserInfo(String str, String str2, String str3) {
        WkUserInfo wkUserInfo = new WkUserInfo();
        wkUserInfo.mUHID = str;
        wkUserInfo.mMobileNumber = str2;
        wkUserInfo.mSIMSerialNumber = str3;
        setUserInfo(wkUserInfo);
    }

    public void setUHid(String str) {
        this.wkServer.mUHID = str;
    }

    public boolean hasValidUHID() {
        return this.wkServer.mUHID != null && this.wkServer.mUHID.length() > 0 && !this.wkServer.mUHID.equals(WkServer.FAKE_USER_UHID);
    }

    public void setUserInfo(WkUserInfo wkUserInfo) {
        synchronized (this.userSynLock) {
            if (wkUserInfo != null) {
                if (hasValidUHID() && !this.wkServer.mUHID.equals(wkUserInfo.mUHID)) {
                    clearUserInfo();
                }
            }
            e.a("userinfo:".concat(String.valueOf(wkUserInfo)), new Object[0]);
            if (wkUserInfo != null) {
                this.wkServer.mUHID = wkUserInfo.mUHID;
                WkSettings.setUHID(this.mContext, this.wkServer.mUHID);
                WkSettings.setMobileNumber(this.mContext, wkUserInfo.mMobileNumber);
                WkSettings.setSimSerialNumber(this.mContext, wkUserInfo.mSIMSerialNumber);
                WkSettings.setNickName(this.mContext, wkUserInfo.mNickName);
                WkSettings.setUserAvatar(this.mContext, wkUserInfo.mAvatar);
                WkSettings.setUserToken(this.mContext, wkUserInfo.mUserToken);
                WkSettings.setThirdPartInfos(this.mContext, wkUserInfo.mThirdInfos);
                WkSettings.setOpenId(this.mContext, wkUserInfo.mOpenId);
                WkSettings.setSessionId(wkUserInfo.mSessionId);
                WkSettings.setThirdPartType(this.mContext, wkUserInfo.mThirdType);
                WkSettings.setGender(this.mContext, wkUserInfo.mSex);
            }
        }
    }

    public void clearUserInfo() {
        synchronized (this.userSynLock) {
            e.a("clearUserInfo");
            this.wkServer.mUHID = WkServer.FAKE_USER_UHID;
            WkSettings.setUHID(this.mContext, "");
            WkSettings.setMobileNumber(this.mContext, "");
            WkSettings.setSimSerialNumber(this.mContext, "");
            WkSettings.setNickName(this.mContext, "");
            WkSettings.setSessionId(this.mContext, "");
            WkSettings.setUserAvatar(this.mContext, "");
            WkSettings.setUserToken(this.mContext, "");
            WkSettings.setThirdPartInfos(this.mContext, "");
            WkSettings.setOpenId(this.mContext, "");
            WkSettings.setThirdPartType(this.mContext, "");
            WkSettings.setGender(this.mContext, "");
            WkSettings.clearSDUserInfo();
        }
    }

    public int syncInitDevPB(String str) {
        String initUrl = getInitUrl();
        e.a("olddhid syncInitDevPB  url is ".concat(String.valueOf(initUrl)), new Object[0]);
        e.a("olddhid syncInitDevPB  bad olddhdh is ".concat(String.valueOf(str)), new Object[0]);
        byte[] request = PBUtils.getRequest(true, true, "k", WkServer.INITDEV_PID_PB, getInitDevParam(this.mContext, WkServer.INITDEV_PID_PB, str));
        byte[] post = WkHttp.post(initUrl, request);
        if (post == null || post.length == 0) {
            new StringBuilder("no_dhid").append(com.bluefay.b.d.getIP());
            return 10;
        }
        e.a(c.a(post), new Object[0]);
        try {
            PBResponse response = getResponse(WkServer.INITDEV_PID_PB, post, request);
            e.a("response:".concat(String.valueOf(response)), new Object[0]);
            if (!response.isSuccess()) {
                return 31;
            }
            byte[] serverData = response.getServerData();
            if (serverData == null) {
                return 32;
            }
            String str2 = b.a.a(serverData).f3852a;
            e.a("dhid:".concat(String.valueOf(str2)), new Object[0]);
            if (this.wkServer.mDHID != null) {
                if (this.wkServer.mDHID.length() != 0) {
                    if (TextUtils.isEmpty(str)) {
                        return 0;
                    }
                    e.a("olddhid setDHIDReplaceOldOne new ok dihd is ".concat(String.valueOf(str2)), new Object[0]);
                    setDHIDReplaceOldOne(str2, true);
                    return 1;
                }
            }
            setDHID(str2, true);
            StringBuilder sb = new StringBuilder();
            sb.append(this.wkServer.mDHID);
            sb.append("$");
            sb.append(com.bluefay.b.d.getIP());
            return 1;
        } catch (Exception e) {
            e.a(e);
            return 30;
        }
    }

    private byte[] getInitDevParam(Context context, String str, String str2) {
        String simSerialNumber = WkPlatform.getSimSerialNumber(context);
        a.C0097a.C0098a a2 = a.C0097a.a();
        if (simSerialNumber == null) {
            simSerialNumber = "";
        }
        a2.a(simSerialNumber);
        a2.b(WkPlatform.getOS());
        a2.c(WkPlatform.getOSVersion());
        a2.d(String.valueOf(WkPlatform.getAndroidVersionCode()));
        a2.e(WkPlatform.getAppVersionName(context));
        a2.f(String.valueOf(WkPlatform.getScreenHeightPixels(context)));
        a2.g(String.valueOf(WkPlatform.getScreenWidthPixels(context)));
        a2.h(WkPlatform.getDeviceFingerprint());
        a2.i(WkPlatform.getDeviceManufacturer());
        a2.j(WkPlatform.getDeviceModel());
        a2.k(WkPlatform.getAndroidID(context));
        return ((a.C0097a) a2.build()).toByteArray();
    }

    public void setDHIDReplaceOldOne(String str, boolean z) {
        e.a("dhid:".concat(String.valueOf(str)), new Object[0]);
        if (str != null) {
            this.wkServer.mDHID = str;
            WkSettings.setDHID(this.mContext, str);
            WkSettings.setSDDHIDIfExistClean(str);
            e.a("olddhid WkSettings.setDHID WkSettings.getDHID " + WkSettings.getDHID(""), new Object[0]);
            e.a("olddhid WkSettings.setDHID WkSettings.getSDDHID " + WkSettings.getSDDHID(), new Object[0]);
        }
    }

    public byte[] decrypt(byte[] bArr, String str) {
        return decrypt(bArr, str, true, true);
    }

    public byte[] decrypt(byte[] bArr, String str, boolean z, boolean z2) {
        e.a("dtype:%s so:%s fix:%s", str, Boolean.valueOf(z), Boolean.valueOf(z2));
        if (z) {
            if (NotifyType.LIGHTS.equals(str)) {
                return WkBrowserSecretKeyNativeNew.s13(bArr, z2, this.mContext);
            }
            if ("k".equals(str)) {
                return WkBrowserSecretKeyNativeNew.s17(bArr, z2, this.mContext);
            }
            if ("a".equals(str)) {
                return WkBrowserSecretKeyNativeNew.s11(bArr, this.mContext);
            }
            if ("r".equals(str)) {
                e.c("no r decrypt");
            } else if ("n".equals(str)) {
                return bArr;
            }
        } else if (NotifyType.LIGHTS.equals(str)) {
            e.c("l is native, not java");
        } else if ("a".equals(str)) {
            return WkSecretKey.decryptAES(bArr, this.wkServer.mAESKey, this.wkServer.mAESIV);
        } else {
            if ("r".equals(str)) {
                e.c("r is native, not java");
            } else if ("n".equals(str)) {
                return bArr;
            }
        }
        return null;
    }

    public byte[] getSecurityParamsPBNew(boolean z, String str) {
        e.b("usefix:%s type:%s", Boolean.valueOf(z), str);
        c.a.C0106a a2 = c.a.a();
        a2.a(this.wkServer.mAppId);
        a2.b(this.wkServer.mDHID);
        try {
            a2.d(String.valueOf(this.mContext.getPackageManager().getPackageInfo(this.mContext.getPackageName(), 0).versionCode));
        } catch (Exception e) {
            e.a(e);
        }
        a2.e(this.wkServer.mChannelID);
        a2.f(WkPlatform.getLang());
        if (isValidIMEI(this.wkServer.mIMEI)) {
            a2.g(this.wkServer.mIMEI);
        } else {
            e.a("old:" + this.wkServer.mIMEI);
            this.wkServer.mIMEI = com.bluefay.a.c.getPhoneIMEI(this.mContext);
            e.a("fix:" + this.wkServer.mIMEI);
            a2.g(this.wkServer.mIMEI != null ? this.wkServer.mIMEI : "");
        }
        if (z) {
            a2.a(0);
        } else {
            a2.a(1);
        }
        a2.c(str);
        return ((c.a) a2.build()).toByteArray();
    }

    public byte[] getPublicParamsPBNew(boolean z) {
        String str;
        a.C0101a.C0102a a2 = a.C0101a.a();
        a2.d(this.wkServer.mAppId);
        a2.c(WkPlatform.getLang());
        try {
            PackageInfo packageInfo = this.mContext.getPackageManager().getPackageInfo(this.mContext.getPackageName(), 0);
            a2.j(packageInfo.versionName);
            a2.f(String.valueOf(packageInfo.versionCode));
        } catch (Exception e) {
            e.a(e);
        }
        a2.g(this.wkServer.mChannelID);
        a2.h(this.wkServer.mOrgChannelID);
        if (isValidIMEI(this.wkServer.mIMEI)) {
            a2.i(this.wkServer.mIMEI);
        } else {
            e.a("old:" + this.wkServer.mIMEI);
            this.wkServer.mIMEI = com.bluefay.a.c.getPhoneIMEI(this.mContext);
            e.a("fix:" + this.wkServer.mIMEI);
            a2.i(this.wkServer.mIMEI != null ? this.wkServer.mIMEI : "");
        }
        String localMac = getLocalMac();
        if (localMac == null) {
            localMac = "";
        }
        a2.e(localMac);
        a2.a(this.wkServer.mDHID);
        if (z) {
            a2.b(com.linksure.browser.activity.user.a.c(BrowserApp.f()));
        } else {
            a2.b(this.wkServer.mUHID);
        }
        String networkType = WkPlatform.getNetworkType(this.mContext);
        a2.m(networkType);
        if (TTParam.KEY_w.equals(networkType)) {
            WifiInfo connectionInfo = ((WifiManager) this.mContext.getSystemService("wifi")).getConnectionInfo();
            String str2 = null;
            if (connectionInfo != null) {
                str2 = checkSSID(connectionInfo.getSSID());
                str = checkBSSID(connectionInfo.getBSSID());
            } else {
                str = null;
            }
            if (str2 == null) {
                str2 = "";
            }
            if (str == null) {
                str = "";
            }
            a2.l(str);
            a2.k(str2);
        } else {
            a2.l("");
            a2.k("");
        }
        a2.r(WkSettings.getUserToken(this.mContext));
        a2.q(this.wkServer.mMapProvider);
        a2.o(this.wkServer.mLongitude);
        a2.p(this.wkServer.mLatitude);
        StringBuilder sb = new StringBuilder();
        sb.append(System.currentTimeMillis());
        a2.n(sb.toString());
        return ((a.C0101a) a2.build()).toByteArray();
    }

    public byte[] encrypt(byte[] bArr, String str, boolean z, boolean z2) {
        e.a("etype:%s so:%s fix:%s", str, Boolean.valueOf(z), Boolean.valueOf(z2));
        if (z) {
            if (NotifyType.LIGHTS.equals(str)) {
                return WkBrowserSecretKeyNativeNew.s12(bArr, z2, this.mContext);
            }
            if ("k".equals(str)) {
                try {
                    return WkBrowserSecretKeyNativeNew.s16(bArr, z2, this.mContext);
                } catch (Exception e) {
                    e.c("WkBrowserSecretKeyNativeNew.s16 error ".concat(String.valueOf(e)));
                }
            } else if ("a".equals(str)) {
                return WkBrowserSecretKeyNativeNew.s10(bArr, this.mContext);
            } else {
                if ("r".equals(str)) {
                    return WkBrowserSecretKeyNativeNew.s8(bArr, this.mContext);
                }
            }
        } else if (NotifyType.LIGHTS.equals(str)) {
            e.c("l is native, not java");
        } else if ("a".equals(str)) {
            return WkSecretKey.encryptAES(bArr, this.wkServer.mAESKey, this.wkServer.mAESIV);
        } else {
            if ("r".equals(str)) {
                e.c("r is native, not java");
            }
        }
        return null;
    }

    private static boolean isValidIMEI(String str) {
        return (str == null || str.length() == 0 || "000000000000000".equals(str)) ? false : true;
    }

    public static String checkBSSID(String str) {
        return ("\u0000\u0000:\u0000\u0000:\u0000\u0000:\u0000\u0000:\u0000\u0000:\u0000\u0000".equals(str) || "00:00:00:00:00:00".equals(str)) ? "" : str;
    }

    public static String checkSSID(String str) {
        String removeDoubleQuotes = removeDoubleQuotes(str);
        if (isBadSSID(removeDoubleQuotes)) {
            return "";
        }
        return removeDoubleQuotes.replaceAll("\u0000|\u0001|\u0002|\u0003|\u0004|\u0005|\u0006|\u0007", "*");
    }

    private static String removeDoubleQuotes(String str) {
        int length;
        if (!TextUtils.isEmpty(str) && (length = str.length()) > 1 && str.charAt(0) == '\"') {
            int i = length - 1;
            if (str.charAt(i) == '\"') {
                return str.substring(1, i);
            }
        }
        return str;
    }

    private static boolean isBadSSID(String str) {
        return TextUtils.isEmpty(str) || str.startsWith("0x") || str.startsWith("0X") || str.equalsIgnoreCase("<unknown ssid>") || str.equalsIgnoreCase("null");
    }

    public String getLocalMac() {
        if (this.wkServer.mMAC == null || this.wkServer.mMAC.length() == 0) {
            this.wkServer.mMAC = com.bluefay.d.b.a(this.mContext);
        }
        return this.wkServer.mMAC;
    }

    public byte[] getRequest(String str, byte[] bArr) {
        return PBUtils.getRequest(true, true, "k", str, bArr);
    }
}