// Path: CoreLibrary/src/main/java/com/didi/virtualapk/internal/Constants.java
// public class Constants {
//     public static final String KEY_IS_PLUGIN = "isPlugin";
//     public static final String KEY_TARGET_PACKAGE = "target.package";
//     public static final String KEY_TARGET_ACTIVITY = "target.activity";
// 
//     public static final String OPTIMIZE_DIR = "dex";
//     public static final String NATIVE_DIR = "valibs";
// 
//     public static final boolean COMBINE_RESOURCES = true;
//     public static final boolean COMBINE_CLASSLOADER = true;
//     public static final boolean DEBUG = true;
//     
//     public static final String TAG = "VA";
//     public static final String TAG_PREFIX = TAG + ".";
// 
// }


import android.content.Context;
import android.util.Base64;
import android.util.Log;
import com.didi.virtualapk.internal.Constants;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/*
 * Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.didi.virtualapk.utils;




/**
 * Created by renyugang on 16/5/12.
 */

/**
 * verify signature of zip file<br>
 * usage: boolean valid = ZipVerifyUtil.verifyZip(context, zipPath)
 */
public class ZipVerifyUtil {

    public static boolean verifyZip(Context context, String zipPath) {
        return verifyZip(context, zipPath, "test.cer");
    }
    
    public static boolean verifyZip(Context context, String zipPath, String cerName) {
        try {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            InputStream in = context.getAssets().open(cerName);
            Certificate certificate = certificateFactory.generateCertificate(in);
            in.close();
            return verifyZip(zipPath, certificate);
        } catch (IOException | CertificateException e) {
// Path: CoreLibrary/src/main/java/com/didi/virtualapk/internal/Constants.java
// public class Constants {
//     public static final String KEY_IS_PLUGIN = "isPlugin";
//     public static final String KEY_TARGET_PACKAGE = "target.package";
//     public static final String KEY_TARGET_ACTIVITY = "target.activity";
// 
//     public static final String OPTIMIZE_DIR = "dex";
//     public static final String NATIVE_DIR = "valibs";
// 
//     public static final boolean COMBINE_RESOURCES = true;
//     public static final boolean COMBINE_CLASSLOADER = true;
//     public static final boolean DEBUG = true;
//     
//     public static final String TAG = "VA";
//     public static final String TAG_PREFIX = TAG + ".";
// 
// }


// Path: CoreLibrary/src/main/java/com/didi/virtualapk/utils/ZipVerifyUtil.java
import android.content.Context;
import android.util.Base64;
import android.util.Log;
import com.didi.virtualapk.internal.Constants;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/*
 * Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.didi.virtualapk.utils;




/**
 * Created by renyugang on 16/5/12.
 */

/**
 * verify signature of zip file<br>
 * usage: boolean valid = ZipVerifyUtil.verifyZip(context, zipPath)
 */
public class ZipVerifyUtil {

    public static boolean verifyZip(Context context, String zipPath) {
        return verifyZip(context, zipPath, "test.cer");
    }
    
    public static boolean verifyZip(Context context, String zipPath, String cerName) {
        try {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            InputStream in = context.getAssets().open(cerName);
            Certificate certificate = certificateFactory.generateCertificate(in);
            in.close();
            return verifyZip(zipPath, certificate);
        } catch (IOException | CertificateException e) {
            Log.w(Constants.TAG, e);