Skip to main content

How to extract certificates and private keys from iOS Keychain

Illustration of How to extract certificates and private keys from iOS Keychain
Marcin Zięba

Introduction: What is the iOS Keychain?

The iOS Keychain is Apple’s secure storage mechanism designed to keep sensitive information safe, such as passwords, encryption keys, and certificates. Unlike application-level storage, the Keychain benefits from hardware-backed protection provided by the Secure Enclave and the system’s sandboxing model. This makes it the preferred method for iOS applications to store critical credentials that must persist between launches while remaining inaccessible to other apps.

From a security assessment perspective, understanding how client certificates and private keys are stored in the Keychain is crucial, particularly since these assets often play a key role in authentication flows with backend services. Mismanagement or insufficient protections - especially regarding the application’s resilience - can provide attackers with opportunities on compromised devices.

Authentication in iOS Apps: X.509 Client Certificates

Many modern iOS applications implement mutual TLS (mTLS) authentication as part of their security design. In this model, the client must not only validate the server’s certificate but also present an X.509 certificate and the associated private key to prove its identity.

Some of them may not fully utilize mTLS and implement only access control based on user’s identity backed by a client certificate.

The client certificate and key are typically stored in the Keychain and accessed by the app whenever a secure session is initiated. If an attacker is able to extract these credentials, they could impersonate a legitimate client, bypassing standard authentication mechanisms.

How such information can be extracted?

After fulfilling the initial requirements (jailbreak detection and instrumentation prevention), intercepting the application’s traffic through an HTTP proxy may result in additional errors, such as the one shown for the request below:

Proxy error

The server’s response displays an error related to the certificate because HTTP proxies are not capable of forwarding certificates:

Certificate error

In order to retrieve the certificate, the Objection framework can be used:

Objection framework

Below there is a dumped keychain file. Certificate is marked yellow and corresponding private key – red:

Keychain dump

Next, the obtained data must be processed into a format that allows generating a PKCS #12 archive:

PKCS processing

After that action archive can be loaded in the Burp Suite:

Burp Suite loading

Now, initial request can be resent:

Request resend

The server’s response indicates that the operation was successful:

Success response

Conclusions and Defensives

While the Keychain provides robust protection under normal conditions, it remains vulnerable in certain scenarios - particularly on jailbroken devices.

To mitigate the risk of unauthorized access to certificates or private keys, application developers and security teams should rely on 3 most crucial things:

  1. Strong implementation jailbreak detection - Disallow running the app on jailbroken iOS devices, or in case where application utilizes certificates degrade app functionality when such dangerous environment is detected.

  2. Secure runtime - Harden the application against runtime tampering attempts by blocking dylib injection or monitoring runtime integrity.

  3. Apply code obfuscation and anti-tampering measures - Make it harder for attackers to reverse engineer or modify the app.

By combining these defensive strategies, organizations can significantly reduce the risk of private key compromise and unauthorized certificate extraction from the iOS Keychain.

Other Insights

Illustration of Zero Auth to Admin: Exploiting Known Vulnerabilites in Real World Pen Tetsts

Zero Auth to Admin: Exploiting Known Vulnerabilites in Real World Pen Tetsts

Krystian Działowy

During an internal penetration test, I identified an unpatched MikroTik RouterOS device vulnerable to CVE-2018-14847. By exploiting this flaw in the Winbox service, I was able to extract administrator credentials without authentication and subsequently gained full read/write access via FTP and Winbox GUI. This vulnerability is particularly dangerous due to its low complexity and high impact - it allows complete device takeover with just network access to the Winbox service.

READ article
Illustration of Filter Injection via Microsoft Graph API in a Custom Application: From Verbose Errors to Account Takeover

Filter Injection via Microsoft Graph API in a Custom Application: From Verbose Errors to Account Takeover

Grzegorz Bronka

During a recent security assessment, it was identified that a client web application integrating Microsoft Entra through the Microsoft Graph API was vulnerable to a novel form of filter injection. This flaw originated in the password reset functionality, where user-supplied input was incorporated directly into Graph API queries without adequate sanitization or validation. Exploiting this weakness allowed bypassing password reset token validation, ultimately enabling unauthorized password resets for arbitrary user accounts. This article details the discovery process and demonstrates practical payloads used to exploit the issue.

READ article
A professional cybersecurity consultant ready to assist with your inquiry.

Any questions?

Happy to get a call or email
and help!