vault.rs

crates/veilvoice-crypto/src/vault.rs

veilvoice-crypto · 904 lines · read the source here · or on GitHub

Where the app lock is kept: two copies, unpredictable names, and a restore.

What is real here and what is only awkward

This module does three things to the app-lock file, and they are not worth the same amount. Saying which is which is the point of this section.

The second copy is real. A lock kept in one file is removed by deleting that file. A lock kept in two files in two different directories is not, unless the person deleting knows about both. When the first copy is gone or unreadable, Vault::load restores it from the second and reports the event, so the lock comes back and the owner is told it went.

The administrator-only copy is real, where the platform provides it. On Unix, when VeilVoice is run with enough privilege to write under /etc, the second copy is written there and is thereafter not writable by an ordinary user. Removing the lock then needs sudo, which is a genuine step up from needing a file manager. VeilVoice never asks for that privilege and never elevates itself: it uses what it already has and otherwise carries on. On Windows the equivalent needs an access-control list this crate does not link the API to set, so the second copy there is a second copy and nothing more, and this module says so rather than implying a protection it did not obtain.

The unpredictable name and the masked contents are neither. They are obscurity. The name is derived from a value in an index file that sits at a fixed, obvious path, because something has to, or nothing could ever find the lock again. Anybody who reads this source, or simply reads the index, recomputes both names in a second. What they buy is narrow and real enough to keep: a scan for the string VEILLOK1 across a disk finds nothing, a backup rule written against applock.bin misses, and advice of the form "just delete this file" does not survive being passed on. None of that stops an attacker who is paying attention, and none of it is counted as security anywhere in the documentation.

What none of it does

It does not stop somebody holding the disk. It does not stop somebody who knows the passphrase. It does not make the failed-attempt counter trustworthy: see crate::lock::AppLock::to_bytes for why that one cannot be authenticated at all. If the threat is the disk, the answer is still full-volume encryption.

In plain words

The lock is kept twice, in two places, under names that are not guessable from the outside, and scrambled so it does not look like a password file. If one copy goes missing, the other puts it back and you are told.

The scrambling and the odd names are speed bumps, not locks. They stop careless deletion and casual searching. They do not stop somebody who has decided to get in and has your disk. Where VeilVoice is already running with administrator rights, the spare copy is put somewhere an ordinary user cannot touch, and that part is not a speed bump.

WHAT THIS FILE CONTAINS

904 lines defining 21 functions (14 public), 2 types and 8 constants. Everything below is read out of the source, so it cannot disagree with the code.

The types it owns.

  • enum Found line 92 · What Vault::load found when it went looking.
  • struct Vault line 119 · The two files a lock lives in, and the index that names them.

What happens when it runs. These are the ways in: public, and nothing else in this file calls them, so they are what an outside caller reaches first.

  • Vault::at line 134 · Resolve the vault under base, creating the index if there is none.
    reaches name_for, writable
  • Vault::primary line 196 · The file the lock is read from and written to.
  • Vault::shadow line 201 · The second copy.
  • Vault::index line 206 · The index that names both.
  • Vault::decoy line 211 · The decoy passphrase's record, where one is set.
  • Vault::load_decoy line 226 · Read the decoy record, or None when no decoy is set.
    reaches mask
  • Vault::has_decoy_file line 237 · Whether there is a decoy record at all, whether or not it reads.
  • Vault::store_decoy line 242 · Write the decoy record, masked, owner-only.
    reaches write_one, mask
  • Vault::clear_decoy line 247 · Remove the decoy record.
  • Vault::load line 261 · Read the lock, restoring one copy from the other if it has to.
    reaches read_masked, write_one, mask
  • Vault::store line 310 · Write both copies, and say whether the spare is now current.
    reaches write_one, mask
  • Vault::clear line 321 · Remove both copies, the decoy record and the index with them.
  • admin_dir_present line 434 · That same directory, but only when it is already there.
    reaches pretended
  • admin_dir line 497 · A directory only an administrator can write to, if this process can make one there.
    reaches pretended

WHAT CALLS WHAT

The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one.

The same graph as Mermaid source
%%{init: {"theme":"base","themeVariables":{"background":"#1a1b26","primaryColor":"#1f2335","primaryTextColor":"#c0caf5","primaryBorderColor":"#7aa2f7","secondaryColor":"#16161e","tertiaryColor":"#16161e","lineColor":"#737aa2","textColor":"#c0caf5","mainBkg":"#1f2335","nodeBorder":"#7aa2f7","clusterBkg":"#16161e","clusterBorder":"#2f3549","fontFamily":"ui-monospace, SFMono-Regular, Consolas, monospace","fontSize":"14px"}}}%%
flowchart TD
    n_at(["Vault::at<br/>line 134"])
    n_primary(["Vault::primary<br/>line 196"])
    n_shadow(["Vault::shadow<br/>line 201"])
    n_index(["Vault::index<br/>line 206"])
    n_decoy(["Vault::decoy<br/>line 211"])
    n_load_decoy(["Vault::load_decoy<br/>line 226"])
    n_has_decoy_file(["Vault::has_decoy_file<br/>line 237"])
    n_store_decoy(["Vault::store_decoy<br/>line 242"])
    n_clear_decoy(["Vault::clear_decoy<br/>line 247"])
    n_load(["Vault::load<br/>line 261"])
    n_store(["Vault::store<br/>line 310"])
    n_clear(["Vault::clear<br/>line 321"])
    n_write_one["Vault::write_one<br/>line 341"]
    n_read_masked["Vault::read_masked<br/>line 360"]
    n_name_for["name_for<br/>line 368"]
    n_mask["mask<br/>line 387"]
    n_writable["writable<br/>line 406"]
    n_admin_dir_present(["admin_dir_present<br/>line 434"])
    n_pretended["pretended<br/>line 457"]
    n_pretend_admin_dir["pretend_admin_dir<br/>line 478"]
    n_admin_dir(["admin_dir<br/>line 497"])
    n_admin_dir --> n_pretended
    n_admin_dir_present --> n_pretended
    n_at --> n_name_for
    n_at --> n_writable
    n_load --> n_read_masked
    n_load --> n_write_one
    n_load_decoy --> n_mask
    n_read_masked --> n_mask
    n_store --> n_write_one
    n_store_decoy --> n_write_one
    n_write_one --> n_mask
    click n_at href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L134" "open the source"
    click n_primary href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L196" "open the source"
    click n_shadow href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L201" "open the source"
    click n_index href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L206" "open the source"
    click n_decoy href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L211" "open the source"
    click n_load_decoy href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L226" "open the source"
    click n_has_decoy_file href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L237" "open the source"
    click n_store_decoy href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L242" "open the source"
    click n_clear_decoy href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L247" "open the source"
    click n_load href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L261" "open the source"
    click n_store href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L310" "open the source"
    click n_clear href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L321" "open the source"
    click n_write_one href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L341" "open the source"
    click n_read_masked href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L360" "open the source"
    click n_name_for href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L368" "open the source"
    click n_mask href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L387" "open the source"
    click n_writable href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L406" "open the source"
    click n_admin_dir_present href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L434" "open the source"
    click n_pretended href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L457" "open the source"
    click n_pretend_admin_dir href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L478" "open the source"
    click n_admin_dir href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-crypto/src/vault.rs#L497" "open the source"
    classDef entry fill:#1f2335,stroke:#7aa2f7,color:#c0caf5
    class n_at,n_primary,n_shadow,n_index,n_decoy,n_load_decoy,n_has_decoy_file,n_store_decoy,n_clear_decoy,n_load,n_store,n_clear,n_admin_dir_present,n_admin_dir entry
    classDef helper fill:#1f2335,stroke:#bb9af7,color:#c0caf5
    class n_write_one,n_read_masked,n_name_for,n_mask,n_writable,n_pretended,n_pretend_admin_dir helper
    subgraph chart_key ["Key"]
        direction LR
        key_entry["entry: a way in: public, and nothing in this file calls it"]
        key_helper["helper: private to this file"]
    end
    class key_entry entry
    class key_helper helper

This site loads no third-party script, so it cannot run Mermaid; the diagram above is the same nodes and edges drawn by the generator instead. GitHub renders the source below directly.

ITEMS

ItemLineDocumentation
SITE_LEN const61Length of the per-installation value the file names are derived from.
NAME_BYTES const64Bytes of hex in a derived file name.
INDEX_NAME const67Fixed name of the index.
LABEL_PRIMARY const75Derives the real vault's key from the material the unlock produced.
LABEL_SHADOW const78Derives the decoy vault's key from the same material, so the two keys are unrelated even though one passphrase leads to both.
LABEL_MASK const80Derives the mask that hides which of the two an index entry belongs to.
LABEL_DECOY const88The decoy passphrase's own record, where one is set.
Found pub enum92What Vault::load found when it went looking.
Vault pub struct119The two files a lock lives in, and the index that names them.
Vault::at pub fn134Resolve the vault under base, creating the index if there is none.
Vault::primary pub fn196The file the lock is read from and written to.
Vault::shadow pub fn201The second copy.
Vault::index pub fn206The index that names both.
Vault::decoy pub fn211The decoy passphrase's record, where one is set.
Vault::load_decoy pub fn226Read the decoy record, or None when no decoy is set.
Vault::has_decoy_file pub fn237Whether there is a decoy record at all, whether or not it reads.
Vault::store_decoy pub fn242Write the decoy record, masked, owner-only.
Vault::clear_decoy pub fn247Remove the decoy record.
Vault::load pub fn261Read the lock, restoring one copy from the other if it has to.
Vault::store pub fn310Write both copies, and say whether the spare is now current.
Vault::clear pub fn321Remove both copies, the decoy record and the index with them.
Vault::write_one fn341Mask bytes for this site and write them at path, creating the directory if it is not there.
Vault::read_masked fn360Read one file back and unmask it, or None if it is not a lock.
name_for fn368The file name derived from site under label.
mask fn387Exclusive-or bytes with a keystream derived from site.
writable fn406Whether this process can create a file in dir, found out by doing it.
ADMIN_DIR const425Where an administrator's copy of the lock goes, on a platform that has one.
admin_dir_present pub fn434That same directory, but only when it is already there.
pretended fn457This thread's answer from pretend_admin_dir, if a test has given one.
pretend_admin_dir pub(crate) fn478Tell this thread's tests where the administrator's directory is, or that there is none.
admin_dir pub fn497A directory only an administrator can write to, if this process can make one there.