Skip to content

state_exec: sha256, sha256-hex and random-token builtins - #911

Merged
transfix merged 4 commits into
masterfrom
feat/state-exec-sha256-random
Oct 31, 2026
Merged

transfix merged 4 commits into
masterfrom
feat/state-exec-sha256-random

Conversation

@transfix

Copy link
Copy Markdown
Owner

For cypkg's OIDC sign-in by device pairing against cvcpkg:

  1. POST /v1/auth/device with verifier_hash, the hex SHA-256 of a random secret (cvcpkg's pairing.py: hashlib.sha256(verifier.encode()).hexdigest()).
  2. The user approves the code in a browser.
  3. The client polls /v1/auth/device/token with the verifier.

The DSL had no hash function, and its only randomness was math.random, which is not a CSPRNG.

Builtins

  • (sha256 x) and (sha256-hex x) hash a string's UTF-8 bytes, or a bytes value's octets.
    • They return 32 bytes, or 64 lowercase hex digits. Any other argument is a TypeError.
    • They reuse libcvc's cvc::sha256_hex (state_blob_store.h), so there is no new dependency.
    • (sha256-hex verifier) equals Python's hashlib.sha256(verifier.encode()).hexdigest().
  • (random-token nbytes ["base64url"|"hex"]) returns 1..256 bytes from the OS CSPRNG as text.
    • The default encoding is unpadded base64url (RFC 4648 §5); "hex" gives lowercase hex.
    • The bytes come from getentropy (Linux, macOS, POSIX), Emscripten's getentropy (crypto.getRandomValues), or rand_s on Windows.
    • A count outside 1..256 or an unknown encoding is a ValueError; a non-integer count is a TypeError.
  • None of the three is added to Ariadne's read-lane allowlist (bind:, visible_when:); the init: and action lanes get all three.

Tests

state_exec_builtins_test (73 pass locally) adds:

  • SHA-256 known answers ("", "abc", the 448-bit NIST message);
  • a string and the same bytes giving the same hash;
  • the raw digest's length and first and last octets;
  • token lengths and alphabets for 1, 2, 3, 31, 32, 33 and 256 bytes in both encodings, and two tokens differing;
  • argument errors.

state_exec_exceptions_test and ariadne_runtime_test also pass.

Docs: docs/STATE_EXEC_DEVELOPER_GUIDE.md, "Hashing and Secure Randomness".

- (sha256 x) / (sha256-hex x): the SHA-256 of a string's UTF-8 bytes or a bytes value,
  as 32 bytes or 64 lowercase hex digits (libcvc's own cvc::sha256_hex).
- (random-token nbytes ["base64url"|"hex"]): 1..256 bytes from the OS CSPRNG
  (getentropy; crypto.getRandomValues under Emscripten; rand_s on Windows) as
  unpadded base64url (default) or hex.
- Not in Ariadne's read-lane allowlist. Tests: NIST known answers, the raw digest,
  token lengths and alphabets, and argument errors. Docs: the developer guide.
transfix added a commit to cy-pca/cypkg that referenced this pull request Oct 30, 2026
Account > Sign in with a browser runs cvcpkg's device pairing, its OIDC
route for a terminal: a random verifier (random-token), its SHA-256 sent
to /v1/auth/device, the code and an absolute approval URL shown, and a
poll of /v1/auth/device/token at the server's interval (slow_down
honoured) with capture_auth taking the access and refresh tokens into
the host. Cancel stops it; a denied or expired code says so. main.ari
re-asks the host once a token is captured. Sign out revokes a paired
session on the server before forgetting it.

bin/cypkg keeps the sign-in in ari's credential store (--credential-store
cypkg, 0600) unless --no-remember. Pairing needs sha256-hex and
random-token (transfix/libcvc#911); CI now merges #911 and #912, and the
resolver keeps both sides of docs and test conflicts between open PRs.

The fixture plays the pairing endpoints, with /_approve standing in for
a person at /link; pairing_test.ari covers approve, revoke, deny, cancel.
transfix added a commit to cy-pca/cypkg that referenced this pull request Oct 30, 2026
…th a token or a browser (#6)

* Snappier search: facets only for a new query, prefetched pages, a progress bar

Next was slow because every page asked cvcpkg.org for facets, which
makes it count every match: 1.2 s for page 2 of everything and 2.4 s
for page 2 of zlib, against 0.2 s and 0.4 s without. Now only a new
query or filter asks for facets (the honest package count); paging
reuses that count. After showing a page the search module prefetches
the next one in the background and keeps the page it left, so Next and
Prev are answered with no request.

Requests wait in 50 ms slices (http-get-async and await with a
timeout), and between slices the module draws an indeterminate progress
bar at the bottom of its view; the package module does too. lib.ari
gains search-key, body-text and progress-bar, and search-query takes
facets.

The fixture logs its requests (/_requests) and answers a slow: name
after a second. Module tests show a new query asks for facets and
paging doesn't, Next and Prev make no request, and the bar draws during
a slow request and clears after; with prefetch disabled they fail.

* wip: windows

* Menu bar and windows: builders, builds, activity, account; API-token sign-in

A View menu opens a window per page the registry's site has: Builders,
Builds (by status, paged), Activity and Account, beside Search. Each is a
module in share/cypkg/, started when its window first opens, refreshing
about every 10 s while open (idle-wait answers a click at once), with a
progress bar at its bottom.

Signing in: bin/cypkg --token-env VAR hands a cvctok_ token to ari
(--credential-env, bound to the registry by a policy file for the run).
main.ari asks the host (has? works only at the top level) and hands
auth.* to the modules through a hole; every request then sends the token.
Account shows whoami and signs out; a refused token is dropped. Browser
sign-in (device pairing) waits on sha256-hex and random-token in libcvc.

net.ari holds fetch, now shared by every module, so lib.ari stays pure.
--progress off makes plain blocking requests, for a browser ari without
transfix/libcvc#914, which CI's browser build now merges. The fixture
serves builders, builds, activity and whoami; tests cover each module,
the account signed in and out, each window's frame, and opening Builders
from the View menu in FTXUI and tvision.

* Sign in with a browser: device pairing, remembered between runs

Account > Sign in with a browser runs cvcpkg's device pairing, its OIDC
route for a terminal: a random verifier (random-token), its SHA-256 sent
to /v1/auth/device, the code and an absolute approval URL shown, and a
poll of /v1/auth/device/token at the server's interval (slow_down
honoured) with capture_auth taking the access and refresh tokens into
the host. Cancel stops it; a denied or expired code says so. main.ari
re-asks the host once a token is captured. Sign out revokes a paired
session on the server before forgetting it.

bin/cypkg keeps the sign-in in ari's credential store (--credential-store
cypkg, 0600) unless --no-remember. Pairing needs sha256-hex and
random-token (transfix/libcvc#911); CI now merges #911 and #912, and the
resolver keeps both sides of docs and test conflicts between open PRs.

The fixture plays the pairing endpoints, with /_approve standing in for
a person at /link; pairing_test.ari covers approve, revoke, deny, cancel.

* CI: read ari's outputs before grepping them, so grep -q can't SIGPIPE the writer
nicotina-ci added 3 commits October 30, 2026 19:42
# Conflicts:
#	src/cvc/tests/state_exec_builtins_test.cpp
# Conflicts:
#	docs/STATE_EXEC_DEVELOPER_GUIDE.md
# Conflicts:
#	docs/STATE_EXEC_DEVELOPER_GUIDE.md
@transfix
transfix merged commit 23db22b into master Oct 31, 2026
27 checks passed
@transfix
transfix deleted the feat/state-exec-sha256-random branch October 31, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant