Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
JSSE and BC CertificateParser
Browse files Browse the repository at this point in the history
  • Loading branch information
hsiafan committed Jan 18, 2018
1 parent 9431415 commit 54a8042
Show file tree
Hide file tree
Showing 41 changed files with 2,944 additions and 51 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ try(ApkFile apkFile = new ApkFile(new File(filePath))) {
}
```

##### 4. Get certificate and verify apk signature
##### 4. Get Apk Sign info

To get apk signer certificate info and other messages, using:

```java
try(ApkFile apkFile = new ApkFile(new File(filePath))) {
ApkSignStatus signStatus = apkFile.verifyApk();
List<CertificateMeta> certs = apkFile.getCertificateMetas();
for (CertificateMeta certificateMeta : certs) {
System.out.println(certificateMeta.getSignAlgorithm());
}
List<ApkSigner> signers = apkFile.getApkSingers(); // apk v1 signers
List<ApkV2Signer> v2signers = apkFile.getApkV2Singers(); // apk v2 signers
}
```

Expand Down
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.58</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.58</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/net/dongliu/apk/parser/AbstractApkFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public List<ApkSigner> getApkSingers() throws IOException, CertificateException
private void parseCertificates() throws IOException, CertificateException {
this.apkSigners = new ArrayList<>();
for (CertificateFile file : getAllCertificateData()) {
CertificateParser parser = new CertificateParser(file.getData());
CertificateParser parser = CertificateParser.getInstance(file.getData());
List<CertificateMeta> certificateMetas = parser.parse();
apkSigners.add(new ApkSigner(file.getPath(), certificateMetas));
}
Expand Down Expand Up @@ -339,9 +339,11 @@ private void parseResourceTable() throws IOException {
}

/**
* Check apk sign.
* TODO:Now only use jar-sign, apk-signing v2 not supported
* Check apk sign. This method only use apk v1 scheme verifier
*
* @deprecated using google official ApkVerifier of apksig lib instead.
*/
@Deprecated
public abstract ApkSignStatus verifyApk() throws IOException;

@Override
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/net/dongliu/apk/parser/ApkFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ protected ByteBuffer fileData() throws IOException {
}


/**
* {@inheritDoc}
*
* @deprecated using google official ApkVerifier of apksig lib instead.
*/
@Override
@Deprecated
public ApkSignStatus verifyApk() throws IOException {
ZipEntry entry = zf.getEntry("META-INF/MANIFEST.MF");
if (entry == null) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/dongliu/apk/parser/ApkParsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
*/
public class ApkParsers {

private static boolean useBouncyCastle;

public static boolean useBouncyCastle() {
return useBouncyCastle;
}

/**
* Use BouncyCastle instead of JSSE to parse X509 certificate.
* If want to use BouncyCastle, you will also need to add bcprov and bcpkix lib to your project.
*/
public static void useBouncyCastle(boolean useBouncyCastle) {
ApkParsers.useBouncyCastle = useBouncyCastle;
}

/**
* Get apk meta info for apk file
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/dongliu/apk/parser/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class Main {
public static void main(String[] args) throws IOException, CertificateException {
try (ApkFile apkFile = new ApkFile(args[0])) {
System.out.println(apkFile.getApkV2Singers().get(0).getCertificateMetas());
System.out.println(apkFile.getApkSingers().get(0).getCertificateMetas());
}
}
}
Loading

0 comments on commit 54a8042

Please sign in to comment.