3.1 KiB
3.1 KiB
Keys, API keys and key pairs
What custos-gen and custos-keys generate besides passwords. All randomness comes from the OS CSPRNG.
Secret keys (custos_gen::secret_key)
16 ..= 128 random bytes (default 32 = 256 bits), written as lowercase hex, base64url without padding, or standard base64 with padding. For symmetric keys, HMAC and JWT secrets, encryption passphrases for tools.
API keys (custos_gen::api_key)
<prefix>_<32 base62 characters><6 base62 characters of checksum> e.g. domi_7Kq…Zx41aP0c
prefix: empty, or a lowercase letter then up to 15 lowercase letters or digits. It says what the key is for at a glance, and lets leak scanners find it. No prefix: the key starts with the 32 characters.- 32 base62 characters: 190.5 bits, each character uniform (rejection sampling, no modulo bias).
- The checksum is CRC-32 (IEEE) of everything before it, in base62, padded to 6 characters. It catches typos and lets a scanner tell a real key from random text. It is not a security feature.
Key pairs (custos_keys::generate)
| Algorithm | Name in the item | Notes |
|---|---|---|
| Ed25519 | ed25519 |
the default: SSH, signing, minisign-style tools |
| ECDSA P-256 | ecdsa-p256 |
where Ed25519 is not accepted (some cloud KMS, older hardware) |
| RSA 3072 / 4096 | rsa-3072, rsa-4096 |
for systems that accept nothing else; generation takes seconds |
Each gives:
public-key: the OpenSSH public line (ssh-ed25519 AAAA… comment), forauthorized_keys;public-pem: the SubjectPublicKeyInfo PEM;private-key*: the PKCS#8 PEM (unencrypted; the vault is its encryption);private-openssh*: the OpenSSH private key (unencrypted, same reason), forssh -i;fingerprint:SHA256:…, exactly asssh-keygen -lprints it.
The crates are RustCrypto's: ssh-key, ed25519-dalek (its Ed25519 backend), p256, rsa.
Importing (custos_keys::import)
An existing private key becomes the same kind of item. Accepted formats:
| Input | Header | Algorithms |
|---|---|---|
| OpenSSH private key | BEGIN OPENSSH PRIVATE KEY |
Ed25519, ECDSA P-256, RSA |
| PKCS#8 | BEGIN PRIVATE KEY |
Ed25519, ECDSA P-256, RSA |
| PKCS#1 | BEGIN RSA PRIVATE KEY |
RSA |
| SEC1 | BEGIN EC PRIVATE KEY |
ECDSA P-256 |
- The public line, the PEMs and the fingerprint are derived from the private key, never copied from the input. A pasted public key therefore cannot disagree with its private key.
- RSA: 2048 to 4096 bits. An imported 2048-bit key is named
rsa-2048; Custos never generates one. - A passphrase-protected key is refused (
Encrypted): OpenSSH with a cipher,ENCRYPTED PRIVATE KEY, or PKCS#1 withProc-Type: 4,ENCRYPTED. Remove the passphrase first (ssh-keygen -p); the vault is the key's encryption. - Comment: an OpenSSH key keeps its own comment; the other formats take the item's name.
- Line ends: CRLF and surrounding whitespace are accepted, as in a paste or a Windows file.
- Errors never repeat the input.
- ssh-key 0.6.7 conversion bug: its
TryFrom<&RsaKeypair> for rsa::RsaPrivateKeyusesptwice. Custos rebuilds the key fromn, e, d, p, qand validates it instead.