龙岗云视频 v2.7版本的 MD5 值为:9298cfa7a85a45936abaf845b6f6bd5c

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


package com.videogo.util;

import android.content.Context;
import android.text.TextUtils;
import com.videogo.util.HttpsUtils;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import okhttp3.EzvizHttpCache;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.Internal;
import org.json.JSONArray;

public class CertUpdateHelper {
    private static final String CERT_UPDATE_URL = "https://download.ezvizops.com/cert/cer.json";
    private static final String PRIVATE_CERT_NAME = "ezvizops.v3.pem.der";
    private static final String TAG = "CertUpdateHelper";
    private static final int TIMEOUT = 15000;
    private static CertUpdateHelper sInstance;
    private File mCertLocalPath;
    private Context mContext = LocalInfo.getInstance().getContext();
    private ExecutorService mExecutorService = Executors.newFixedThreadPool(1);
    private OkHttpClient mHttpClient;

    private CertUpdateHelper() {
    }

    private HttpsUtils.SSLParams createSSLSocketFactory(Context context) {
        InputStream open;
        InputStream inputStream = null;
        try {
            try {
                open = context.getAssets().open(PRIVATE_CERT_NAME);
            } catch (Throwable th) {
                th = th;
            }
        } catch (Exception e) {
            e = e;
        }
        try {
            HttpsUtils.SSLParams sslSocketFactory = HttpsUtils.getSslSocketFactory(open);
            IOUtil.closeQuietly(open);
            return sslSocketFactory;
        } catch (Exception e2) {
            inputStream = open;
            e = e2;
            LogUtil.w(TAG, e);
            IOUtil.closeQuietly(inputStream);
            return HttpsUtils.getSslSocketFactory();
        } catch (Throwable th2) {
            inputStream = open;
            th = th2;
            IOUtil.closeQuietly(inputStream);
            throw th;
        }
    }

    public void downloadCert(final String str) {
        this.mExecutorService.execute(new Runnable() {
            @Override
            public void run() {
                if (TextUtils.isEmpty(str)) {
                    return;
                }
                LogUtil.d(CertUpdateHelper.TAG, "download " + str);
                CertUpdateHelper.this.initCertLocalPath();
                String fileNameByUrl = Utils.getFileNameByUrl(str);
                File file = new File(CertUpdateHelper.this.mCertLocalPath, fileNameByUrl);
                if (file.exists()) {
                    LogUtil.d(CertUpdateHelper.TAG, "download " + str + " exists");
                    return;
                }
                ?? r3 = CertUpdateHelper.this.mCertLocalPath;
                File file2 = new File((File) r3, fileNameByUrl + ".tmp");
                CertUpdateHelper.this.initHttpClient();
                InputStream inputStream = null;
                try {
                    try {
                        try {
                            Response execute = CertUpdateHelper.this.mHttpClient.newCall(new Request.Builder().url(str).build()).execute();
                            LogUtil.d(CertUpdateHelper.TAG, "download " + str + " code:" + execute.code());
                            if (execute.isSuccessful()) {
                                if (!file2.exists()) {
                                    file2.createNewFile();
                                }
                                r3 = execute.body().byteStream();
                                try {
                                    ?? fileOutputStream = new FileOutputStream(file2);
                                    try {
                                        IOUtil.copyLarge(r3, fileOutputStream);
                                        IOUtil.closeQuietly((Closeable) r3);
                                    } catch (Exception e) {
                                        e = e;
                                        inputStream = r3;
                                    } catch (Throwable th) {
                                        th = th;
                                    }
                                    try {
                                        IOUtil.closeQuietly((Closeable) fileOutputStream);
                                        try {
                                            file2.renameTo(file);
                                            LogUtil.d(CertUpdateHelper.TAG, "download " + str + " done");
                                        } catch (Exception e2) {
                                            e = e2;
                                            fileOutputStream = 0;
                                            r3 = inputStream;
                                            inputStream = fileOutputStream;
                                            LogUtil.w(CertUpdateHelper.TAG, e);
                                            IOUtil.closeQuietly((Closeable) r3);
                                            IOUtil.closeQuietly(inputStream);
                                            return;
                                        }
                                    } catch (Exception e3) {
                                        e = e3;
                                    } catch (Throwable th2) {
                                        th = th2;
                                        r3 = 0;
                                        inputStream = fileOutputStream;
                                        IOUtil.closeQuietly((Closeable) r3);
                                        IOUtil.closeQuietly(inputStream);
                                        throw th;
                                    }
                                } catch (Exception e4) {
                                    e = e4;
                                }
                            }
                            IOUtil.closeQuietly((Closeable) null);
                            IOUtil.closeQuietly((Closeable) null);
                        } catch (Throwable th3) {
                            th = th3;
                            r3 = 0;
                        }
                    } catch (Exception e5) {
                        e = e5;
                        r3 = 0;
                    }
                } catch (Throwable th4) {
                    th = th4;
                }
            }
        });
    }

    public static CertUpdateHelper getInstance() {
        if (sInstance == null) {
            synchronized (CertUpdateHelper.class) {
                if (sInstance == null) {
                    sInstance = new CertUpdateHelper();
                }
            }
        }
        return sInstance;
    }

    public void initCertLocalPath() {
        if (this.mCertLocalPath == null) {
            this.mCertLocalPath = new File(this.mContext.getFilesDir(), "cert");
            if (this.mCertLocalPath.exists() || !this.mCertLocalPath.mkdirs()) {
                return;
            }
            LogUtil.e(TAG, "failed to create cert folder!");
        }
    }

    public void initHttpClient() {
        if (this.mHttpClient == null) {
            HttpsUtils.SSLParams createSSLSocketFactory = createSSLSocketFactory(this.mContext);
            OkHttpClient.Builder readTimeout = new OkHttpClient.Builder().sslSocketFactory(createSSLSocketFactory.sSLSocketFactory, createSSLSocketFactory.trustManager).connectTimeout(15000L, TimeUnit.MILLISECONDS).writeTimeout(15000L, TimeUnit.MILLISECONDS).readTimeout(15000L, TimeUnit.MILLISECONDS);
            Internal.instance.setCache(readTimeout, new EzvizHttpCache(this.mContext).internalCache);
            this.mHttpClient = readTimeout.build();
        }
    }

    public void checkCertUpdate() {
        this.mExecutorService.execute(new Runnable() {
            @Override
            public void run() {
                CertUpdateHelper.this.initHttpClient();
                try {
                    Response execute = CertUpdateHelper.this.mHttpClient.newCall(new Request.Builder().url(CertUpdateHelper.CERT_UPDATE_URL).build()).execute();
                    String string = execute.body() != null ? execute.body().string() : null;
                    LogUtil.d(CertUpdateHelper.TAG, string);
                    JSONArray jSONArray = new JSONArray(string);
                    for (int i = 0; i < jSONArray.length(); i++) {
                        CertUpdateHelper.this.downloadCert(jSONArray.getString(i));
                    }
                } catch (Exception e) {
                    LogUtil.w(CertUpdateHelper.TAG, e);
                }
            }
        });
    }

    public File[] getLocalCert() {
        initCertLocalPath();
        return this.mCertLocalPath.listFiles();
    }
}