Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Trustwave and Cybereason Merge to Form Global MDR Powerhouse for Unparalleled Cybersecurity Value. Learn More

Services
Managed Detection & Response

Eliminate active threats with 24/7 threat detection, investigation, and response.

Co-Managed SOC (SIEM)

Maximize your SIEM investment, stop alert fatigue, and enhance your team with hybrid security operations support.

Advisory & Diagnostics

Advance your cybersecurity program and get expert guidance where you need it most.

Penetration Testing

Test your physical locations and IT infrastructure to shore up weaknesses before exploitation.

Database Security

Prevent unauthorized access and exceed compliance requirements.

Email Security

Stop email threats others miss and secure your organization against the #1 ransomware attack vector.

Digital Forensics & Incident Response

Prepare for the inevitable with 24/7 global breach response in-region and available on-site.

Firewall & Technology Management

Mitigate risk of a cyberattack with 24/7 incident and health monitoring and the latest threat intelligence.

Solutions
BY TOPIC
Microsoft Security
Unlock the full power of Microsoft Security
Offensive Security
Solutions to maximize your security ROI
Rapidly Secure New Environments
Security for rapid response situations
Securing the Cloud
Safely navigate and stay protected
Securing the IoT Landscape
Test, monitor and secure network objects
Why Trustwave
About Us
Awards and Accolades
Trustwave SpiderLabs Team
Trustwave Fusion Security Operations Platform
Trustwave Security Colony
Partners
Technology Alliance Partners
Key alliances who align and support our ecosystem of security offerings
Trustwave PartnerOne Program
Join forces with Trustwave to protect against the most advance cybersecurity threats

Regression Workaround for TWSL2011-007: The iOS SSL Validation Vulnerability (UPDATED)

Trustwave SpiderLabs recently released an advisory (TWSL2011-007) regarding improper x509 certificate chain validation on Apple iOS. The vulnerability (reserved as CVE-2011-0228 at the time of writing) was discovered and reported to Apple by our own Paul Kehrer. Also attributed for independently discovering and reporting the vulnerability was Gregor Kopf of Recurity Labs.

The vulnerability is also actually essentially the same as one found in IE back in 2002 by moxie, author of SSLSniff.

The iOS vulnerability has been confirmed on pretty much all iOS versions up to and including 4.3.4 and 4.2.9(CDMA). Apple released patches to iOS shortly before the Trustwave Advisory was released as iOS firmware updates (versions 4.3.5 and 4.2.10(CDMA) respectively).

While we definitely encourage all users to upgrade their iOS versions as soon as possible, the world isn't a perfect place. Developers of security sensitive mobile applications who rely on SSL for secure communications and x509 trust verification are left in a difficult position with potentially serious implications.

Say you're an application developer for iOS for something such as a mobile banking or payment-processing application. You are faced with a choice, either force all users to upgrade iOS, or, if possible identify a code workaround that you can implement in your own application for earlier iOS versions. Then, release an update to your own application and require them to at least apply that.

With this in mind, we have been looking into possible code workarounds to address the certificate validation vulnerability for individual applications. After some trial and error, we found that by using the Apple Secure Trust API directly to validate your own certificates, and by configuring certain features, you can properly detect and reject invalid certificates designed to exploit this bug.

One goal of the implementation was to stick to core Apple API's as much as possible, whilst still using only the ones supported for approval in the app store. This workaround uses the Secure Trust API to establish a SSL validation policy, requiring validation of the FQDN of the leaf certificate in the chain. The leaf certificate represents the last certificate in the chain, or the certificate signed for the site is configured for. The routine is called with a leaf name and a reference to the leaf certificate and it returns true if the certificate is validated, and false otherwise.

  #import <CoreFoundation/CoreFoundation.h>  #import <Security/Security.h>    bool isCertValid(CFStringRef leafName, SecCertificateRef leafCert) {    bool ret=false;    SecTrustRef trust;    SecTrustResultType res;        SecPolicyRef policy = SecPolicyCreateSSL(true, leafName);    OSStatus status = SecTrustCreateWithCertificates((void *)leafCert, policy, &trust);        if ((status == noErr) &&        (SecTrustEvaluate(trust, &res) == errSecSuccess) &&         ((res == kSecTrustResultProceed) || (res == kSecTrustResultUnspecified)))     { ret = true; }        if (trust) CFRelease(trust);    if (policy) CFRelease(policy);         return ret;  }

Note, you can technically pass a null leafName to this implementation, but don't, or the workaround will not validate the certificate properly.

UPDATE 8/10/2011 (thanks to Adam Goodman of DuoSecurity): The above workaround is not designed to work with intermediate certificates. Only pass the leaf certificate in as the leafCert parameter, without any additional intermediate certificates. If you use intermediate certificates
for validation, you will need something much more robust than the simple workaround we have supplied above. See the comments at the end of this blog as well as Adam's Blog Post for more information.

We've put a command-line version of the implementation up on github as a reference. The command-line utility takes as its arguments a leaf name and a certificate filename (the file should be in raw DER format, which is just the bas64-decoded data of the public-key in a PEM).

We have also confirmed this works in conjunction with the commonly used CFNetwork API as well by accessing and validating the certificate on the network stream after the API's own built-in SSL handshake is complete. We may post up a CFNetwork reference implementation too in the near future, so keep an eye on the github project.

ABOUT TRUSTWAVE

Trustwave is a globally recognized cybersecurity leader that reduces cyber risk and fortifies organizations against disruptive and damaging cyber threats. Our comprehensive offensive and defensive cybersecurity portfolio detects what others cannot, responds with greater speed and effectiveness, optimizes client investment, and improves security resilience. Learn more about us.

Latest Intelligence

Discover how our specialists can tailor a security program to fit the needs of
your organization.

Request a Demo