SPB Git

Repository Public

BACKUP_FORMAT.md 2.9 KB 71 lines markdown

1# `.spvault` backup format — version 123A `.spvault` file is a complete, encrypted copy of the vault: every card record, its photographs and the vault manifest (card order, custom categories). It contains no clear-text card data, not even the number of cards. Implementation: `SPVault/Engines/Backup/BackupArchive.swift`. Uniform type identifier: `ai.spboucher.spvault`.45## Layout67```8"SPVAULT\0"        8 bytes   magic9version            u16 BE    110header length      u32 BE11header             JSON, clear12repeat until end of file:13  record length    u32 BE14  record           SPV1 sealed blob, kind 7 (see CRYPTOGRAPHY.md)15```1617Clear header:1819```json20{21  "appVersion": "1.0.0",22  "createdAt": 786400000.0,23  "format": "spvault",24  "kdf": { "algorithm": "pbkdf2-hmac-sha256", "iterations": 600000, "salt": "<32 random bytes, base64>" }25}26```2728## Keys2930```31base = PBKDF2-HMAC-SHA256(passphrase (NFC, UTF-8), salt, iterations)      32 bytes32key  = HKDF-SHA256(base, salt = SHA-256(header bytes), info = "spvault/backup/v1")33```3435Because the hash of the header is the HKDF salt, changing any byte of the clear header changes the key and nothing decrypts.3637## Records3839Each record is AES-256-GCM with a fresh random nonce and this additional authenticated data:4041```42"SPV1" | 1 | 7 | SHA-256(header) | record index (u32 BE) | final flag (1 for the last record, else 0)43```4445- Record 0: summary — `{ cardCount, manifest, createdAt }`.46- Records 1…n: one card each — `{ card, front, frontThumbnail, back?, backThumbnail? }` (JSON; images as stored, HEIC or JPEG).4748## Verification on import4950A backup is accepted only if all of the following hold; otherwise nothing is restored.5152| Check | Failure reported as |53|---|---|54| Magic and version | not a backup / unsupported version |55| KDF algorithm known, iterations ≥ 100 000, salt ≥ 16 bytes | corrupted |56| Record 0 authenticates | wrong passphrase |57| Every record authenticates at its own index | corrupted (covers altered, reordered or substituted records) |58| The last record carries the final flag | corrupted (covers truncation) |59| Number of card records equals `cardCount` | corrupted |60| No duplicate card identifier | corrupted |6162## Restore6364Restoring re-encrypts every card under a new random key of the current device and its own master key; nothing of the old device's key material is in the file. Modes: *merge* (cards are matched by identifier; existing ones are replaced) or *replace* (the vault is emptied first). Records are passed through `SensitiveDataPolicy.sanitized`, so a file produced by anything else cannot bring a security code or track data into the vault.6566On a new iPhone: onboarding creates a new vault (new master key bound to that iPhone's Face ID), then imports the file.6768## Passphrase6970The export refuses a passphrase below 12 characters or below the "Good" estimate of `PassphrasePolicy`. The passphrase is not stored anywhere; a lost passphrase makes the file unreadable.71
Files main
Menu

Theme