net.dongliu.apk.parser.bean.CertificateMeta Java Examples

The following examples show how to use net.dongliu.apk.parser.bean.CertificateMeta. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CertificateParser.java    From ApkToolPlus with Apache License 2.0 6 votes vote down vote up
/**
 * get certificate info
 *
 * @throws IOException
 * @throws CertificateEncodingException
 */
public void parse() throws IOException, CertificateException {

    PKCS7 pkcs7 = new PKCS7(Utils.toByteArray(in));
    X509Certificate[] certificates = pkcs7.getCertificates();
    certificateMetas = new ArrayList<>();
    for (X509Certificate certificate : certificates) {
        CertificateMeta certificateMeta = new CertificateMeta();
        certificateMetas.add(certificateMeta);

        byte[] bytes = certificate.getEncoded();
        String certMd5 = md5Digest(bytes);
        String publicKeyString = byteToHexString(bytes);
        String certBase64Md5 = md5Digest(publicKeyString);
        certificateMeta.setData(bytes);
        certificateMeta.setCertBase64Md5(certBase64Md5);
        certificateMeta.setCertMd5(certMd5);
        certificateMeta.setStartDate(certificate.getNotBefore());
        certificateMeta.setEndDate(certificate.getNotAfter());
        certificateMeta.setSignAlgorithm(certificate.getSigAlgName());
        certificateMeta.setSignAlgorithmOID(certificate.getSigAlgOID());
    }
}
 
Example #2
Source File: BCCertificateParserTest.java    From apk-parser with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void parse() throws IOException, CertificateException {
    byte[] data = Inputs.readAllAndClose(getClass().getResourceAsStream("/sign/63_CERT.RSA"));
    CertificateParser parser = new BCCertificateParser(data);
    List<CertificateMeta> certificateMetas = parser.parse();
    assertEquals("SHA1WITHRSA", certificateMetas.get(0).getSignAlgorithm());


    data = Inputs.readAllAndClose(getClass().getResourceAsStream("/sign/gmail_CERT.RSA"));
    parser = new BCCertificateParser(data);
    certificateMetas = parser.parse();
    assertEquals(1, certificateMetas.size());
    CertificateMeta certificateMeta = certificateMetas.get(0);
    assertEquals("MD5WITHRSA", certificateMeta.getSignAlgorithm());
    assertEquals("9decc0608f773ad1f4a017c02598d80c", certificateMeta.getCertBase64Md5());
}
 
Example #3
Source File: Main.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, CertificateException {
    //String apkFile = args[0];
    String apkFile = "C:\\Users\\Administrator.USER-20150319TJ\\Desktop\\test\\锁屏.apk";
    try (ApkParser parser = new ApkParser(apkFile)) {
        parser.setPreferredLocale(Locale.getDefault());
        System.out.println(parser.getApkMeta());
        List<CertificateMeta> certList = parser.getCertificateMetaList();
        for (CertificateMeta certificateMeta : certList) {
            System.out.println(certificateMeta);
        }
    }
}
 
Example #4
Source File: CertificateMetas.java    From apk-parser with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static List<CertificateMeta> from(List<X509Certificate> certificates) throws CertificateEncodingException {
    List<CertificateMeta> certificateMetas = new ArrayList<>(certificates.size());
    for (X509Certificate certificate : certificates) {
        CertificateMeta certificateMeta = CertificateMetas.from(certificate);
        certificateMetas.add(certificateMeta);
    }
    return certificateMetas;
}
 
Example #5
Source File: CertificateMetas.java    From apk-parser with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static CertificateMeta from(X509Certificate certificate) throws CertificateEncodingException {
    byte[] bytes = certificate.getEncoded();
    String certMd5 = md5Digest(bytes);
    String publicKeyString = byteToHexString(bytes);
    String certBase64Md5 = md5Digest(publicKeyString);
    return new CertificateMeta(
            certificate.getSigAlgName().toUpperCase(),
            certificate.getSigAlgOID(),
            certificate.getNotBefore(),
            certificate.getNotAfter(),
            bytes, certBase64Md5, certMd5);
}
 
Example #6
Source File: JSSECertificateParserTest.java    From apk-parser with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
@Ignore
// issue 63
public void parseJDKFailed() throws IOException, CertificateException {
    byte[] data = Inputs.readAllAndClose(getClass().getResourceAsStream("/sign/63_CERT.RSA"));
    CertificateParser parser = new JSSECertificateParser(data);
    List<CertificateMeta> certificateMetas = parser.parse();
    assertEquals("SHA1WITHRSA", certificateMetas.get(0).getSignAlgorithm());
}
 
Example #7
Source File: JSSECertificateParserTest.java    From apk-parser with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void parseJDK() throws IOException, CertificateException {
    byte[] data = Inputs.readAllAndClose(getClass().getResourceAsStream("/sign/gmail_CERT.RSA"));
    CertificateParser parser = new JSSECertificateParser(data);
    List<CertificateMeta> certificateMetas = parser.parse();
    assertEquals(1, certificateMetas.size());
    CertificateMeta certificateMeta = certificateMetas.get(0);
    assertEquals("MD5WITHRSA", certificateMeta.getSignAlgorithm());
    assertEquals("9decc0608f773ad1f4a017c02598d80c", certificateMeta.getCertBase64Md5());
}
 
Example #8
Source File: ApkFileTest.java    From apk-parser with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testGetSignature() throws IOException, CertificateException {
    String path = getClass().getClassLoader().getResource("apks/Twitter_v7.93.2.apk").getPath();
    try (ApkFile apkFile = new ApkFile(path)) {
        List<ApkSigner> apkSingers = apkFile.getApkSingers();
        assertEquals(1, apkSingers.size());
        ApkSigner apkSigner = apkSingers.get(0);
        assertEquals("META-INF/CERT.RSA", apkSigner.getPath());
        List<CertificateMeta> certificateMetas = apkSigner.getCertificateMetas();
        assertEquals(1, certificateMetas.size());
        CertificateMeta certificateMeta = certificateMetas.get(0);
        assertEquals("69ee076cc84f4d94802d61907b07525f", certificateMeta.getCertMd5());
    }
}
 
Example #9
Source File: ByteArrayApkFileTest.java    From apk-parser with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testGetSignature() throws IOException, CertificateException {
    String path = getClass().getClassLoader().getResource("apks/Twitter_v7.93.2.apk").getPath();
    byte[] bytes = Files.readAllBytes(Paths.get(path));
    try (ByteArrayApkFile apkFile = new ByteArrayApkFile(bytes)) {
        List<ApkSigner> apkSingers = apkFile.getApkSingers();
        assertEquals(1, apkSingers.size());
        ApkSigner apkSigner = apkSingers.get(0);
        assertEquals("META-INF/CERT.RSA", apkSigner.getPath());
        List<CertificateMeta> certificateMetas = apkSigner.getCertificateMetas();
        assertEquals(1, certificateMetas.size());
        CertificateMeta certificateMeta = certificateMetas.get(0);
        assertEquals("69ee076cc84f4d94802d61907b07525f", certificateMeta.getCertMd5());
    }
}
 
Example #10
Source File: Signature.java    From unidbg with Apache License 2.0 4 votes vote down vote up
public Signature(VM vm, CertificateMeta meta) {
    super(vm.resolveClass("android/content/pm/Signature"), meta);
}
 
Example #11
Source File: CertificateParser.java    From ApkToolPlus with Apache License 2.0 4 votes vote down vote up
public List<CertificateMeta> getCertificateMetas() {
    return certificateMetas;
}
 
Example #12
Source File: CertificateParser.java    From apk-parser with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * get certificate info
 */
public abstract List<CertificateMeta> parse() throws CertificateException;