crates/veilvoice-verify/src/update.rs
veilvoice-verify · 1650 lines · read the source here · or on GitHub
The update that does the update.
Roadmap item 179. veilvoice_setup::update reports that a newer release exists and stops there, which leaves the reader to download it, verify it, unpack it and replace their copy by hand. Most people will do some of that and not the rest, and the part they skip is the checking. This does all four in one act, and the checking is the part it will not skip.
The stance this changes, and the sentence that survives it
veilvoice_setup::update used to say, as a design note rather than a limitation:
> An update checker that could install its own answer is an update checker > that can be made to install somebody else's.
That sentence is still true and it is still the constraint this module is written around. What made it an argument for doing nothing was the missing half: whose answer. Every byte that reaches your disk here is checked against a signature made by a key that is compiled into the binary you are already running, before anything is unpacked and long before anything is copied over a program. Somebody who can answer the network cannot produce that signature, so they cannot make this install their answer. They can make it refuse, loudly, which is the correct failure.
The other half of that sentence, that nothing happens on its own, is unchanged and is not a detail. There is no timer, no check at startup and no background thread. An update happens because a person asked for one, in the same session, and every step of it is reported as it happens.
The order, which is the whole design
- Ask.
offeredcallsveilvoice_setup::update::check, which reads one public page with the transfer tool the operating system already ships. Nothing is downloaded. - Fetch. The archive for this platform,
SHA256SUMS,SHA256SUMS.ascandCONTENTS.sha256, into a directory the caller names. Nothing is run and nothing is opened. - Prove. The signature over
SHA256SUMSagainst the compiled-in key; the archive againstSHA256SUMS;CONTENTS.sha256againstSHA256SUMS; and then every file inside the archive againstCONTENTS.sha256, read where it lies without unpacking it. - Open. Only now, and with the system's own
tar, into an empty directory. What lands is hashed again against the same signed list, because an extractor is a program too. - Replace. Each new binary is written beside the one it replaces and renamed into place, through the same routine
veilvoice installuses. - Record. The integrity record is re-taken, for the reason below.
- Restart, which the caller does, because a window and a command line part company here.
Steps 3 and 4 are crate::check, unchanged and uncopied. That was the condition roadmap item 164 was landed first for: an updater that verified a download with its own second implementation would be a second implementation to get subtly wrong, in the one place where being subtly wrong means accepting something.
The archive is never trusted to name its own files
Nothing here reads a name out of the archive and acts on it. The list of members comes from CONTENTS.sha256, which the signature covers, and the archive is compared against that list in both directions: a member the list does not have is a failure, and a listed file the archive does not carry is a failure. So the archive-traversal defects, a member called ../../.bashrc or a symbolic link pointing at one, are refused at the comparison rather than caught at the extractor.
The integrity record, and why it is re-taken here
veilvoice-guard records what VeilVoice's own files hash to, and the window checks that record at every launch. An update replaces those files with different ones, so the next launch after an update would report the update as a change, every time, for ever. A tamper alarm that fires on the ordinary maintenance of the thing it watches is an alarm people learn to dismiss, and an alarm people dismiss is worth nothing on the day it is right.
So the record is re-taken as part of the update. Two constraints on when and how, both of which are the point rather than housekeeping:
- After the signature has been checked, never before. A record re-taken first would be a record of whatever arrived, blessed by this program, and an update that failed its signature check would have already written down the attacker's files as the correct ones.
- Unsealed unless the reader is there to seal it. The sealed record is sealed under the app lock's passphrase, which exists only while somebody is present and has typed it. With it in hand the new record is sealed; without it the record is written in the clear and
Done::recordsays so, in those words, rather than sealing it under something kept beside it and calling that protection.
With an app lock set, the passphrase is required rather than optional: see Error::Locked. Updating past a lock without it would leave the machine with new files and a sealed record of the old ones, which reads as tampering at the next unlock and cannot be told apart from the real thing.
What this updates is the copy you are running
Not "the installation", which this program is in no position to be certain about: VeilVoice runs portably by design, and a folder somebody unzipped is as real an installation as anything under ~/.local. The files replaced are the ones beside std::env::current_exe, which is what a person pressing update means, and it is the one answer that is right for a portable folder, a per-user install and a copy somebody put somewhere of their own.
In plain words
Downloads the new version, checks it properly, and puts it in place.
It checks the download against a signature made with a key that is already inside the program you are running, before it opens the file, and it opens the file before it touches anything of yours. If any of that fails, nothing is replaced and it tells you what failed.
If you have an app lock, it will ask for it, because the record of what VeilVoice's own files should look like has to be rewritten by the update and that record is locked with the same passphrase.
WHAT THIS FILE CONTAINS
1650 lines defining 22 functions (7 public), 5 types and 2 constants. Everything below is read out of the source, so it cannot disagree with the code.
The types it owns.
enum Errorline 216 · Everything that can stop an update, in the words the reader is given.struct Offerline 281 · A newer release, and the file to fetch for it.enum Stepline 376 · What the update is doing, reported as it happens.enum Recordline 391 · What became of the integrity record.struct Doneline 402 · A finished update.
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.
offeredline 295 · Ask what is published, and offer it if it is newer.
reachesarchive_forperformline 454 · The whole update, in the one order that is safe.
reachescheck_password,installation,lock_is_set,update_within,workspace,check_password_in,lock_in,open_archive,proved_contents,put_in_place,retake_record,extractrelaunchline 991 · Start the updated program and return.
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_this_platform["this_platform<br/>line 162"]
n_archive_for["archive_for<br/>line 204"]
n_fmt["Error::fmt<br/>line 247"]
n_offered(["offered<br/>line 295"])
n_lock_is_set["lock_is_set<br/>line 326"]
n_lock_in["lock_in<br/>line 346"]
n_installation["installation<br/>line 361"]
n_perform(["perform<br/>line 454"])
n_check_password["check_password<br/>line 495"]
n_check_password_in["check_password_in<br/>line 503"]
n_workspace["workspace<br/>line 524"]
n_update_within["update_within<br/>line 530"]
n_proved_contents["proved_contents<br/>line 616"]
n_archive_name["archive_name<br/>line 700"]
n_open_archive["open_archive<br/>line 710"]
n_extract["extract<br/>line 784"]
n_tar_program["tar_program<br/>line 812"]
n_put_in_place["put_in_place<br/>line 850"]
n_replaced_so_far["replaced_so_far<br/>line 899"]
n_retake_record["retake_record<br/>line 916"]
n_write_beside["write_beside<br/>line 976"]
n_relaunch(["relaunch<br/>line 991"])
n_check_password --> n_check_password_in
n_check_password_in --> n_lock_in
n_extract --> n_tar_program
n_lock_is_set --> n_lock_in
n_offered --> n_archive_for
n_open_archive --> n_extract
n_perform --> n_check_password
n_perform --> n_installation
n_perform --> n_lock_is_set
n_perform --> n_update_within
n_perform --> n_workspace
n_proved_contents --> n_archive_name
n_put_in_place --> n_replaced_so_far
n_retake_record --> n_write_beside
n_update_within --> n_open_archive
n_update_within --> n_proved_contents
n_update_within --> n_put_in_place
n_update_within --> n_retake_record
n_workspace --> n_installation
click n_this_platform href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L162" "open the source"
click n_archive_for href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L204" "open the source"
click n_fmt href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L247" "open the source"
click n_offered href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L295" "open the source"
click n_lock_is_set href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L326" "open the source"
click n_lock_in href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L346" "open the source"
click n_installation href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L361" "open the source"
click n_perform href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L454" "open the source"
click n_check_password href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L495" "open the source"
click n_check_password_in href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L503" "open the source"
click n_workspace href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L524" "open the source"
click n_update_within href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L530" "open the source"
click n_proved_contents href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L616" "open the source"
click n_archive_name href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L700" "open the source"
click n_open_archive href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L710" "open the source"
click n_extract href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L784" "open the source"
click n_tar_program href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L812" "open the source"
click n_put_in_place href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L850" "open the source"
click n_replaced_so_far href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L899" "open the source"
click n_retake_record href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L916" "open the source"
click n_write_beside href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L976" "open the source"
click n_relaunch href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/update.rs#L991" "open the source"
classDef entry fill:#1f2335,stroke:#7aa2f7,color:#c0caf5
class n_offered,n_perform,n_relaunch entry
classDef api fill:#1f2335,stroke:#7dcfff,color:#c0caf5
class n_archive_for,n_lock_is_set,n_installation,n_workspace api
classDef helper fill:#1f2335,stroke:#bb9af7,color:#c0caf5
class n_this_platform,n_fmt,n_lock_in,n_check_password,n_check_password_in,n_update_within,n_proved_contents,n_archive_name,n_open_archive,n_extract,n_tar_program,n_put_in_place,n_replaced_so_far,n_retake_record,n_write_beside helper
subgraph chart_key ["Key"]
direction LR
key_entry["entry: a way in: public, and nothing in this file calls it"]
key_api["api: public, and also used inside this file"]
key_helper["helper: private to this file"]
end
class key_entry entry
class key_api api
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
| Item | Line | Documentation |
|---|---|---|
PUBLISHED pub const | 131 | Every platform label the release workflow publishes an archive for. |
PLATFORM pub const | 152 | This build's label, or None for a build of a kind nothing is published for. |
this_platform fn | 162 | The label picked apart by target, as the workflow's matrix picks it. |
archive_for pub fn | 204 | The archive this platform's release is published under. |
Error pub enum | 216 | Everything that can stop an update, in the words the reader is given. |
Error::fmt fn | 247 | |
Offer pub struct | 281 | A newer release, and the file to fetch for it. |
offered pub fn | 295 | Ask what is published, and offer it if it is newer. |
lock_is_set pub fn | 326 | Whether this machine has an app lock set. |
lock_in fn | 346 | The lock kept under base, without creating anything if there is none. |
installation pub fn | 361 | Where the running copy of VeilVoice lives. |
Step pub enum | 376 | What the update is doing, reported as it happens. |
Record pub enum | 391 | What became of the integrity record. |
Done pub struct | 402 | A finished update. |
perform pub fn | 454 | The whole update, in the one order that is safe. |
check_password fn | 495 | Refuse a passphrase the app lock does not accept, before anything is done. |
check_password_in fn | 503 | check_password against the lock under base, so a test can give it one. |
workspace pub fn | 524 | Where an update does its work: beside the copy being replaced. |
update_within fn | 530 | The update itself, with the workspace's lifetime handled by the caller above. |
proved_contents fn | 616 | The signature, the hash list, the contents list and every member, in that order, all of it crate::check. |
archive_name fn | 700 | The archive's own file name, which is the key into the contents list. |
open_archive fn | 710 | Unpack into an empty directory, then hash what landed. |
extract fn | 784 | Unpack with the tool the operating system already ships. |
tar_program fn | 812 | tar, by absolute path. |
put_in_place fn | 850 | Put each new binary at the name people run, one program at a time. |
replaced_so_far fn | 899 | Say what an update had already put in place when it stopped. |
retake_record fn | 916 | Re-take the integrity record over the files that were just replaced. |
write_beside fn | 976 | Write the sealed record, owner-readable, making its directory if needed. |
relaunch pub fn | 991 | Start the updated program and return. |