SPB Git

Repository Public

BACKUP_FORMAT.md 2.9 KB

# .spvault backup format — version 1

A .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.

# Layout

text
"SPVAULT\0"        8 bytes   magic
version            u16 BE    1
header length      u32 BE
header             JSON, clear
repeat until end of file:
  record length    u32 BE
  record           SPV1 sealed blob, kind 7 (see CRYPTOGRAPHY.md)

Clear header:

json
{
  "appVersion": "1.0.0",
  "createdAt": 786400000.0,
  "format": "spvault",
  "kdf": { "algorithm": "pbkdf2-hmac-sha256", "iterations": 600000, "salt": "<32 random bytes, base64>" }
}

# Keys

text
base = PBKDF2-HMAC-SHA256(passphrase (NFC, UTF-8), salt, iterations)      32 bytes
key  = HKDF-SHA256(base, salt = SHA-256(header bytes), info = "spvault/backup/v1")

Because the hash of the header is the HKDF salt, changing any byte of the clear header changes the key and nothing decrypts.

# Records

Each record is AES-256-GCM with a fresh random nonce and this additional authenticated data:

text
"SPV1" | 1 | 7 | SHA-256(header) | record index (u32 BE) | final flag (1 for the last record, else 0)
  • Record 0: summary — { cardCount, manifest, createdAt }.
  • Records 1…n: one card each — { card, front, frontThumbnail, back?, backThumbnail? } (JSON; images as stored, HEIC or JPEG).

# Verification on import

A backup is accepted only if all of the following hold; otherwise nothing is restored.

Check Failure reported as
Magic and version not a backup / unsupported version
KDF algorithm known, iterations ≥ 100 000, salt ≥ 16 bytes corrupted
Record 0 authenticates wrong passphrase
Every record authenticates at its own index corrupted (covers altered, reordered or substituted records)
The last record carries the final flag corrupted (covers truncation)
Number of card records equals cardCount corrupted
No duplicate card identifier corrupted

# Restore

Restoring 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.

On a new iPhone: onboarding creates a new vault (new master key bound to that iPhone's Face ID), then imports the file.

# Passphrase

The 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.

Files main
Menu

Theme