Power Battery v2.0.2版本的 MD5 值为:ca694e0112a4d0aa17ae668e765b51de

以下内容为反编译后的 u.java 源代码,内容仅作参考


package com.flurry.sdk;

import android.os.Build;
import android.text.TextUtils;
import android.util.Base64;
import com.flurry.sdk.m;
import com.huawei.hms.ads.co;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.Signature;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Locale;
import java.util.UUID;
import javax.net.ssl.HttpsURLConnection;
public class u extends x {
    private static final String g = "u";
    private static String h;
    private HttpsURLConnection i;
    private String j;

    public u(String str) {
        this.a = str;
        h = "Flurry-Config/1.0 (Android " + Build.VERSION.RELEASE + "/" + Build.ID + ")";
    }

    private static boolean a(String str, String str2, String str3) {
        try {
            PublicKey generatePublic = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(Base64.decode(str, 0)));
            Signature signature = Signature.getInstance("SHA256withRSA");
            signature.initVerify(generatePublic);
            signature.update(str2.getBytes(aa.a));
            return signature.verify(Base64.decode(str3, 0));
        } catch (GeneralSecurityException e) {
            kn.b(g, "GeneralSecurityException for Signature: ".concat(String.valueOf(e)));
            return false;
        }
    }

    private static boolean b(String str, String str2, String str3) {
        try {
            PublicKey generatePublic = KeyFactory.getInstance("EC").generatePublic(new X509EncodedKeySpec(Base64.decode(str, 0)));
            Signature signature = Signature.getInstance("SHA256withECDSA");
            signature.initVerify(generatePublic);
            signature.update(str2.getBytes(aa.a));
            return signature.verify(Base64.decode(str3, 0));
        } catch (GeneralSecurityException e) {
            kn.b(g, "GeneralSecurityException for Signature: ".concat(String.valueOf(e)));
            return false;
        }
    }

    public static boolean d() {
        try {
            KeyFactory.getInstance("EC");
            Signature.getInstance("SHA256withECDSA");
            return true;
        } catch (NoSuchAlgorithmException e) {
            kn.a(g, "ECDSA encryption is not available: ".concat(String.valueOf(e)));
            return false;
        }
    }

    @Override
    protected final InputStream a() throws IOException {
        OutputStream outputStream;
        this.i = (HttpsURLConnection) new URL(this.a).openConnection();
        this.i.setReadTimeout(10000);
        this.i.setConnectTimeout(15000);
        this.i.setRequestMethod("POST");
        this.i.setRequestProperty("User-Agent", h);
        this.i.setRequestProperty("Content-Type", "application/json");
        this.i.setDoInput(true);
        this.i.setDoOutput(true);
        this.c = UUID.randomUUID().toString().toUpperCase(Locale.ENGLISH);
        BufferedWriter bufferedWriter = null;
        try {
            outputStream = this.i.getOutputStream();
            try {
                BufferedWriter bufferedWriter2 = new BufferedWriter(new OutputStreamWriter(outputStream, co.Code));
                try {
                    bufferedWriter2.write(w.a(this.c));
                    bufferedWriter2.close();
                    if (outputStream != null) {
                        outputStream.close();
                    }
                    int responseCode = this.i.getResponseCode();
                    if (responseCode < 400) {
                        if (responseCode == 304) {
                            String headerField = this.i.getHeaderField("guid");
                            if (this.c.equals(headerField)) {
                                this.b = m.b;
                                kn.a(g, "Empty payload; No Change.");
                            } else {
                                this.b = new m(m.a.AUTHENTICATE, "Guid: " + this.c + ", payload: " + headerField);
                                String str = g;
                                StringBuilder sb = new StringBuilder("Authentication error: ");
                                sb.append(this.b);
                                kn.b(str, sb.toString());
                            }
                        }
                        this.j = this.i.getHeaderField("Content-Signature");
                        this.e = this.i.getHeaderField("ETag");
                        if (this.e != null && this.e.startsWith("\"") && this.e.endsWith("\"")) {
                            this.e = this.e.substring(1, this.e.length() - 1);
                        }
                        kn.a(g, "Content-Signature: " + this.j + ", ETag: " + this.e);
                        return this.i.getInputStream();
                    }
                    throw new IOException("Server response code is ".concat(String.valueOf(responseCode)));
                } catch (Throwable th) {
                    th = th;
                    bufferedWriter = bufferedWriter2;
                    if (bufferedWriter != null) {
                        bufferedWriter.close();
                    }
                    if (outputStream != null) {
                        outputStream.close();
                    }
                    throw th;
                }
            } catch (Throwable th2) {
                th = th2;
            }
        } catch (Throwable th3) {
            th = th3;
            outputStream = null;
        }
    }

    @Override
    protected final boolean a(ByteArrayOutputStream byteArrayOutputStream) {
        String[] split;
        String str;
        String str2;
        if (TextUtils.isEmpty(this.j)) {
            str = g;
            str2 = "Content-Signature is empty.";
        } else {
            HashMap hashMap = new HashMap();
            for (String str3 : this.j.split(";")) {
                int indexOf = str3.indexOf("=");
                if (indexOf > 0) {
                    hashMap.put(str3.substring(0, indexOf), str3.substring(indexOf + 1));
                }
            }
            String str4 = (String) hashMap.get("keyid");
            if (TextUtils.isEmpty(str4)) {
                str = g;
                str2 = "Error to get keyid from Signature.";
            } else {
                this.d = z.a.get(str4);
                kn.a(g, "Signature keyid: " + str4 + ", key: " + this.d);
                if (this.d == null) {
                    str = g;
                    str2 = "Unknown keyid from Signature.";
                } else {
                    boolean containsKey = hashMap.containsKey("sha256ecdsa");
                    String str5 = (String) hashMap.get(containsKey ? "sha256ecdsa" : "sha256rsa");
                    if (TextUtils.isEmpty(str5)) {
                        str = g;
                        str2 = "Error to get rsa from Signature.";
                    } else {
                        kn.a(g, "Signature rsa: ".concat(String.valueOf(str5)));
                        String byteArrayOutputStream2 = byteArrayOutputStream.toString();
                        if (containsKey ? b(this.d, byteArrayOutputStream2, str5) : a(this.d, byteArrayOutputStream2, str5)) {
                            return true;
                        }
                        str = g;
                        str2 = "Incorrect signature for response.";
                    }
                }
            }
        }
        kn.b(str, str2);
        return false;
    }

    @Override
    protected final void b() {
        if (this.i != null) {
            this.i.disconnect();
        }
    }

    @Override
    public final boolean c() {
        return "https://cfg.flurry.com/sdk/v1/config".equals(this.a);
    }
}