@Test public void testV1SchemeSignatureCertNotReencoded() throws Exception { ApkVerifier.Result result = verify("v1-only-with-rsa-1024-cert-not-der.apk"); if (!result.isVerified()) { List<ApkVerifier.Result.V1SchemeSignerInfo> signers = result.getV1SchemeSigners(); if (signers.size() > 0) { ApkVerifier.Result.V1SchemeSignerInfo signer = signers.get(0); for (IssueWithParams issue : signer.getErrors()) { if (issue.getIssue() == Issue.JAR_SIG_PARSE_EXCEPTION) { CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); if ("SUN".equals(certFactory.getProvider().getName())) { Throwable exception = (Throwable) issue.getParams()[1]; Throwable e = exception; while (e != null) { String msg = e.getMessage(); e = e.getCause(); if ((msg != null) && (msg.contains("Redundant length bytes found"))) { Assume.assumeNoException(exception); } } } break; } } } } assertVerified(result); List<X509Certificate> signingCerts = result.getSignerCertificates(); assertEquals(1, signingCerts.size()); assertEquals( "c5d4535a7e1c8111687a8374b2198da6f5ff8d811a7a25aa99ef060669342fa9", HexEncoding.encode(sha256(signingCerts.get(0).getEncoded()))); }
public Result verify() throws IOException, ApkFormatException, NoSuchAlgorithmException, IllegalStateException { Closeable in = null; try { DataSource apk; if (mApkDataSource != null) { apk = mApkDataSource; } else if (mApkFile != null) { RandomAccessFile f = new RandomAccessFile(mApkFile, "r"); in = f; apk = DataSources.asDataSource(f, 0, f.length()); } else { throw new IllegalStateException("APK not provided"); } return verify(apk); } finally { if (in != null) { in.close(); } } }
ApkVerifier { public Result verify() throws IOException, ApkFormatException, NoSuchAlgorithmException, IllegalStateException { Closeable in = null; try { DataSource apk; if (mApkDataSource != null) { apk = mApkDataSource; } else if (mApkFile != null) { RandomAccessFile f = new RandomAccessFile(mApkFile, "r"); in = f; apk = DataSources.asDataSource(f, 0, f.length()); } else { throw new IllegalStateException("APK not provided"); } return verify(apk); } finally { if (in != null) { in.close(); } } } }
ApkVerifier { public Result verify() throws IOException, ApkFormatException, NoSuchAlgorithmException, IllegalStateException { Closeable in = null; try { DataSource apk; if (mApkDataSource != null) { apk = mApkDataSource; } else if (mApkFile != null) { RandomAccessFile f = new RandomAccessFile(mApkFile, "r"); in = f; apk = DataSources.asDataSource(f, 0, f.length()); } else { throw new IllegalStateException("APK not provided"); } return verify(apk); } finally { if (in != null) { in.close(); } } } private  ApkVerifier(
            File apkFile,
            DataSource apkDataSource,
            Integer minSdkVersion,
            int maxSdkVersion); }
ApkVerifier { public Result verify() throws IOException, ApkFormatException, NoSuchAlgorithmException, IllegalStateException { Closeable in = null; try { DataSource apk; if (mApkDataSource != null) { apk = mApkDataSource; } else if (mApkFile != null) { RandomAccessFile f = new RandomAccessFile(mApkFile, "r"); in = f; apk = DataSources.asDataSource(f, 0, f.length()); } else { throw new IllegalStateException("APK not provided"); } return verify(apk); } finally { if (in != null) { in.close(); } } } private  ApkVerifier(
            File apkFile,
            DataSource apkDataSource,
            Integer minSdkVersion,
            int maxSdkVersion); Result verify(); }
ApkVerifier { public Result verify() throws IOException, ApkFormatException, NoSuchAlgorithmException, IllegalStateException { Closeable in = null; try { DataSource apk; if (mApkDataSource != null) { apk = mApkDataSource; } else if (mApkFile != null) { RandomAccessFile f = new RandomAccessFile(mApkFile, "r"); in = f; apk = DataSources.asDataSource(f, 0, f.length()); } else { throw new IllegalStateException("APK not provided"); } return verify(apk); } finally { if (in != null) { in.close(); } } } private  ApkVerifier(
            File apkFile,
            DataSource apkDataSource,
            Integer minSdkVersion,
            int maxSdkVersion); Result verify();  }