Skip to content

Commit

Permalink
Support SNI tricks for Android 9+
Browse files Browse the repository at this point in the history
  • Loading branch information
krlvm committed Jul 1, 2020
1 parent 2a56bbe commit d965064
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@
*/
package org.littleshoot.proxy.mitm;

import android.os.Build;

import org.bouncycastle.asn1.ASN1EncodableVector;
import org.bouncycastle.asn1.ASN1InputStream;
import org.bouncycastle.asn1.ASN1Sequence;
Expand Down Expand Up @@ -461,10 +463,19 @@ private static X509Certificate signCertificate(
X509v3CertificateBuilder certificateBuilder,
PrivateKey signedWithPrivateKey) throws OperatorCreationException,
CertificateException {
ContentSigner signer = new JcaContentSignerBuilder(SIGNATURE_ALGORITHM)
.setProvider(PROVIDER_NAME).build(signedWithPrivateKey);
return new JcaX509CertificateConverter().setProvider(
PROVIDER_NAME).getCertificate(certificateBuilder.build(signer));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ContentSigner signer = new JcaContentSignerBuilder(SIGNATURE_ALGORITHM)
.build(signedWithPrivateKey);
return new JcaX509CertificateConverter()
.getCertificate(certificateBuilder.build(signer));
} else {
ContentSigner signer = new JcaContentSignerBuilder(SIGNATURE_ALGORITHM)
.setProvider(PROVIDER_NAME)
.build(signedWithPrivateKey);
return new JcaX509CertificateConverter()
.setProvider(PROVIDER_NAME)
.getCertificate(certificateBuilder.build(signer));
}
}

public static TrustManager[] getTrustManagers(KeyStore keyStore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public CertificateSniffingMitmManager(Authority authority)
sslEngineSource = new BouncyCastleSslEngineSource(authority, true,
true);
} catch (final Exception e) {
e.printStackTrace();
throw new RootCertificateException(
"Errors during assembling root CA.", e);
}
Expand Down

0 comments on commit d965064

Please sign in to comment.