fetch.rs

crates/veilvoice-verify/src/fetch.rs

veilvoice-verify · 447 lines · read the source here · or on GitHub

Download a release, without putting an HTTP client in the dependency graph.

The constraint this is written around

VeilVoice is offline by construction, and that is not a slogan: a CI job fails the build if reqwest, hyper, curl, ureq, tungstenite, isahc or surf appears anywhere in cargo tree. The claim on the front page -- "no network code in the dependency graph" -- is one a reader can check in ten seconds, and it is a large part of why this project is worth trusting.

Fetching a release to check it is a genuinely useful thing for this binary to do, and it is also the one thing that claim forbids. So the download is done by the tool the operating system already ships, invoked as a subprocess:

| Platform | Used | Already present because | |---|---|---| | Windows 10+ | curl.exe | shipped in System32 since 2018 | | macOS | curl | part of the base system | | Linux, BSD | curl, else wget | one or the other is on essentially every install |

cargo tree stays exactly as clean as it was, the CI job that enforces it is untouched, and nothing in the library crates gained the ability to talk to anything. What changed is that one command-line tool, whose entire purpose is checking downloads, can now also make one -- when asked, never on its own.

This is the same pattern the rest of the project already uses for platform work it will not link a dependency for: veilvoice-watch reads the registry through reg query, and veilvoice-guard reads the event log through wevtutil.

What is deliberately not done here

No downloader is resolved by bare name. Finding curl by searching PATH on Windows includes the current directory, so running this from a folder containing a hostile curl.exe would run that instead -- finding F-13, in the one program whose job is deciding whether a download is genuine. Absolute paths are tried first, and a bare name is only ever a last resort on platforms where the search order does not include the working directory.

Nothing is fetched implicitly. A download happens because the user passed a subcommand that says so. There is no update check, no telemetry, and no "just in case" request.

Only one address is ever asked for, and it is compiled in. A URL cannot be supplied on the command line, so this cannot be turned into a general downloader by an argument. GitHub answers a release download by sending it on to its own file host, and that redirect is followed over HTTPS only, at most five times.

Neither downloader reads its user's configuration file. A .curlrc or .wgetrc can turn off certificate checks or send the request through a proxy, and a verifier whose download depends on a file it never shows is not saying what it did.

In plain words

Downloads a release, without VeilVoice containing any networking code.

It asks the tool your system already has to do the fetching. That is what keeps a real promise the rest of the project makes: there is no HTTP client anywhere in what VeilVoice is built from, which you can check yourself, and this is the one command that touches the network at all.

WHAT THIS FILE CONTAINS

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

The types it owns.

  • struct Downloader line 120 · Where a downloader was found, and what to call it.
  • enum Style line 132 · Which downloader is being driven, since the two want different arguments for the same job.

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.

  • download line 205 · Fetch one URL into into.
    reaches arguments, at_a_known_origin, find_downloader, no_downloader_message
  • asset_url line 296 · The URL of one file in one release.
  • valid_tag line 315 · A release tag, rejected unless it looks like one.
  • valid_asset line 324 · An asset filename, rejected unless it looks like one.

WHAT CALLS WHAT

at_a_known_origin line 102 find_downloader line 147 no_downloader_message line 188 download line 205 arguments line 256 asset_url line 296 valid_tag line 315 valid_asset line 324 entry: a way in: public, and nothing in this file calls it api: public, and also used inside this file helper: private to this file dashed: a call that goes back up, or across a wrapped rank 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 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_a_known_origin["at_a_known_origin<br/>line 102"]
    n_find_downloader["find_downloader<br/>line 147"]
    n_no_downloader_message["no_downloader_message<br/>line 188"]
    n_download(["download<br/>line 205"])
    n_arguments["arguments<br/>line 256"]
    n_asset_url(["asset_url<br/>line 296"])
    n_valid_tag(["valid_tag<br/>line 315"])
    n_valid_asset(["valid_asset<br/>line 324"])
    n_download --> n_arguments
    n_download --> n_at_a_known_origin
    n_download --> n_find_downloader
    n_download --> n_no_downloader_message
    click n_at_a_known_origin href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/fetch.rs#L102" "open the source"
    click n_find_downloader href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/fetch.rs#L147" "open the source"
    click n_no_downloader_message href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/fetch.rs#L188" "open the source"
    click n_download href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/fetch.rs#L205" "open the source"
    click n_arguments href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/fetch.rs#L256" "open the source"
    click n_asset_url href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/fetch.rs#L296" "open the source"
    click n_valid_tag href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/fetch.rs#L315" "open the source"
    click n_valid_asset href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-verify/src/fetch.rs#L324" "open the source"
    classDef entry fill:#1f2335,stroke:#7aa2f7,color:#c0caf5
    class n_download,n_asset_url,n_valid_tag,n_valid_asset entry
    classDef api fill:#1f2335,stroke:#7dcfff,color:#c0caf5
    class n_at_a_known_origin,n_no_downloader_message api
    classDef helper fill:#1f2335,stroke:#bb9af7,color:#c0caf5
    class n_find_downloader,n_arguments 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

ItemLineDocumentation
HOST pub const78Where a VeilVoice release is fetched from.
ORIGINS pub const91Every origin this program will ever fetch from.
at_a_known_origin pub fn102Whether a URL is at one of the origins above.
REPO pub const109The repository releases are fetched from.
MAX_BYTES pub const117The largest file this will accept.
Downloader struct120Where a downloader was found, and what to call it.
Style enum132Which downloader is being driven, since the two want different arguments for the same job.
find_downloader fn147Absolute paths first, and a bare name only where that is safe.
no_downloader_message pub fn188Say what could not be found, and what to do instead.
download pub fn205Fetch one URL into into.
arguments fn256What one downloader is told, to fetch url into into and nothing else.
asset_url pub fn296The URL of one file in one release.
SUMS pub const301The list of hashes every release publishes, one line per file.
SIGNATURE pub const304The detached signature over that list, which is what ties it to the signing key rather than to whoever served the page.
valid_tag pub fn315A release tag, rejected unless it looks like one.
valid_asset pub fn324An asset filename, rejected unless it looks like one.