Android network checks

Android certificate pinning: testing and reporting

Pinning restricts which certificates an app accepts for its own servers. It is a defense-in-depth control, so the finding depends on the app's risk and what pinning was meant to stop.

What pinning adds to TLS

Standard TLS validation accepts any certificate that chains to a trusted certificate authority. Pinning narrows that to a specific public key or certificate, so a certificate issued by another authority, including one an attacker convinced the device to trust, is rejected.

Since Android 7.0, apps targeting API level 24 or higher do not trust user-installed CA certificates by default. That already stops most casual interception. Pinning adds protection against mis-issued certificates and compromised authorities. It is reviewed under MASVS-NETWORK.

Where pins are defined

  • Network security configuration: a <pin-set> in the XML referenced by android:networkSecurityConfig, with SHA-256 hashes of the subject public key and an optional expiration date. See the network security configuration guide.
  • OkHttp: a CertificatePinner attached to the client, listing hosts and sha256/ hashes.
  • Custom code: a TrustManager or HostnameVerifier implementation. Review these carefully: an empty checkServerTrusted or a verifier that always returns true disables validation entirely.

A pin set should include a backup key so a certificate rotation does not lock users out. Note when the configured expiration date has passed, because pinning then stops being enforced.

Compute a pin from a server certificate

A pin is the Base64-encoded SHA-256 hash of the certificate's SubjectPublicKeyInfo, not of the whole certificate. That is why a renewed certificate that keeps the same key still matches. To check the pins in an app against a test server you are authorized to contact:

openssl s_client -connect api.example.test:443 -servername api.example.test </dev/null \
  | openssl x509 -pubkey -noout \
  | openssl pkey -pubin -outform der \
  | openssl dgst -sha256 -binary \
  | openssl enc -base64

Compare the output with the <pin> values in the network security configuration or the sha256/ entries in an OkHttp CertificatePinner. If none match the leaf or an intermediate key in the served chain, pinning would fail on that host. If the configuration has a single pin with no backup, record the rotation risk.

Missing pinning vs broken validation

These are different findings and should not share a severity. Missing pinning on an app that uses standard validation is a hardening observation whose importance depends on the risk profile, for example a banking app versus a recipe reader.

Broken validation, such as a trust manager that accepts every certificate or a WebView that proceeds on certificate errors, means any network attacker can read and modify traffic. That is usually a serious finding regardless of whether pinning was ever intended.

Runtime check

On an authorized test device, route traffic through an intercepting proxy. First, without installing its CA, check that the app refuses the connection: success here indicates broken validation. Then install the proxy CA as a trusted certificate on the test device and check whether the app still refuses connections to pinned hosts.

Record which hosts were pinned and which were not; many apps pin their API host but not analytics or CDN hosts. If testing requires bypassing pinning with instrumentation such as Frida, note it: a successful bypass on a rooted test device shows the control is client-side, which is expected, not a separate vulnerability.

Report it with the evidence

Include the configuration or code location, the hosts tested, the device setup (user CA installed or not, rooted or not) and the observed result for each host. Recommend pinning to public keys with a backup, monitoring expiration, and fixing any trust manager or WebView that accepts invalid certificates first.

Use the MASVS checklist to decide whether pinning is required for this app, and the report evidence guide to separate configuration signals from observed traffic.

Related reading