SSL Pinning and Bypasses

Null Meet Bangalore

21 November 2015

Slides

Abstract

This talk will focus on following items

Both implementation and Bypass will be covered in the session.

AI Generated Summary

AI Generated Content Disclaimer

Note: This summary is AI-generated and may contain inaccuracies, errors, or omissions. If you spot any issues, please contact the site owner for corrections. Errors or omissions are unintended.

This presentation, SSL Pinning and Bypasses (Android and iOS), covers implementing and defeating certificate pinning on both mobile platforms. The session explains why the existing PKI model fails, how pinning adds a layer of protection against man-in-the-middle attacks, demonstrates pinning with OkHttp on Android and SwiftHTTP or TrustKit on iOS, and then bypasses both implementations using Xposed with JustTrustMe on Android and SSL Kill Switch 2 on iOS.

Summary

The deck opens with how man-in-the-middle interception actually works: the attacker adds the root CA of an interception proxy to the device trust store, diverts traffic through that proxy, and the browser accepts the proxy’s certificate because its CA is trusted, giving full visibility of the traffic. This was framed as a symptom of broken PKI: the system trusts every CA in the trust store, including attacker-controlled ones like the PortSwigger CA, it validates root CAs rather than the full certification chain, and any CA can issue a certificate for any website, as the Diginotar, Trustwave and NIC incidents showed. Stolen certificates drop operators into revocation problems with CRLs, and OCSP, which itself runs over port 80, is the attempted rescue. The answer was to pin trust on the application’s own certification chain and validate it at the client side, so the application trusts only specific certificates or public keys instead of anything issued by any trusted CA.

On Android the deck showed implementation options: storing the certificate in SQLite for direct comparison, storing SHA1 hashes to compare, or storing the SHA1 hash of one element in the chain. The demo used OkHttp by Square, which pins SHA1 hashes of the entire chain or a set of elements in it. The bypass used the Xposed Framework, which hooks function calls at runtime: whenever a request is made for the check function inside com.squareup.okhttp.CertificatePinner, the hook forces it to return true. The JustTrustMe module implements this bypass.

On iOS, pinning was demonstrated with third-party helpers SwiftHTTP and TrustKit, or directly via SecTrustEvaluate through NSURLConnectionDelegate, with the helpers essentially wrapping the native Secure Transport API calls. The bypass used the original ios-ssl-kill-switch by iSEC Partners and its successor ssl-kill-switch2 by nabla-c0d3, which works on iOS 9.0.2 and does not affect iTunes or the App Store by default. These tools leverage Cydia Substrate, inject into processes through MobileSubstrate, and hook the Secure Transport API instead of higher-level APIs such as SecTrustEvaluate or NSURL, because that API is the lowest-level TLS implementation on iOS. Three patches are applied: SSLCreateContext is patched to disable built-in certificate validation in all SSL contexts, SSLSetSessionOption is patched to remove the ability to re-enable validation, and SSLHandshake is patched to force trust-all custom certificate validation.

The close covered the trade-offs: whenever the certificate changes, whether through a new provider, a chain change, revocation or theft, the application code must be updated, which is manageable because mobile apps can push updates but adds maintenance overhead. The payoff is that without rooting or jailbreaking the device, pinning is nearly impossible to bypass, which is why developers get another layer against traffic interception while pentesters need to be ready for the bypass techniques.

Key Themes

Notable Points

  1. Mobile applications handling sensitive data should implement SSL certificate pinning, which adds a defense layer that prevents MITM interception unless the device is rooted or jailbroken.
  2. On Android, OkHttp’s CertificatePinner can pin SHA1 hashes of the certificate chain, and backup pins should be included to plan for certificate rotation.
  3. On iOS, TrustKit or SwiftHTTP simplify pinning, while direct implementation via SecTrustEvaluate through NSURLConnectionDelegate gives maximum control.
  4. When testing pinned Android apps, the Xposed Framework with the JustTrustMe module bypasses OkHttp and other common pinning implementations.
  5. For iOS penetration testing, ssl-kill-switch2, the successor to ios-ssl-kill-switch, hooks at the Secure Transport API level, the lowest-level TLS implementation on iOS, to bypass higher-level pinning implementations.
  6. SSL pinning requires application updates whenever certificates change, so a pinning strategy should include backup pins and planned rotation to avoid breaking the application when certificates are renewed or replaced.

Notable Quotes

“Another layer to achieve secure communication specially protection against MiTM”

“System Trust all CA in Trust Store (PortSwigger CA)”

“Certificate Stolen: Welcome to Revocation hell and CRL Nightmare”

“OCSP to the rescue over port 80”

“Pin Trust on our own certification chain and validate it at Client Side”

“You need to update the code everytime certificate changes”

Social chatter