Mobile certificate validation and hostname checks
Encryption is useful only when the mobile application verifies the intended server. Understanding mobile certificate validation and hostname checks helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Cryptographic protection depends on the whole operation: the algorithm, its parameters, key handling and the way results are verified. Different mechanisms provide confidentiality, integrity or evidence of origin. Substituting one property for another can leave the important business requirement unprotected.
Such unsafe implementations can allow an attacker to run a MITM attack with a valid (or self-signed) certificate and intercept or tamper with the app's traffic.
The method onReceivedSslError(...) is triggered when a WebView encounters an SSL certificate error while loading a page. By default, the WebView cancels the request to protect users from insecure connections. Overriding this method and calling SslErrorHandler.proceed without proper validation disables these protection.
Why it matters
Consider a realistic failure: a custom trust handler accepts an unrelated certificate and exposes authenticated traffic.
A weakness can undermine trust in stored records or messages even when their appearance does not change. Assessment should connect the defect to the data or action it protects and the capabilities available to an attacker.
Mobile behaviour can change between a fresh installation, an authenticated session, background activity and a device migration. The assessment needs the actual release and representative supported device states.
How penetration testers check for it
Check chain validation, hostnames and error paths across every networking library.
- Using checkServerTrusted(...) which is error prone, when NSC would be enough.
- Using checkValidity instead of full validation: relying only on checkValidity checks whether the certificate is expired or not yet valid, but does not verify trust or hostname matching.
- Misusing getAcceptedIssuers: Returning null or an empty array without proper handling may effectively disable issuer validation.
- Always accepting hostnames: overriding verify(...) to unconditionally return true, regardless of the actual hostname or certificate.
- Trace key generation, access, replacement and verification.
- Test invalid inputs and failure handling with controlled data.
How to fix it
Use platform validation and remove permissive custom certificate handling.
- Use maintained standard implementations and appropriate parameters.
- Protect keys throughout generation, use and retirement.
- Authenticate the content and identity that the operation actually relies on.
- Reject failed verification before trusting or processing the result.
An unusual cryptographic implementation is not enough to establish practical compromise. The report should explain the failed property and a defensible consequence.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- Mobile certificate pinning design and lifecycle risks
- Implementing email address validation and ownership checks
- Building mobile security checks into the development lifecycle
Read about our methodology or contact pentested.com to discuss your mobile applications.