Skip to content

Commit 33c9feb

Browse files
committed
Add a fallback hook for meta proxygen unpinning
1 parent 4c20195 commit 33c9feb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

android/android-certificate-unpinning-fallback.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Java.perform(function () {
3838
try {
3939
const X509TrustManager = Java.use("javax.net.ssl.X509TrustManager");
4040
const defaultTrustManager = getCustomX509TrustManager(); // Defined in the unpinning script
41+
const certBytes = Java.use("java.lang.String").$new(CERT_PEM).getBytes();
42+
const trustedCACert = buildX509CertificateFromBytes(certBytes); // Ditto
4143

4244
const isX509TrustManager = (cls, methodName) =>
4345
methodName === 'checkServerTrusted' &&
@@ -78,6 +80,12 @@ Java.perform(function () {
7880
return !!matchedChain;
7981
};
8082

83+
const isMetaPinningMethod = (errorMessage, method) =>
84+
method.argumentTypes.length === 1 &&
85+
method.argumentTypes[0].className === 'java.util.List' &&
86+
method.returnType.className === 'void' &&
87+
errorMessage.includes('pinning error');
88+
8189
const matchOkHttpChain = (cls, expectedReturnTypeName) => {
8290
// Find the chain.proceed() method:
8391
const methods = getMethods(cls);
@@ -202,6 +210,23 @@ Java.perform(function () {
202210
callingClass.class.getName()
203211
}`);
204212
}
213+
} else if (isMetaPinningMethod(errorMessage, failingMethod)) {
214+
failingMethod.implementation = function (certs) {
215+
if (DEBUG_MODE) console.log(` => Fallback patch for meta proxygen pinning`);
216+
for (const cert of certs.toArray()) {
217+
if (cert.equals(trustedCACert)) {
218+
return; // Our own cert - all good
219+
}
220+
}
221+
222+
if (DEBUG_MODE) {
223+
console.warn(' Meta unpinning fallback found only untrusted certificates');
224+
}
225+
// Fall back to normal logic, in case of passthrough or similar
226+
return failingMethod.call(this, certs);
227+
}
228+
229+
console.log(` [+] ${className}->${methodName} (Meta proxygen pinning fallback patch)`);
205230
} else {
206231
console.error(' [ ] Unrecognized TLS error - this must be patched manually');
207232
return;

0 commit comments

Comments
 (0)