Menu

The weirdlock1 browser viewer, for implementers

The viewer every locked album carries — what it is made of, the rules it keeps, how it is tested, how to verify a copy and how an album embeds it.

This page is for whoever builds, embeds, reviews or checks the viewer that opens a weirdlock1 album in a browser. People who only want to open an album read Locked content.

The release#

Release 1 of the viewer (format weirdlock1, Apache-2.0); the set's fingerprint (SHA-256 of the lines <path> <sha256>\n in this order): 127b8ccc4cb21484860c3d92e16154168d40ca2e498f5882425494cd376962da.

FileSHA-256BytesSubresource Integrity
index.html7513d2ecc1bc650069e81e7cbb54bb50ac1c63ebe65248787faa1c6340e355ac1182— (the bootstrap)
v/1/viewer.js286331fec207d354c9321a6e2663aa50d865cb5a66893091a5eb4db379788d3469268sha384-0Mozlyw6LdK4EZtv4baNrW/jkGE+ef3APLyTMZ61sG+nogxyAFdGtpBeBm9YDWrA
v/1/viewer.cssf0158408df06832b6876f40c753b897b167fd030a1f7e12c553382f1bd0a72093902sha384-YqUzZb0jljaiXRoqJvxIkvM+tPEXL01Kr7ZyNVztVfiOcWsf9dYZYHJiNy/gK9Dv

The bootstrap's content security policy: default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' blob:; media-src 'self' blob:; connect-src 'self'; worker-src 'none'; frame-src 'none'; object-src 'none'; base-uri 'none'; form-action 'none'.

The release is three files placed at the root of an album folder, next to lock/:

index.html            the bootstrap: the content security policy, no-referrer, and the two files below with Subresource Integrity
v/<release>/viewer.js the viewer: the format library and the page, in one script
v/<release>/viewer.css its stylesheet (system fonts only)
lock/keyring          the album (the format)
lock/manifest
lock/b/<id>

The same files are in every album of a release, so their blocks are stored once per account and their content addresses never change.

Where to download it#

The published release is served at https://docs.weird.ro/viewer/:

  • https://docs.weird.ro/viewer/viewer.json: the release (its number, each file's path, SHA-256 and size, the SRI values, the content security policy, the set's fingerprint, and the source commit it was built from: source_commit);
  • https://docs.weird.ro/viewer/v/<release>/viewer.js and …/viewer.css: the two files of a release, which never change (a change to their bytes is a new release number);
  • https://docs.weird.ro/viewer/index.html: the bootstrap, answered as plain text, byte for byte (it is never run on that address).

How it is made#

The viewer is plain modern JavaScript without a framework or a dependency, shipped as written: no minifier and no bundler run on it, so the script a browser receives is the source a reviewer reads. It joins three source files, each in its own function scope:

  • scrypt.js: scrypt (RFC 7914). Its memory-hard core is @noble/hashes 1.8.0 (esm/scrypt.js, MIT), copied verbatim — the build fails if those lines change — with WebCrypto's PBKDF2-HMAC-SHA-256 for its two one-iteration steps.
  • weirdlock.js: the format, decoder and encoder, on WebCrypto alone (AES-256-GCM, HKDF-SHA-256, HMAC-SHA-256, SHA-256, X25519). The application locks albums with this same file.
  • viewer.js: the page.

The build is deterministic: building the same source twice gives the same bytes, so a release rebuilt from its source commit can be compared with the table above. The three files stay within 96 KiB.

The rules it keeps#

  • Its own origin only. It runs when the album is the root of its origin: a hostname of the owner's domain, or the content's own address (<cid>.ipfs.<gateway domain>). On a path such as /ipfs/<cid>/ (a shared gateway, where every customer's pages share one origin), on a host named gateway.…, without HTTPS (except localhost), or inside a frame (window.top !== window.self; frame-ancestors cannot be set from a meta tag), it says why and reads nothing.
  • No other request. It fetches lock/keyring, lock/manifest and lock/b/<id> by relative address, without credentials, refusing redirects, and nothing else: no update check, no font, no analytics. Its policy: default-src 'none' with 'self' for scripts, styles and connections, blob: for decrypted images and media, base-uri 'none', form-action 'none'.
  • No storage. No cookie, localStorage, sessionStorage or IndexedDB, ever. The album key is a variable, zeroed on "lock again", after 15 minutes without use and when the page is left; every object URL is revoked then.
  • The format's decoder rules (§4.4, §7, §8, §10): the keyring parsed whole before any cryptography; ways in tried in order; the MAC verified with crypto.subtle.verify (constant time); streams checked against the expected kind and id, never the header's; a segment's plaintext used only after its tag verified, a file only after its whole stream authenticated, with its stored length and zero padding checked; the manifest parsed strictly (lowercase unique keys, one value, nesting at most 8) and validated as the reference does; every bound of §10.3. Failures are said in two messages (wrong password or key; damaged or altered) and never reported to a server.
  • Ways in. A password (with the scrypt cost the stanza names, 2^15 to 2^20); a link key from the address's fragment #k=… (then removed from the address bar and the current history entry with history.replaceState); a key file of the weird CLI (x25519_private) or a recovery kit, chosen on the device and read there. Person keys need X25519 in WebCrypto; without it the viewer says to use the CLI.
  • Memory. A file is decrypted whole into a Blob only up to a cap (512 MiB; 256 MiB on devices reporting 4 GB of memory or less, 128 MiB at 2 GB); a larger one is not fetched, and the viewer names the CLI command instead. Thumbnails are decoded by the browser's image decoder only.
  • not-after. After it, the viewer refuses to open and says the owner's date.
  • Languages. Romanian and English, chosen from the browser's languages, with a switch.

How it is tested#

  • In Node, on WebCrypto: every case of every test vector (positive and negative) decodes as recorded, with its class, slot and plaintexts; every positive vector is encoded again from its recorded random draws and matches byte for byte (keyring, manifest, every blob, the single file whole); one bit flipped in every byte of a locked file never opens it; scrypt matches RFC 7914's vectors and Node's own scrypt; round trips through every way in, padded and not; the manifest's strictness.
  • In headless Chromium: the same suite; then the built viewer opens an album with a password, a link, a key file and a recovery kit at 390 and 1280 pixels, downloads a file byte for byte, locks again with every object URL revoked, refuses a shared path and a frame, keeps to its cap and to not-after. Every request is intercepted (none leaves the album's origin), storage and cookies are watched (never touched), and content security policy violations fail the test.

scrypt at the default cost (2^17, r = 8) takes about 0.4 s in a browser on a recent laptop, longer on a phone, and needs 128 MiB of memory for that time.

Embedding it#

A program that writes locked albums (the weird CLI, the application) places the release in every album:

  1. Take the release by content: viewer.json (published at the download address, and the table above) lists each file's path, SHA-256 and size, the SRI values, the set's fingerprint and the source commit. Keep the three files of a pinned release and check each SHA-256 against it. The bootstrap names its release in <meta name="weirdlock-viewer" content="<release>"> and loads v/<release>/; both stay as they are for every release.
  2. When building an album folder, write index.html, v/<release>/viewer.js and v/<release>/viewer.css byte for byte, beside lock/. Never rewrite them (the SRI values in index.html bind the other two).
  3. Print the viewer's release and fingerprint with the album, so its owner can compare what is served with what was published.
  4. Offer to update an existing album's viewer: a new folder with the same lock/ and the new release, the hostname pointed at it.

Verifying a served copy#

The CLI reads an album's viewer files (never its encrypted part, so no password or key is asked), hashes them and says which release they are:

$ weird storage lock viewer verify <cid>$ weird storage lock viewer verify <cid> --gateway https://ipfs.example$ weird storage lock viewer show

verify exits 1 when the files match no release it knows (changed after the album was made, or newer than the program); with --gateway it reads a CID from any IPFS gateway, without an account. show prints the release the program puts in new albums, to compare with viewer.json. By hand: download the album (weird storage get <cid> -o ./album) and compare the SHA-256 of ./album/index.html, ./album/v/1/viewer.js and ./album/v/1/viewer.css with the table above. The browser itself refuses a changed script or stylesheet (Subresource Integrity); only index.html can be changed unnoticed by the browser, and it is small enough to read.