Skip to content

Digital Signature and Certificate verification - #21247

Merged
calixteman merged 1 commit into
mozilla:masterfrom
beurdouche:master
Jun 30, 2026
Merged

calixteman merged 1 commit into
mozilla:masterfrom
beurdouche:master

Conversation

@beurdouche

@beurdouche beurdouche commented May 9, 2026 •

Copy link
Copy Markdown
Member

This is an initial version of the feature off-by-default. A follow-up with a comprehensive treatment of the certificate revocation mechanisms should happen before this can be enabled by default.

@codecov-commenter

codecov-commenter commented May 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 23.97094% with 314 lines in your changes missing coverage. Please review.
βœ… Project coverage is 89.40%. Comparing base (25eae30) to head (07b1c62).

Files with missing lines Patch % Lines
web/digital_signature_properties_manager.js 2.02% 290 Missing ⚠️
src/core/document.js 89.77% 9 Missing ⚠️
web/app.js 55.00% 9 Missing ⚠️
src/display/api.js 0.00% 4 Missing ⚠️
src/core/worker.js 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21247      +/-   ##
==========================================
- Coverage   89.80%   89.40%   -0.40%     
==========================================
  Files         261      262       +1     
  Lines       66346    66758     +412     
==========================================
+ Hits        59581    59687     +106     
- Misses       6765     7071     +306     
Flag Coverage Ξ”
browsertest 66.51% <4.16%> (-0.11%) ⬇️
fonttest 9.03% <ΓΈ> (ΓΈ)
integrationtest 68.55% <5.32%> (-0.51%) ⬇️
unittest 57.31% <84.37%> (+0.03%) ⬆️
unittestcli 56.28% <84.37%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Harness.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@marco-c

marco-c commented May 11, 2026

Copy link
Copy Markdown
Contributor

Was UX/Content involved with this?

How is a user supposed to differentiate these signatures from the signatures PDF.js already supports? I find the use of the same terminology very confusing.

They were consulted and they didn't agree with this approach (the main reason being what you said here), so it's not going to be enabled in Firefox but only in Enterprise Firefox.

Comment thread src/core/document.js Resolved
Comment thread src/core/document.js Resolved
Comment thread web/firefoxcom.js Resolved
Comment thread web/signature_properties_manager.js Resolved
Comment thread web/signature_properties_manager.js Resolved
Comment thread web/signature_properties_manager.js Resolved
Comment thread web/signature_properties_manager.js Resolved
Comment thread web/signature_properties_manager.js Resolved
Comment thread test/pdfs/sig_corpus/generate.py Resolved
Comment thread test/pdfs/sig_corpus/README.md Resolved
Comment thread test/pdfs/sig_corpus/README.md Resolved
Comment thread web/digital_signature_properties.css Resolved
Comment thread web/digital_signature_properties.css Resolved
Comment thread web/signature_properties.css Resolved
Comment thread web/signature_properties.css Resolved
Comment thread web/signature_properties.css Resolved
Comment thread web/signature_properties.css Resolved
Comment thread web/firefoxcom.js Resolved
Comment thread web/signature_properties_manager.js Resolved
Comment thread l10n/en-US/viewer.ftl Resolved
Comment thread l10n/en-US/viewer.ftl Resolved
Comment thread l10n/en-US/viewer.ftl Resolved

@bcolsson bcolsson left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

Adds a new "Digital signature properties" doorhanger to the pdf.js
toolbar that lists every digital signature found in the opened PDF,
verifies each one (via NSS in the Firefox build through a new chrome
bridge), and shows per-signature status + certificate state.

The viewer side parses /Sig dicts in the worker
(`PDFDocument.signatures`), strict-validates the /ByteRange offsets
before slicing, and ships only signature metadata across the worker
boundary. The PKCS#7 blob and signed-data byte spans live in a
worker-side map and are fetched lazily one signature at a time via
a new `getSignatureData(id)` RPC, immediately before verification
runs, so the bytes never sit in main-thread memory for the
document's lifetime.

The panel is feature-gated by `pdfjs.enableSignatureVerification`
(true in MOZCENTRAL/TESTING, off by default in the GENERIC build).
External services expose a `createSignatureVerifier()` factory that
the Firefox build wires up to `nsIX509CertDB.asyncVerifyPKCS7Object`;
GENERIC builds return null and the toolbar button stays hidden.

UI summary:
- Toolbar button states: loading dots while in flight, then green
  check, orange `!`, or red `βœ•` based on the worst aggregate
  signature status.
- Doorhanger contains a banner summarising the document state, then
  one card per signature with status row + certificate row (sub-
  signatures nested under their outer revision via /ByteRange
  containment).
- Icons are mono SVGs themed via `mask-image` + `background-color`
  so they pick up light/dark/HCM via `--sig-icon-*` vars; flipped
  under RTL via `scaleX(var(--dir-factor))`. The HCM mapping reuses
  the alt-text vocabulary (ButtonFace / ButtonText / ButtonBorder /
  GrayText / AccentColor / LinkText) so this panel reads the same
  as the rest of the editor toolbar in high-contrast mode.
- All visible strings are localized via Fluent
  (`pdfjs-digital-signature-properties-*`); status row, banner, and
  certificate row use explicit lookup tables instead of generated
  ids so a grep finds them.
- Esc + outside-click close the panel through the viewer's existing
  handlers; the manager exposes `isOpen`, `close()`, and
  `shouldCloseOnClick(target)` for that.

This commit also adds a `test/pdfs/sig_corpus/` directory holding a
Python generator that produces a corpus of signed PDFs covering
every visible state of the doorhanger (verified / untrusted /
expired / invalid / unknown / multi-signature variants). The corpus
is intentionally NOT part of the automated test suite β€” it is a
manual-test tool. Generated `.pdf` files are gitignored; only the
generator, README, and a `user.js.example` snippet are tracked.
The generator shells out to mozilla-central's
`security/manager/tools/pycms.py` (resolved via `--mozilla-central
<path>` or the `MOZILLA_CENTRAL_SRC` env var) and the embedded test
trust anchors (`pdf-sign-ca` / `pdf-sign-ca-expired`), gated by
`security.pdf_signature_verification.enable_test_trust_anchors` so
the test certificates never validate in shipping Firefox.

@calixteman calixteman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

This branch was previously deployed

1 inactive deployment
code-coverage β€” 07b1c625 Deployed Jun 30, 2026 by beurdouche via Test (22) #16181
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement digital signature validation

8 participants