package main // Exhibit 26. The zoo seals a postcard the way any app would with storage's sealing block: the page // loads rc-crypt.js and rc-seal.js from storage (pinned by hash), the key is made and kept in the // browser (wrapped to the root storage's window hands over, never this server), the words are sealed // there into an envelope, and the envelope goes through the public paths: app/begin, a PUT straight // to B2, app/commit, app/urls. This server only forwards (/api/26/storage, below) and never sees a // key. The self-check plays the person's browser in Odin (robotseal.odin, seal.odin). import "core:encoding/json" import "core:fmt" import "core:strings" import "ratcloud:rc" // storage's scripts, by hash: a page that runs whatever storage serves would run whatever storage's // server says; pinned, a changed file is refused and this card says so. SEAL_JS := [2][2]string { {"rc-crypt.js", "sha384-bC+ArqaU/QjwcbSzAMUu6nMqClMDFOG4cHed3KFtzzYt052HX2z+hJ0Timbw2yoX"}, {"rc-seal.js", "sha384-9iwPEKMkzo7FSo5YaKL+wOCJSA+zaGiotVBJcMkzBnGex/wljIj/v1Nkz5mHu2rF"}, } POSTCARD_MAX :: 65536 // the zoo seals postcards of words, nothing bigger, into a person's storage E26_Data :: struct { id: i64 `json:"id"`, size: int `json:"size"`, at: i64 `json:"at"`, head: string `json:"head"`, words: int `json:"words"`, sealcheck: json.Value `json:"sealcheck"`, amber: bool `json:"amber,omitempty"`, } e26 :: proc() -> Exhibit { return { n = 26, try_ = "seal a postcard", wing = "Sealed", title = "Sealed means sealed", promise = "A file an app seals for you opens on your devices and nowhere else; the server keeps only what it cannot read.", block = "storage's sealing block: rc-crypt.js and rc-seal.js (https://storage./seal/v1/) seal in the browser with a key only your devices and your recovery key open; the app's server forwards keyring calls and stores envelopes it cannot read.", src = {"e26_sealed.odin", #load("e26_sealed.odin", string)}, files = srcs({"bulk.odin", #load("bulk.odin", string)}, {"robotseal.odin", #load("robotseal.odin", string)}, {"seal.odin", #load("seal.odin", string)}), script = {"web/e26.js", #load("web/e26.js", string)}, show = proc(me: ^rc.User) -> string { d, s, found := stored_data(26, E26_Data) last := "" if found && s.ok do last = fmt.tprintf(`

The self-check seals a fresh postcard for the robot each time, %s: %d bytes in the bucket, none of them its words.

`, ago(s.at), d.size) if me == nil do return cat(signin_line("to seal a postcard only your devices can open."), last) tags := strings.builder_make() for f in SEAL_JS do rc.render_to(&tags, ``, {{"1", rc.app_url("storage")}, {"2", f[0]}, {"3", f[1]}}) return cat(strings.to_string(tags), fmt.tprintf(`

Loading…

`, me.id), last) }, // The app's own route to storage for its page: keyring calls as they are; begin only for the // postcard, sealed; commit and urls as they are. Storage checks the person and the folder. api = proc(a: ^Api) -> bool { if a.do_ != "storage" || !a.post do return false if a.me == nil {reply_err(a, 401, "sign in first"); return true} op := in_str(a, "op") body := jget(a.in_, "body") if _, isobj := body.(json.Object); !isobj do body = json.Object{} switch op { case "keyring", "commit": case "begin": f := jarr(body, "files") if len(f) != 1 || jstr(f[0], "path") != POSTCARD || jstr(f[0], "type") != ENV_TYPE || jint(f[0], "size") > POSTCARD_MAX {reply_err(a, 400, "the zoo saves one sealed postcard, at most 64 KB"); return true} case "urls": body = parse(fmt.tprintf(`{{"paths":[%s]}}`, jq(POSTCARD))) case: reply_err(a, 400, "no such call") return true } s, r := storage_call(op, to_json(body)) // storage's answer as it is, with its status reply_raw(a, to_json(r), s if s != 0 else 502) return true }, check = proc() -> Check { s, err := robot_sealing() if err != "" do return fail(err) k, kr, kerr := robot_zoo_key(&s) if kerr != "" do return fail(kerr) words := postcard_words() file, env_, perr := robot_seal_postcard(k, words) if perr != "" do return fail(perr) _, held, berr := robot_postcard_bytes() if berr != "" do return fail(berr) sp := strings.last_index_byte(words, ' ') word := words[sp + 1:len(words) - 1] if !eq_bytes(held, env_) do return fail("the bucket holds other bytes than the robot sealed") if string(held[:4]) != "RCE1" do return fail("the stored object does not start with an envelope header") if strings.contains(string(held), word) || strings.contains(string(held), "robot") do return fail("the stored bytes contain the words") Keys :: struct { id: string, k: []u8, } ks := Keys{kr.mk_id, k} key_for :: proc(id: string, arg: rawptr) -> []u8 {x := (^Keys)(arg); return x.k if id == x.id else nil} back, oerr := envelope_open(key_for, &ks, held) if oerr != "" do return fail(cat("the robot's own device cannot open what it sealed: ", oerr)) if string(back) != words do return fail("the robot's device opened other words than it sealed") wrong := Keys{kr.mk_id, random_bytes(32)} if _, werr := envelope_open(key_for, &wrong, held); werr == "" do return fail("a key that is not the robot's opened the postcard") // Back of house (ST-2): last night's sample of sealed objects, each starting with an envelope header. scr := rc.fetch({url = cat(rc.app_url("storage"), "/sealcheck.json"), timeout_ms = 10_000}) sc := parse(string(scr.body)) night := "the nightly header check has not run yet" ran := jhas(sc, "at") && jbool(sc, "at") if ran do night = fmt.tprintf("last night's header check: %d of %d sealed objects sampled, every one an envelope", jint(sc, "sampled"), jint(sc, "sealed")) if jbool(sc, "ok") else fmt.tprintf("last night's header check found %d sealed object(s) without an envelope header", jint(sc, "bad")) data := E26_Data{jint(file, "id"), len(held), jint(file, "updated"), hex(held[:24]), len(words), sc, false} if ran && !jbool(sc, "ok") do return fail(night, data) if ran && now() - jint(sc, "at") > 26 * 3600 do data.amber = true return pass(fmt.tprintf("sealed %d characters for the robot into a %d-byte envelope (Apps/Zoo/sealed/postcard.rce, file %d): the bucket's bytes hold none of the words and open only with the robot's key; %s", len(words), len(held), jint(file, "id"), night), data) }, } }