Skip to content

Commit

Permalink
Handle the signature of built-in okhttp.Address in Android Nougat
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Nov 7, 2023
1 parent 05d9b8a commit 676627d
Showing 1 changed file with 52 additions and 5 deletions.
57 changes: 52 additions & 5 deletions android/android-certificate-unpinning.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,66 @@ const PINNING_FIXES = {
'com.android.okhttp.Address': [
{
methodName: '$init',
overload: [
'java.lang.String',
'int',
'com.android.okhttp.Dns',
'javax.net.SocketFactory',
'javax.net.ssl.SSLSocketFactory',
'javax.net.ssl.HostnameVerifier',
'com.android.okhttp.CertificatePinner',
'com.android.okhttp.Authenticator',
'java.net.Proxy',
'java.util.List',
'java.util.List',
'java.net.ProxySelector'
],
replacement: () => {
const OkHostnameVerifier = Java.use("com.android.okhttp.internal.tls.OkHostnameVerifier");
const defaultHostnameVerifier = OkHostnameVerifier.INSTANCE.value;

const CertPinner = Java.use("com.android.okhttp.CertificatePinner");
const defaultCertPinner = CertPinner.DEFAULT.value;
const defaultHostnameVerifier = Java.use("com.android.okhttp.internal.tls.OkHostnameVerifier")
.INSTANCE.value;
const defaultCertPinner = Java.use("com.android.okhttp.CertificatePinner")
.DEFAULT.value;

return function () {
// Override arguments, to swap any custom check params (widely used
// to add stricter rules to TLS verification) with the defaults instead:
arguments[5] = defaultHostnameVerifier;
arguments[6] = defaultCertPinner;

this.$init(...arguments);
}
}
},
// Almost identical patch, but for Nougat and older. In these versions, the DNS argument
// isn't passed here, so the arguments to patch changes slightly:
{
methodName: '$init',
overload: [
'java.lang.String',
'int',
// No DNS param
'javax.net.SocketFactory',
'javax.net.ssl.SSLSocketFactory',
'javax.net.ssl.HostnameVerifier',
'com.android.okhttp.CertificatePinner',
'com.android.okhttp.Authenticator',
'java.net.Proxy',
'java.util.List',
'java.util.List',
'java.net.ProxySelector'
],
replacement: () => {
const defaultHostnameVerifier = Java.use("com.android.okhttp.internal.tls.OkHostnameVerifier")
.INSTANCE.value;
const defaultCertPinner = Java.use("com.android.okhttp.CertificatePinner")
.DEFAULT.value;

return function () {
// Override arguments, to swap any custom check params (widely used
// to add stricter rules to TLS verification) with the defaults instead:
arguments[4] = defaultHostnameVerifier;
arguments[5] = defaultCertPinner;

this.$init(...arguments);
}
}
Expand Down

0 comments on commit 676627d

Please sign in to comment.