<!-- Generated by website/scripts/sync-docs.mjs from docs/guide/usage.md. Edit that file, not this one. -->

# Usage

> Every page of this site: https://dyokto.github.io/y509/docs/llms.txt

```bash
y509 cert-chain.pem                       # a file (PEM, DER or PKCS#7)
y509 example.com:443                      # a live server
y509 smtp.example.com:587 --starttls smtp # ...behind STARTTLS
cat chain.pem | y509                      # stdin
kubectl get secret tls -o json | y509     # a Kubernetes TLS secret
```

PKCS#7 (`.p7b`, `.p7c`), PKCS#12 (`.p12`, `.pfx`) and Kubernetes TLS secrets are detected by content, so pipes work too. A secret is read from `tls.crt`, then `ca.crt`.

PKCS#12 is tried without a password first. If one is needed, it comes from `Y509_PKCS12_PASSWORD`, `--password-file`, or a prompt. Never a flag, since flags show up in `ps`. Private keys are ignored.

## Live servers

```bash
y509 example.com:443
y509 --connect 10.0.0.1:8443 --servername api.internal
y509 db.example.com:5432 --starttls postgres
y509 ldap.example.com:389 --starttls ldap
y509 db.example.com:3306 --starttls mysql
```

An existing file path is read as a file; anything else is an address. `--connect` forces an address. `--starttls` supports `smtp`, `lmtp`, `imap`, `nntp`, `ftp`, `ldap`, `mysql` and `postgres` (aliases: `mariadb`, `postgresql`).

The TUI handshake verifies nothing on purpose, so you can inspect a broken chain. Certificates are shown **in the order the server sent them**.

## Comparing two chains

```bash
y509 diff before.pem after.pem
y509 diff node1.example.com:443 node2.example.com:443
```

```text
Chain differences:
  - leaf.example.com
  + leaf.example.com
    Example Intermediate CA

The leaf was replaced:
  • serial: 8149... -> 9e2c...
  • not after: 2026-09-30 -> 2026-12-29
  • dns names: example.com -> example.com, www.example.com
```

Certificates are matched by SHA-256 of their DER, not by subject, since a renewal keeps the name. Exit 0 if identical, 1 if different, like `diff(1)`. Useful for spotting a rotation, or two CDN nodes serving different chains.

## Taking an inventory

`inventory` lists what you have, without verifying anything. It exits 0 for anything it could read:

```bash
y509 inventory www.example.com:443 api.example.com:443
y509 inventory chain.pem --csv > inventory.csv
```

```text
TARGET                   SUBJECT           KEY        SIGNATURE            EXPIRES     DAYS
www.example.com:443      www.example.com   ECDSA 256  ECDSA-SHA256         2026-11-02  49
www.example.com:443      R11               RSA 2048   SHA256-RSA           2027-03-12  179
```

Good for PCI DSS 4.0.1 inventories or finding RSA keys ahead of a post-quantum migration. `--json` adds fingerprints and lifetimes.
