Certificates and keys in mobile apps
Apps ship certificates and keys for TLS pinning, for client-certificate authentication, for
talking to payment or device-attestation services, and sometimes by mistake. The tool reads them, shows
what each certificate is for, and computes the fingerprints and pins that apps compare against. Everything
runs in your browser and nothing is uploaded.
- Android:
res/raw/ and assets/ (.bks, .pem,
.crt, .p12), pins in res/xml/network_security_config.xml or in
code (OkHttp CertificatePinner). META-INF/*.RSA is the APK's own signature (a
PKCS#7 bundle).
- iOS:
.cer / .der / .p12 in the app bundle, pins in
Info.plist (NSPinnedDomains) or in code (TrustKit, Alamofire).
- .NET / React Native / Flutter: often hex or base64 strings in the code. Paste them.
Contents
- Formats
- What a certificate shows
- Fingerprints and pins
- Checking an app's pins
- Keystores and passwords
- Limits
- The X509 library
- The ASN.1 and PEM libraries
2What a certificate shows
- Subject and issuer, the names it covers (SAN), its validity (expired or nearly expired
certificates are flagged), serial number, key (algorithm, size, curve) and signature algorithm. SHA-1 /
MD5 signatures and RSA keys shorter than 2048 bits are flagged.
- Extensions, decoded: basic constraints (is it a CA?), key usage, extended key usage (TLS server,
client, code signing…), key identifiers, CRL and OCSP locations, policies (DV / OV / EV), Certificate
Transparency timestamps.
- Chains: certificates are linked from each leaf to the issuer that signed it (by name and key
identifier), up to a self-signed root or to an issuer that isn't in the files.
- Private keys are identified (format, algorithm, size) but their contents aren't shown. An
unencrypted private key inside an app is called out: anyone with the app has it.
- ASN.1 shows the raw structure, with object identifiers named. PEM / DER download
the item, Copy PEM copies it.
3Fingerprints and pins
| Value |
Of |
Used by |
| SHA-256 / SHA-1 fingerprint |
the whole certificate |
certificate pinning (changes with every renewal), browsers,
openssl x509 -fingerprint |
SPKI pin sha256/… |
the public key (SubjectPublicKeyInfo), base64 |
OkHttp CertificatePinner, Android network_security_config
(<pin digest="SHA-256">), TrustKit, iOS NSPinnedDomains
(SPKI-SHA256-BASE64) |
| SPKI SHA-256 (hex) |
the same, in hex |
libraries that print pins in hex |
| RSA key (GetPublicKeyString) |
the RSA public key itself (PKCS#1), hex |
.NET X509Certificate.GetPublicKeyString(); apps that compare the whole key |
Public-key pins survive certificate renewals as long as the key is kept, which is why most apps pin keys
rather than certificates.
4Checking an app's pins
Paste the pins from the app into Pin check, one per line or as they appear in the code. The tool
picks out sha256/… and sha1/… pins, hex fingerprints (with or without colons), hex
public keys and base64 hashes or keys. Each pin is shown as a match or not, and matching certificates are
marked pinned. To see which server certificates an app accepts, open the server's chain (for example
saved from a browser, or with openssl s_client -showcerts) together with the pins.
5Keystores and passwords
- JKS, JCEKS and BKS store certificates unencrypted, so they're shown without a password. Keys stay
encrypted, so only their names are listed. The password protects an integrity check; when one is
entered it is checked.
- PKCS#12 usually encrypts the certificates too. The tool asks for the password, which is often
in the app's code or resources next to the file. PBES2 with AES (the default in OpenSSL 3 and in Java's
keytool), 3DES and 40- or 128-bit RC2 (OpenSSL 1.x's default) can be read; RC4 can't.
- Keystores are read with the same library as the Keystore tool,
which can also change them.
- The password stays in the page. It isn't stored or sent anywhere.
6Limits
- Signatures aren't verified, and nothing is checked online (no revocation or CT lookups). The chain is
built from names and key identifiers.
- Private keys are never decrypted or displayed here (the Keystore tool can export them).
- PKCS#12 files protected with public-key integrity, and BKS "UBER" keystores, aren't supported.
7The X509 library
lib/x509.js is a JavaScript module with no user interface. It reads certificates, public keys, private keys (it identifies them; it doesn't decrypt them), certificate requests and PKCS#7 bundles, and it creates certificates (a certificate authority and the server certificates it signs). Keystores are read by lib/keystore.js (documented in the Keystore tool guide); the tool uses both. It exports three classes:
import { X509, X509Certificate, CertificateAuthority } from "../lib/x509.js";
const { items, container } = X509.read(fileBytesOrPemText);
for (const item of items.filter((item) => item.kind === "cert")) {
console.log(item.subject.text, item.notAfter, item.publicKey.pin);
}
const certificate = new X509Certificate(derBytes);
X509: reading anything (static methods)
| Method | What it does |
| X509.read(input) | { items, container, notes, pkcs12Der }: everything in bytes (DER, or PEM / hex / Base64 text) or a string. A PKCS#12 file gives no items and its bytes in pkcs12Der, for Keystore.read. |
| X509.identify(der, label) | { description, items, pkcs12, trailing }: what one DER value is, by its structure. |
| X509.publicKeyInfo(bytes, node) | A public key from a SubjectPublicKeyInfo (node: where it is in bytes; the whole of bytes when left out). |
| X509.rsaPublicKey(pkcs1Der) | A public key from a bare PKCS#1 RSAPublicKey (wrapped, so its pin matches the SPKI's). |
| X509.readName(bytes, node), X509.commonName(name) | A distinguished name, and its CN (or O). |
X509Certificate: a certificate
| Method / property | What it does |
| new X509Certificate(der, label) | Reads a certificate; throws when the bytes aren't one. new X509Certificate(bytes, label, node) reads one inside larger DER bytes, at an Asn1.parse node. |
| kind, label, version, serial, signatureAlgorithm | kind is "cert" (like the other items); serial is hex. |
| issuer, subject, title | Names (below); title is the subject's common name. |
| notBefore, notAfter | The validity, as Dates. |
| publicKey, extensions, subjectAltNames | The key (below), every extension, and the alternative names [{ type, value }]. |
| sha256, sha1, der | The fingerprints (bytes) and the certificate itself. |
| selfSigned, ca, subjectKeyId, authorityKeyId | Flags, and the key identifiers as colon-separated hex (or null). |
CertificateAuthority: creating certificates
With WebCrypto: ECDSA P-256 keys and SHA-256 signatures. The MITM Proxy uses it: see its guide.
| Method / property | What it does |
| await CertificateAuthority.create(commonName, { organization, validityDays }) | A new self-signed certificate authority with a new extractable key: Basic Constraints CA and Key Usage keyCertSign, cRLSign (both critical), a Subject Key Identifier; 3650 days by default. |
| new CertificateAuthority({ certificateDer, privateKey, keyId, publicKey, jwk }) | An authority stored earlier, with its key imported again (publicKey and jwk are optional). |
| certificateDer, privateKey, publicKey, jwk, keyId | The certificate, its keys (CryptoKeys; jwk is the private key, to store it) and its key identifier (bytes). |
| await authority.issueServerCertificate(host, leafKeyPair, { validityDays }) | The DER of a server certificate for a host name or IPv4 address, signed by the authority (365 days by default: iOS refuses longer for a user-installed CA). leafKeyPair is an ECDSA P-256 CryptoKeyPair. |
const authority = await CertificateAuthority.create("My test CA", { organization: "Lab" });
const leafKeys = await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]);
const der = await authority.issueServerCertificate("api.example.com", leafKeys);
Items
| kind | Fields |
| cert | an X509Certificate |
| pubkey | publicKey, pkcs1, der |
| privkey | format (PKCS#8, PKCS#1, SEC1, PKCS#8 (encrypted), PEM (encrypted)), algorithm, bits, curve, encrypted, der |
| csr | subject, publicKey, signatureAlgorithm, der |
A name is { parts: [{ type, oid, value }], text, der }. A public key is { algorithm, algorithmOid, key, der, sha256, pin, bits }, plus exponent, modulus, rsaHex for RSA and curve for EC. An extension is { oid, name, critical, text }, plus ca, pathLength (basic constraints), names (alternative names, [{ type, value }]) or keyId (key identifiers).
8The ASN.1 and PEM libraries
lib/asn1.js (no dependencies) reads and writes ASN.1 in DER and BER, the encoding of certificates, keys, PKCS#7, PKCS#12, APK signatures and provisioning profiles. It exports Asn1 (reading) and Der (writing), both classes of static methods:
import { Asn1, Der } from "../lib/asn1.js";
const der = Der.sequence(Der.objectIdentifier("1.2.840.113549.1.1.1"), Der.null());
const node = Asn1.parse(der);
console.log(Asn1.oidName(Asn1.oidOf(der, node.children[0]))); // rsaEncryption
| Method | What it does |
| Asn1.parse(bytes, offset, end) | The element tree: { tag, tagClass, constructed, offset, headerLength, length, end, indefinite, children }. tagClass is 0 universal, 1 application, 2 context-specific, 3 private. BER indefinite lengths are read. |
| Asn1.content(bytes, node), Asn1.encoding(bytes, node) | The content bytes, or the whole element. |
| Asn1.octets(bytes, node) | An OCTET STRING's bytes, joining a constructed (BER) one. |
| Asn1.oid(contentBytes), Asn1.oidOf(bytes, node), Asn1.oidName(oid) | Object identifiers as text, and their names ("rsaEncryption", "CN"…); Asn1.OID_NAMES is the table of names. |
| Asn1.integerHex, integerValue, bitLength (contentBytes) | INTEGERs as hex, as a number, and their size in bits. |
| Asn1.string(bytes, node), Asn1.time(bytes, node) | Any string type as text; UTCTime and GeneralizedTime as a Date. |
| Der.sequence, set, element, context, integer, objectIdentifier, octetString, bitString, null, bmpString, utf8String | DER writing: each returns the bytes of one element, from its parts. |
| Der.boolean(value) | A BOOLEAN (TRUE as 0xff, as DER requires). |
| Der.utcTime(date), generalizedTime(date), time(date) | A time in UTC: YYMMDDHHMMSSZ, YYYYMMDDHHMMSSZ, or the one certificates use for that date (UTCTime before 2050, GeneralizedTime from 2050, RFC 5280). |
| Der.contextPrimitive(number, bytes) | An implicitly tagged [number] primitive value, such as a dNSName [2] in alternative names (context is the constructed form). |
lib/pem.js exports Pem (static methods; it uses lib/base64.js):
import { Pem } from "../lib/pem.js";
const blocks = Pem.decode(text); // [{ label: "CERTIFICATE", bytes, encrypted: false }, …]
| Method | What it does |
| Pem.decode(text) | [{ label, bytes, encrypted }]: every PEM block; text without blocks that is a hex or Base64 dump gives one block labelled hex or base64. |
| Pem.encode(label, bytes) | A PEM block, 64 characters per line. |
| Pem.looksLikeText(bytes) | Whether a file starts as printable text. |
The hashes and ciphers (Sha1, Sha256, Aes…, in lib/crypto/) are listed in the Keystore tool guide.