← Certificates
Cert·Format guide
All tools

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.

Contents

  1. Formats
  2. What a certificate shows
  3. Fingerprints and pins
  4. Checking an app's pins
  5. Keystores and passwords
  6. Limits
  7. The X509 library
  8. The ASN.1 and PEM libraries

1Formats

Format Files Read
PEM (base64 text between -----BEGIN …----- lines) .pem .crt .cer .key every block: certificates, public keys, private keys, requests
DER (binary ASN.1) .der .cer .crt X.509 certificates, SubjectPublicKeyInfo, PKCS#1 RSA keys, PKCS#8 and SEC1 private keys, PKCS#10 requests
Hex or base64 dumps pasted text any of the above, e.g. X509Certificate.GetPublicKeyString() values
PKCS#7 bundles .p7b .p7c META-INF/*.RSA the certificates
PKCS#12 .p12 .pfx certificates and key entries; encrypted parts with the password
Java keystores .jks .keystore (JKS, JCEKS) certificates (they aren't encrypted) and the names of key entries
Bouncy Castle keystores .bks (v1, v2) certificates and the names of key entries. This is the classic Android truststore format.

You can open several files at once; a certificate found in more than one of them is shown once, with every alias it has.

2What a certificate shows

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

6Limits

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)

MethodWhat 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 / propertyWhat 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, signatureAlgorithmkind is "cert" (like the other items); serial is hex.
issuer, subject, titleNames (below); title is the subject's common name.
notBefore, notAfterThe validity, as Dates.
publicKey, extensions, subjectAltNamesThe key (below), every extension, and the alternative names [{ type, value }].
sha256, sha1, derThe fingerprints (bytes) and the certificate itself.
selfSigned, ca, subjectKeyId, authorityKeyIdFlags, 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 / propertyWhat 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, keyIdThe 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

kindFields
certan X509Certificate
pubkeypublicKey, pkcs1, der
privkeyformat (PKCS#8, PKCS#1, SEC1, PKCS#8 (encrypted), PEM (encrypted)), algorithm, bits, curve, encrypted, der
csrsubject, 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
MethodWhat 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, utf8StringDER 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 }, …]
MethodWhat 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.