This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate certificate chain by injecting custom provider
This commit is based on PlayIntegrityForkKsBypass by hex3l. Basic idea is to inject a custom KeystoreSpi, overriding generateKeyPair and engineGetCertificateChain method with a software generated keypair. Improvements worth mentioning: 1. Refresh BC provider before building key pair to avoid using old BC shipped with Android. 2. Keep BC class in proguard or R8 will remove ECDSA support in release build. Co-authored-by: Wang Han <[email protected]>
- Loading branch information
Showing
16 changed files
with
659 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
-keep class es.chiteroman.playintegrityfix.EntryPoint {public <methods>;} | ||
-keep class es.chiteroman.playintegrityfix.CustomProvider | ||
-keep class es.chiteroman.playintegrityfix.CustomKeyStoreSpi | ||
-keep class es.chiteroman.playintegrityfix.CustomKeyStoreSpi | ||
-keep class es.chiteroman.playintegrityfix.CustomKeyStoreKeyPairGeneratorSpi$EC | ||
-keep class es.chiteroman.playintegrityfix.CustomKeyStoreKeyPairGeneratorSpi$RSA | ||
|
||
-keep class org.bouncycastle.jcajce.provider.** { *; } | ||
-keep class org.bouncycastle.jce.provider.** { *; } | ||
|
||
-dontwarn javax.naming.** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/src/main/java/es/chiteroman/playintegrityfix/CertUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package es.chiteroman.playintegrityfix; | ||
|
||
import org.bouncycastle.asn1.x500.X500Name; | ||
import org.bouncycastle.cert.X509CertificateHolder; | ||
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; | ||
import org.bouncycastle.openssl.PEMKeyPair; | ||
import org.bouncycastle.openssl.PEMParser; | ||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; | ||
import org.bouncycastle.util.io.pem.PemObject; | ||
import org.bouncycastle.util.io.pem.PemReader; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.security.KeyPair; | ||
import java.security.PrivateKey; | ||
import java.security.cert.Certificate; | ||
|
||
public class CertUtils { | ||
|
||
public static Certificate parseCert(String cert) throws Throwable { | ||
PemObject pemObject; | ||
try (PemReader reader = new PemReader(new StringReader(cert))) { | ||
pemObject = reader.readPemObject(); | ||
} | ||
|
||
X509CertificateHolder holder = new X509CertificateHolder(pemObject.getContent()); | ||
|
||
return (new JcaX509CertificateConverter().getCertificate(holder)); | ||
} | ||
|
||
public static X500Name parseCertSubject(String cert) throws Throwable { | ||
PemObject pemObject; | ||
try (PemReader reader = new PemReader(new StringReader(cert))) { | ||
pemObject = reader.readPemObject(); | ||
} | ||
|
||
X509CertificateHolder holder = new X509CertificateHolder(pemObject.getContent()); | ||
|
||
return holder.getSubject(); | ||
} | ||
|
||
public static KeyPair parseKeyPair(String key) throws Throwable { | ||
Object object; | ||
try (PEMParser parser = new PEMParser(new StringReader(key))) { | ||
object = parser.readObject(); | ||
} | ||
|
||
PEMKeyPair pemKeyPair = (PEMKeyPair) object; | ||
|
||
return new JcaPEMKeyConverter().getKeyPair(pemKeyPair); | ||
} | ||
|
||
public static PrivateKey parsePrivateKey(String keyPair) throws RuntimeException { | ||
try (PEMParser parser = new PEMParser(new StringReader(keyPair))) { | ||
PEMKeyPair pemKeyPair = (PEMKeyPair) parser.readObject(); | ||
return new JcaPEMKeyConverter().getPrivateKey(pemKeyPair.getPrivateKeyInfo()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.