Repository navigation
Web & UI: local system font loading via Local Font Access API and ribbon integration - #386
GhostMitra wants to merge 2 commits into
Conversation
… P-521, brainpool, PSS, rsa_sha1) (storytold#386) * M9: more signature validation algorithms Validation now reads what real signers write, and says when it is weak: - Digests SHA-224, SHA-512/224, SHA-512/256, SHA3-224/256/384/512 and RIPEMD-160, beside SHA-1 and SHA-2. - RSA PKCS#1 v1.5 for every digest, in `rsa_pad`: the one expected encoding is built and compared byte for byte, with or without the DigestInfo's NULL (RFC 8017 App. B.1). A signature over the bare digest, which doesn't say which hash it uses, is refused. The signature value must be below the modulus (RFC 8017 §5.2.2); s and s + n both verified before. - RSA-PSS with the hash, MGF1 hash and salt length the signature declares. - ECDSA as DER, non-minimal DER or raw r||s on P-256, P-384, P-521 and brainpoolP256r1/P384r1/P512r1 (BSI "plain" ECDSA OIDs too); brainpoolP512r1 is hand-written on crypto-bigint because no RustCrypto crate has it. - Ed25519 (RFC 8419), and the legacy adbe.x509.rsa_sha1 format. - An algorithm PdfCraft can't check is Unknown, never Invalid. - SHA-1 and RIPEMD-160 signatures validate, but the signature's details say the algorithm is weak (wording pinned by tests). - Encoding irregularities that were tolerated are listed in the details (`verify_noting`; `verify` keeps its signature). Found while testing, each with a regression test that failed before the fix: a brainpoolP512r1 public key with a coordinate >= p panicked inside crypto-bigint's `sub_mod` (the certificate comes from the PDF); it is refused now, and the point at infinity is an invalid signature, not an error. Vectors were made with OpenSSL (tests/data/README.md has the commands). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> * Update comment to clarify MAC digest restrictions Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * M9: a legacy x509.rsa_sha1 signature whose key the verifier rejects is Invalid; only unsupported keys are "can't check yet" Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Brandon Thomas <echelon@gmail.com>
…old#690) storytold#646 fixed the Windows build after storytold#386 with `_` arms in the two matches in windows.rs. That module is cfg(windows), so Linux and macOS CI never compile it, and the next PublicKey variant will either break the Windows build again or, now, fall into `_` without anyone choosing. The store's two decisions move into keys.rs, which every platform builds, with every variant named and no `_` arm: - PublicKey::store_signing_key: RSA, or ECDSA with 256/384 bits, or None for the kinds PdfCraft only verifies with (P-521, brainpool, Ed25519, Unsupported). - PublicKey::store_signature_der: CNG's raw r||s as DER (RSA as is); the verify-only kinds return SignError::Unsupported, as since storytold#646. windows.rs calls both, with no `_` arms left. Behaviour is unchanged. tests/store_keys.rs runs everywhere: every variant's answer (with an exhaustive match, so a new variant must be added to it), the P-256 and P-384 conversion round-tripped through PublicKey::verify (code that used to compile only on Windows), and malformed CNG signatures erroring rather than panicking. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…torytold#694) (storytold#742) * Sign: decide Windows store keys in code every platform builds storytold#646 fixed the Windows build after storytold#386 with `_` arms in the two matches in windows.rs. That module is cfg(windows), so Linux and macOS CI never compile it, and the next PublicKey variant will either break the Windows build again or, now, fall into `_` without anyone choosing. The store's two decisions move into keys.rs, which every platform builds, with every variant named and no `_` arm: - PublicKey::store_signing_key: RSA, or ECDSA with 256/384 bits, or None for the kinds PdfCraft only verifies with (P-521, brainpool, Ed25519, Unsupported). - PublicKey::store_signature_der: CNG's raw r||s as DER (RSA as is); the verify-only kinds return SignError::Unsupported, as since storytold#646. windows.rs calls both, with no `_` arms left. Behaviour is unchanged. tests/store_keys.rs runs everywhere: every variant's answer (with an exhaustive match, so a new variant must be added to it), the P-256 and P-384 conversion round-tripped through PublicKey::verify (code that used to compile only on Windows), and malformed CNG signatures erroring rather than panicking. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Sign: smart cards and tokens in the Windows store ask for their PIN (storytold#694) Signing with a Windows store identity whose key lives on a smart card or USB token failed with NTE_SILENT_CONTEXT (0x80090022) and no PIN dialog. `identities()` acquires each key with CRYPT_ACQUIRE_SILENT_FLAG so that listing never prompts, and signing reused that handle after `set_silent(false)`. That only drops NCRYPT_SILENT_FLAG from NCryptSignHash: a provider handle that was opened silently stays silent, so a card that needs its PIN refuses instead of asking. `WindowsKey` now keeps the certificate context and acquires a fresh, non-silent key handle when it signs, so the provider can show its own dialog. Listing is unchanged and still silent. Reproduced and checked by hand with a qualified certificate on a SafeNet token (SafeNet Smart Card Key Storage Provider, RSA-2048): 0.5.0 fails with 80090022, this build shows the SafeNet PIN dialog and signs. The software-key round trip (`signing_with_windows_store_identities`, --ignored) still passes on Windows 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Sign: a Windows store identity signs with its issuers A digital ID file brings its certificate chain and the signature embeds it; a Windows store identity signed with its own certificate only. A certificate issued by an intermediate CA (the usual case on a token) then validates only where the reader already has that CA. `windows::find`, which fetches the identity to sign with, now fills `chain` with the certificates Windows chains it to, without the root. `identities()` still builds no chains, so listing stays fast and local. A chain that can't be built leaves `chain` empty, as before. Test `a_windows_store_identity_signs_with_its_issuers` (--ignored, like the other store test): a temporary root, issuer and signer; the signature validates against the root alone. The cleanup guard now also removes the public copy New-SelfSignedCertificate leaves in Intermediate Certification Authorities, which the existing test left behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: James Locke <336218001+jcl-bit@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: mmmaarian03-crypto <253881360+mmmaarian03-crypto@users.noreply.github.com> Co-authored-by: Brandon Thomas <echelon@gmail.com>
FredApps
left a comment
There was a problem hiding this comment.
ReviewerA — source-read COMMENT (not an approval)
I read the head of the diff: the web build loads local system fonts through the Local Font Access API and adds ribbon integration. Statics hold a JS array of fonts and a set of families being fetched (OnceLock<RwLock<HashSet<String>>>). The Local Font Access API needs the user's permission and is only in Chromium, so the code must work without it and must not prompt on load; the font data it returns is untrusted, and a font's licence for embedding (the fsType flags) must be honoured when a document is exported with it. Exposing the installed font list to a web page is a fingerprinting surface, and the permission prompt is the browser's protection, which the PR should not bypass. It overlaps deckcraft#1040 (fonts from a host manifest) and both add deckcraft-fonts to the web crate. I have not run it, and no exact-head CI result exists for this head. Nothing was run.
I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.
Status: waiting_author.
aiongg
left a comment
There was a problem hiding this comment.
AI-generated review (Opus). Not a maintainer decision.
Changes needed:
This adds on-demand loading of local system fonts in the web build, a truncated font name in the ribbon, and a contributor entry. As submitted the code does not compile, and listing a family without loading it changes how missing fonts are substituted.
- crates/ui-egui/src/ribbon.rs:509: the
if can_load {block is never closed, so the dropdown closure at :523 does not parse. - crates/fonts/src/lib.rs:435: the new test
web_catalog_registrationhas no closing brace beforewrap_eot, so the fonts crate does not parse. - crates/fonts/src/fontdb.rs:1088:
has_familynow returns true for a family that is only listed and has no bytes loaded yet. Because of that,document_face(fontdb.rs:1054) skips the metric-compatible stand-ins and draws the default face.face_chainin crates/text/src/lib.rs:505 also pushes that substitute face, and the missing-font notice in crates/engine/src/fonts.rs:30 no longer reports the family. Consider keeping web-listed families out ofhas_familyuntil faces are loaded, and showing them only infamilies(). - apps/deckcraft-web/src/web.rs: if a blob fetch fails, the family stays in
FETCHING_FAMILIESand is never tried again. Removing it on failure would allow a retry. - crates/ui-egui/src/widgets.rs:
truncate_with_ellipsismeasures with a fixed 12-point font that may not match the dropdown's font. It also lays out the text once per character on every frame. - The dropdown truncation and the contributors/people.toml entry are separate from font loading and would be easier to review as their own changes.
Claims checked:
- verified: Local font access is requested only when the user clicks the Load System Fonts button (apps/deckcraft-web/src/web.rs: queryLocalFonts is called only inside load_action, which runs only from the button at crates/ui-egui/src/ribbon.rs:511-513)
- verified: Only family names are indexed at scan time; font bytes are fetched on demand when picked or used in the open presentation (apps/deckcraft-web/src/web.rs: setup_system_fonts collects family strings and calls register_web_families; fetch_family_blobs is called from crates/ui-egui/src/ribbon.rs:499-50…
- contradicted: Unloaded or missing fonts safely fall back to open metrics/substitutes (crates/fonts/src/fontdb.rs:1088 makes has_family true for listed web families with no faces. document_face at crates/fonts/src/fontdb.rs:1054 then returns face() and skips office_twin/metric-twin substitution, and crates/engine…
- verified: No panic risk (apps/deckcraft-web/src/web.rs: every JS call goes through Reflect::get/dyn_into with let-else or ok(); locks use unwrap_or_else(into_inner). crates/fonts/src/fontdb.rs:1088 does the same)
- contradicted: cargo fmt, tests, clippy and the wasm checks passed (crates/ui-egui/src/ribbon.rs:509 opens
if can_load {without closing it before});at :523. crates/fonts/src/lib.rs:435 ends the test without a closing brace before fn wrap_eot at :436. Neither crate can parse) - verified: The ribbon font dropdown truncates long family names with an ellipsis (crates/ui-egui/src/ribbon.rs:487 passes truncate_with_ellipsis(ui, &font, 130.0) as the dropdown label; crates/ui-egui/src/widgets.rs adds the helper (it measures with a fixed 12-point proportional font))
Recommendation: update the pull request; it will be reviewed again.
Reviewed at c274107.
Port of storytold/gridcraft#393 to DeckCraft.
Summary
queryLocalFonts()) is requested exclusively when the user explicitly clicks the "Load System Fonts?" button in the ribbon font picker dropdown.FontDb::register_web_families. Binary font blobs are fetched asynchronously viafont.blob()andarrayBuffer()only on demand when selected from the dropdown or actively used in the open presentation (SlideApp::used_fonts()).FontDb::global().add_font(bytes). Unloaded or missing fonts safely fall back to open metrics/substitutes without panicking.truncate_with_ellipsisin ribbon dropdown to prevent long font family name text overflow.contributors/people.toml.Verification
cargo fmt --checkpassed.cargo test -p deckcraft-fonts -p deckcraft-engine -p deckcraft-ui-eguipassed (all 143 unit tests passed).cargo run -p xtask -- wasmpassed (all 23 crates passedwasm32-unknown-unknowncheck).cargo check --target wasm32-unknown-unknown -p deckcraft-webpassed.cargo clippy -p deckcraft-fonts -p deckcraft-ui-egui -p deckcraft-web -- -D warningspassed (0 warnings).