Android/iOS中证书固定与信任存储的核心差异及实现疑问
First: Why Android Has a "TrustStore" and iOS Feels Like It Doesn’t
Android explicitly exposes the concept of a TrustStore because it lets apps choose between using the system-wide trust store (which includes pre-installed root CAs) or a custom app-specific TrustStore (where you can add only the CAs/certificates your app trusts). This gives developers granular control at the app level.
iOS, on the other hand, doesn’t use the term "TrustStore"—but it absolutely has a trust system, built around the system Keychain and its default trust policy. By default, iOS apps trust all root CAs pre-installed by Apple. Unlike Android, iOS doesn’t let you easily replace the entire trust store for an app; instead, you customize trust via:
- App Transport Security (ATS) settings
- Custom
NSURLSession/URLSessiondelegate methods to validate certificates manually (which is how you implement pinning on iOS)
So the difference is in terminology and how the platform exposes trust configuration, not the existence of a trust store itself.
Core Differences Between Certificate Pinning and Trust Stores
Your observation about verification targets (full certificates vs SHA256 public keys) is part of it, but there are much deeper, more impactful differences:
1. Trust Model Foundation
- TrustStores: Operate on a CA-based trust model. They trust certificates that chain back to a trusted root CA (either system-wide or custom). The trust is delegated to third-party CAs—if a CA is compromised and issues a fake certificate for your domain, the TrustStore will still accept it.
- Certificate Pinning: Operates on a direct trust model. You predefine exactly which certificates or public keys your app will accept, completely bypassing the CA chain. Trust is not delegated to anyone; your app only trusts the entities you explicitly specify.
2. Verification Scope
- TrustStores: Validate the entire certificate chain. This includes checking that each certificate in the chain is signed by the one above it, that none are expired, and that the root is trusted.
- Certificate Pinning: Skips chain validation (or augments it) to only check that the server’s certificate/public key matches one of your pinned values. You don’t care about the CA—you only care that the server presents a key you already know and trust.
3. Flexibility & Maintenance
- TrustStores: Low maintenance once configured. As long as your server’s certificate is issued by a trusted CA and renewed properly, you don’t need to update your app.
- Certificate Pinning: High maintenance. You need to:
- Pre-pin multiple keys (like you’re doing with HPKP) to handle key rotation
- Update your app if you need to change the pinned keys (unless using a dynamic pinning mechanism)
- Handle edge cases like expired pins or emergency key rotations
4. Security Goals
- TrustStores: Protect against unknown untrusted certificates. They block certificates that don’t come from a trusted source, but can’t defend against CA compromises or maliciously issued certificates.
- Certificate Pinning: Protect against known trusted entities being impersonated. It’s specifically designed to stop man-in-the-middle attacks where a compromised CA issues a fake certificate for your domain.
To Sum Up
The difference isn’t just about what you verify (full certificates vs public keys)—it’s about the entire trust model: TrustStores rely on third-party CAs, while pinning puts control directly in your app’s hands. And regarding Android vs iOS, it’s just a difference in how each platform exposes their trust configuration, not the absence of a trust system on iOS.
内容的提问来源于stack exchange,提问作者BennX

