Skip to main content

agentmux_srv_core/backend/vault/
kdbx_names.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! The names a Vault entry's parts and details have in a KeePass entry
5//! (docs/specs/SPEC_VAULT_PANE_AGENTS_USE_SECRETS_UNSEEN_2026_10_19.md §8.3, §8.4).
6//!
7//! KeePass has an entry type of one kind: a title, a user name, a password, an address,
8//! notes, and any number of named custom fields. So a card, a Social Security number or an
9//! API key is an entry whose secret is a *protected custom field* with a name. The exporter
10//! writes these names and the importer reads the same ones (and a few spellings other
11//! people use), so a database leaves and comes back as the same entries.
12
13/// A secret custom field that makes an entry a Vault entry of `kind`, holding its `part`.
14pub struct Primary {
15    pub kind: &'static str,
16    pub part: &'static str,
17    /// What the exporter calls the field.
18    pub title: &'static str,
19    /// Every name the importer takes for it, lowercase.
20    pub aliases: &'static [&'static str],
21}
22
23pub const PRIMARY: &[Primary] = &[
24    Primary { kind: "ssn", part: "value", title: "SSN", aliases: &["ssn", "social security number"] },
25    Primary { kind: "itin", part: "value", title: "ITIN", aliases: &["itin"] },
26    Primary { kind: "tin", part: "value", title: "Taxpayer ID", aliases: &["taxpayer id", "taxpayer id number", "tin"] },
27    Primary { kind: "ein", part: "value", title: "EIN", aliases: &["ein"] },
28    Primary { kind: "date-of-birth", part: "value", title: "Date of birth", aliases: &["date of birth", "dob"] },
29    Primary { kind: "passport", part: "value", title: "Passport number", aliases: &["passport number", "passport"] },
30    Primary {
31        kind: "drivers-licence",
32        part: "value",
33        title: "Driver's licence number",
34        aliases: &["driver's licence number", "driver's license number", "drivers licence number", "drivers license number"],
35    },
36    Primary { kind: "other-id", part: "value", title: "ID number", aliases: &["id number"] },
37    Primary { kind: "card", part: "number", title: "Card number", aliases: &["card number", "credit card number"] },
38    Primary { kind: "bank-account", part: "account", title: "Account number", aliases: &["account number", "bank account number"] },
39    Primary { kind: "api-key", part: "value", title: "API key", aliases: &["api key", "api_key", "apikey"] },
40];
41
42/// A secret that goes with a primary one: a card's expiry, a bank account's routing number.
43pub struct Companion {
44    pub kind: &'static str,
45    pub part: &'static str,
46    pub title: &'static str,
47    pub aliases: &'static [&'static str],
48}
49
50pub const COMPANIONS: &[Companion] = &[
51    Companion { kind: "card", part: "expiry", title: "Expiry", aliases: &["expiry", "expiry date", "expires"] },
52    Companion { kind: "card", part: "exp_month", title: "Expiry month", aliases: &["expiry month", "expiration month"] },
53    Companion { kind: "card", part: "exp_year", title: "Expiry year", aliases: &["expiry year", "expiration year"] },
54    Companion { kind: "card", part: "cvc", title: "CVC", aliases: &["cvc", "cvv", "security code"] },
55    Companion { kind: "card", part: "zip", title: "Billing ZIP", aliases: &["billing zip", "zip", "zip code", "postal code", "billing postal code"] },
56    Companion { kind: "card", part: "name", title: "Cardholder", aliases: &["cardholder", "cardholder name", "name on card"] },
57    Companion { kind: "bank-account", part: "routing", title: "Routing number", aliases: &["routing number", "routing"] },
58];
59
60/// A plain detail: not secret, so an unprotected custom field.
61pub struct Detail {
62    pub name: &'static str,
63    pub title: &'static str,
64    pub aliases: &'static [&'static str],
65}
66
67pub const DETAILS: &[Detail] = &[
68    Detail { name: "owner", title: "Owner", aliases: &["owner"] },
69    Detail { name: "issuer", title: "Issuer", aliases: &["issuer"] },
70    Detail { name: "expires", title: "Expires", aliases: &["expires on", "valid until", "expiration date"] },
71    Detail { name: "service", title: "Service", aliases: &["service"] },
72    Detail { name: "env_name", title: "Environment variable", aliases: &["environment variable", "env name", "env_name"] },
73    Detail { name: "bank", title: "Bank", aliases: &["bank", "bank name"] },
74];
75
76pub fn primary_for(kind: &str) -> Option<&'static Primary> {
77    PRIMARY.iter().find(|p| p.kind == kind)
78}
79
80pub fn matches(aliases: &[&str], name: &str) -> bool {
81    let n = name.trim().to_lowercase();
82    aliases.iter().any(|a| *a == n)
83}