Skip to content

feat(signing): CSC v1 synthetic laboratory workflow and signer UI - #9659

Draft
vitormattos wants to merge 108 commits into
mainfrom
feat/9602-csc-v1-runtime-20261122
Draft

vitormattos wants to merge 108 commits into
mainfrom
feat/9602-csc-v1-runtime-20261122

Conversation

@vitormattos

@vitormattos vitormattos commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Resolves: #9599, #9600, #9602, #9603, #9604

📝 Summary

Add the CSC v1 remote-signing workflow to LibreSign's existing signer experience. An authorized signer, including an invited guest, can discover policy-eligible signing providers, choose a remote certificate and PDF/PAdES format, prepare a signing session, follow its state and complete a signature through the native LibreSign signing request. This PR supports approved synthetic CSC laboratory credentials; it does not claim personal production signing or substitute a shared administrator token for signer consent.

The backend enforces system, group and account policy scopes, signer authorization, document revision binding, idempotent session transitions, and cryptographic validation before publishing the PDF. The separate administrative provider/policy UI is in #9665; the shared driver/OCS foundation was merged in #9611. This PR consolidates the signer-facing UI previously developed in #9695.

🧪 How to test

  1. In an isolated Nextcloud 36 installation with LibreSign configured and the external-signing feature enabled, create a signature request for a verified account signer or an email-invited guest.
  2. Open the existing Sign document screen and expand External signing. Verify that only the signing request's supported identity methods can authorize provider discovery.
  3. Select an integration eligible under the effective system/group/account policy, then select a backend-provided certificate and its supported PDF Basic or PAdES B-B profile.
  4. Prepare the signature and inspect the session states. Continue an authorized session, then check the validated PDF, the native signing-request state and subsequent signer activation.
  5. Test revoked authorization, unavailable providers, changed PDF revisions, duplicate attempts and unknown remote outcomes. An uncertain signature must not be submitted automatically a second time.
  6. Check the same controls in a 390 × 844 mobile viewport, including visible status and error guidance.

Validation evidence

  • Focused unit and integration tests, including session concurrency, authorization, publication and frontend state transitions.
  • Relevant PHP-CS, syntax, Psalm, TypeScript, ESLint and frontend build checks.
  • PHP/Behat coverage across SQLite, MariaDB, MySQL and PostgreSQL, plus Playwright and Node checks.
  • 21/21 GitHub workflows passed at cf53359e before the UX/provider-compatibility changes; the current HEAD must pass its own CI before merge.
  • Independent acceptance with a real personally authorized production CSC credential — not included in this synthetic-laboratory scope.

🎨 UI / Front-end changes

  • Sign with a digital certificate appears in the existing native signer panel, without replacing the normal signing flow.
  • Account and email verification paths, provider/certificate selection, PDF profile choice, preparation and status refresh.
  • Explicit handling for uncertain remote outcomes, without a misleading success state or automatic re-submission.
  • Inline Chromium screenshots attached directly to this PR from the current signer Vue UI show native, accessible choice cards for short lists, compact fallbacks, email verification, PDF options and safe status states. Earlier real Nextcloud 36 navigation capture remains contextual.

CSC signer UX — visible choices, concise language and mobile review (2026-11-25)

Signer journey Updated screenshot
1. Native Sign document entry (previous real Nextcloud 36 navigation capture) Native LibreSign signer sidebar
2. Identity method choices are visible Choose an identity verification method
3. Guest email verification Guest email code
4. One eligible provider and certificate preselected Only eligible service and certificate
5. Two to five providers: visible, selectable radio cards Choose a signing service
6. A selected service reveals its certificate Service selected and certificate loaded
7. Two to five certificates: radio cards with expiration dates Choose an eligible digital certificate
8. Certificate chosen explicitly; technical details optional Certificate selected
9. Advanced PDF options without unexplained PAdES labels Advanced signature format settings
10. Mobile service options, actual 390×844 viewport Mobile list of eligible services
11. Mobile certificate options, actual 390×844 viewport Mobile list of certificates
12. Awaiting approval at signing service Pending signer authorization
13. Uncertain outcome: status recheck, no duplicate submission Uncertain result with safe status action
14. Mobile certificate details (390 × 844 viewport) Mobile single certificate
15. Compact selection with 6 signing services Six services dropdown
16. Compact selection with 6 certificates Six certificates dropdown
17. Prepared signature awaiting explicit authorization Ready to sign

Behavior: one eligible service/certificate is automatically selected; for 2–5 authorized choices, the signer sees native Nextcloud Vue radio cards with names (and certificate expiry dates); 6+ options fall back to a compact select. Multiple options require an explicit selection before preparing the signature. A temporary certificate-lookup failure offers a safe retry. Existing signing status reconciliation and idempotency remain unchanged.

All screenshots above are uploaded as GitHub PR attachments and are not stored in the repository.

The first image is an older real Nextcloud 36 navigation screenshot; it is not a 'before' screenshot of the new service-selection UI. All other images were freshly rendered in Chromium from the actual updated signer Vue component at source revision 31905f681decaa8a5c823c4f64ed626ef6210914 with Nextcloud Vue styles and synthetic account, service, certificate, code and session fixtures. The screenshots are component UI evidence only, not proof of full Nextcloud browser integration, signer-bound OAuth/SAD authorization, or a production cryptographic signature. The states and visual checks are described here; screenshots are PR attachments, not source files.

Focused verification: 35 Vitest tests passed; TypeScript, ESLint, Stylelint, translator hints and production build passed. Browser checks verified click selection, keyboard ArrowDown for both groups, responsive layouts, and absence of unhandled browser errors. End-to-end CSC authorization remains outside this component-preview evidence.

Separate CSC protocol interoperability evidence (not a UI mock):

  • Independent pdfsig verification of external CSC development-stub PDF — independent PAdES B-B verification screenshot — produced by SignerPHP from the exact CMS digest signed through a CSC v1 OAuth/SAD flow. Independent pdfsig verification reported Signature is Valid, ETSI.CAdES.detached, SHA-256, and Certificate issuer is unknown (test certificate, not qualified, not production identity).
  • Reproducible, opt-in development scripts: tests/interop/csc/README.md (no OAuth credentials committed).
  • A read-only admin CSC protocol probe identifies reachable CSC v1.0.4 vs v2.2 servers but always reports personalSigningReady=false until a real signer-bound OAuth callback and credential authorization are integrated.
  • Critical scope of the real cryptographic proof: the public Cleverbase stub does not validate SAD-to-hash binding or consent; the resulting cryptographic signature was independently verified against the actual PDF digest. The current bundled CSC adapter calls credentials/authorize instead of Cleverbase's two browser OAuth authorization-code flows. Consequently this is not evidence that the LibreSign signer web flow supports personal CSC signing yet. See tests/interop/csc/README.md.
  • UX follow-up: the refreshed component screenshots explicitly show automatic selection for a single eligible provider and certificate, while retaining a selector when multiple providers are available.

Still required for real personal CSC signing: registered OAuth client, short-lived signer-bound state and callback, single-use authorization and hash-bound SAD, consent/credential selection with the selected provider, error/recovery integration, and a trusted certificate-chain policy. The existing synthetic execution guard remains intentionally active. Do not present the external stub proof as a personal/qualified signature.

  • Desktop and mobile Chromium UI captured and inspected.
  • Focused Vitest and Playwright regression coverage for signer flow.
  • Independent accessibility and design review (plain-language component copy updated; user testing and full Nextcloud browser acceptance still required).
  • Documentation draft: LibreSign/documentation#185.

🚧 Tasks

  • Complete independent review of the signer-facing UI and the synthetic provider acceptance path before merging.

⚙️ API / Back-end changes

  • CSC v1 integration, guarded outbound HTTP adapter and operator-pinned synthetic credential eligibility.
  • Signer/request binding for account and guest authorization; provider scope checked before credential enumeration and continuation.
  • Durable session lifecycle with encrypted continuation data, atomic transitions, revision checks and no blind signHash retries.
  • PDF reconstruction, signature validation, immutable publication and native request/next-signer updates, including rollback and reconciliation tests.
  • Administrative scope and policy delegation for system, group and account integrations, with server-side access checks.
  • OpenAPI and generated TypeScript contracts updated from the backend declarations.

🚧 Tasks

  • Final human security/architecture review, including whether the synthetic CSC boundary meets the intended acceptance criteria.

✅ Checklist

  • I have read and followed the contribution guide.
  • Changes relate to the CSC implementation and its regression coverage.
  • Commits follow Conventional Commits.
  • All commits include the required DCO sign-off and verified signatures.

🤖 AI (if applicable)

  • The content of this PR was partially or fully generated using AI.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@vitormattos vitormattos changed the title feat(signing): integrate experimental CSC v1 adapter (#9602) feat(signing): CSC runtime and signer workflow integration (#9602, #9600, #9603) Nov 23, 2026
@vitormattos vitormattos added the backend Backend work label Nov 23, 2026 — with ChatGPT Codex Connector
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…ms (#9600)

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…9600)

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…#9611)

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
#9611)

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@vitormattos vitormattos changed the title feat(signing): CSC runtime and signer workflow integration (#9602, #9600, #9603) feat(signing): CSC adapter and persistent signing sessions (#9602, #9600) Nov 23, 2026
Base automatically changed from feat/9595-external-provider-catalog-20261121 to main November 23, 2026 22:55
…ion (#9611)

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Code Metrics Report

Note: Metrics describe the revision analyzed by the successful PHPUnit run. Newer commits with pending, canceled or failed checks may not yet be represented in this report.

main (878d2bf) #9659 (ede8f6a) +/-
Coverage 78.1% 78.8% +0.7%
Test Execution Time 3m52s 4m56s +1m4s
Details
  |                     | main (878d2bf) | #9659 (ede8f6a) |  +/-  |
  |---------------------|----------------|-----------------|-------|
+ | Coverage            |          78.1% |           78.8% | +0.7% |
  |   Files             |            537 |             565 |   +28 |
  |   Lines             |          29818 |           31040 | +1222 |
+ |   Covered           |          23303 |           24489 | +1186 |
- | Test Execution Time |          3m52s |           4m56s | +1m4s |

Code coverage of files in pull request scope (82.8% → 90.3%, patch 92.9%)

Details
Files Coverage +/- Patch Coverage Status
apps/libresign/lib/Activity/Listener.php 74.8% +22.5% - affected
apps/libresign/lib/Events/SignedEventFactory.php 94.1% +23.5% - affected
apps/libresign/lib/Listener/MailNotifyListener.php 87.8% +0.9% - affected
apps/libresign/lib/Listener/TwofactorGatewayListener.php 89.6% +13.7% - affected
apps/libresign/lib/Service/IdentifyMethodService.php 85.3% +0.4% - affected
apps/libresign/lib/Service/Signature/PdfSignatureValidationService.php 83.4% +0.5% - affected
lib/AppInfo/Application.php 0.0% 0.0% - modified
lib/Controller/ExternalSigningDriversController.php 100.0% 0.0% 100.0% modified
lib/Controller/ExternalSigningIntegrationsController.php 96.0% -1.7% 90.0% modified
lib/Controller/ExternalSigningWorkflowController.php 83.6% +83.6% 83.6% added
lib/Exception/ExternalSigningAccessDeniedException.php 0.0% 0.0% - added
lib/ResponseDefinitions.php 0.0% 0.0% - modified
lib/Service/Signing/External/Authorization.php 97.2% +97.2% 97.2% added
lib/Service/Signing/External/AuthorizedRequest.php 100.0% +100.0% 100.0% added
lib/Service/Signing/External/ContextFactory.php 100.0% +100.0% 100.0% added
lib/Service/Signing/External/ContinuationCodec.php 82.3% +82.3% 82.3% added
lib/Service/Signing/External/CredentialSelection.php 91.6% +91.6% 91.6% added
lib/Service/Signing/External/DocumentRevision.php 100.0% +100.0% 100.0% added
lib/Service/Signing/External/DocumentSource.php 78.5% +78.5% 78.5% added
lib/Service/Signing/External/ImmutableArtifactStore.php 90.4% +90.4% 90.4% added
lib/Service/Signing/External/IntegrationScopeAccess.php 93.0% +93.0% 93.0% added
lib/Service/Signing/External/LaboratoryFactory.php 89.4% +89.4% 89.4% added
lib/Service/Signing/External/PreparedStateCodec.php 100.0% +100.0% 100.0% added
lib/Service/Signing/External/Publication.php 100.0% +100.0% 100.0% added
lib/Service/Signing/External/PublicationCommitter.php 96.5% +96.5% 96.5% added
lib/Service/Signing/External/PublicationContext.php 100.0% +100.0% 100.0% added
lib/Service/Signing/External/PublicationEvents.php 100.0% +100.0% 100.0% added
lib/Service/Signing/External/PublicationNotifications.php 0.0% 0.0% - added
lib/Service/Signing/External/PublicationPreparation.php 0.0% 0.0% - added
lib/Service/Signing/External/PublicationPreparer.php 95.8% +95.8% 95.8% added
lib/Service/Signing/External/PublicationTransaction.php 0.0% 0.0% - added
lib/Service/Signing/External/SessionState.php 100.0% +100.0% 100.0% added
lib/Service/Signing/External/SessionStore.php 92.5% +92.5% 92.5% added
lib/Service/Signing/External/Workflow.php 90.1% +90.1% 90.1% added
lib/Service/Signing/ExternalIntegrationAdministration.php 100.0% 0.0% 100.0% modified
lib/Service/Signing/ExternalIntegrationRecord.php 100.0% 0.0% 100.0% modified
lib/Service/Signing/ExternalIntegrationStore.php 96.7% -1.1% 97.4% modified
lib/Service/Signing/Provider/Drivers/Csc/CscCredentialEligibility.php 93.9% +93.9% 93.9% added
lib/Service/Signing/Provider/Drivers/Csc/CscDriver.php 100.0% 0.0% - modified
lib/Service/Signing/Provider/Drivers/Csc/CscIntegration.php 94.0% +94.0% 94.0% added
lib/Service/Signing/Provider/Drivers/Csc/NextcloudHttpTransport.php 93.0% +93.0% 93.0% added
lib/Service/Signing/SyntheticCscSigningOperation.php 89.8% +89.8% 89.8% added

Reported by octocov

…#9600)

Prevent administrative updates, disablement and deletion while signing
sessions are unresolved. Serialize session creation and administration on
the configured integration row to eliminate the check/insert race.
Add regression coverage for pending and uncertain sessions and release
of the administrative guard after rejection.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…#9600)

Restore ExternalIntegrationConflictException from merged foundation, which
was inadvertently omitted from the CSC branch. Guard all integration
revision updates while external signing sessions remain unresolved,
including redundant enable requests. Verify the regression against a
real disposable Nextcloud 36 SQLite instance (99 tests, 378 assertions).

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…9600)

Add provider-neutral read-only lookup for the one durable signing
session bound to a server-authorized actor and SignRequest. This
supports resume after reload or a new PHP worker without client-owned
prepared state or replaying an uncertain private-key submission.

Require explicit feature gating and context validation. Cover signer
and request isolation, uncertainty, and negative access paths.

Validated on isolated Nextcloud 36 and SQLite: 103 focused integration
tests, 412 assertions.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…9603)

Add a strictly laboratory-only orchestration service using SignerPHP
v0.5.1 and persisted, actor-bound signing sessions. Recheck the pinned
certificate, document and integration before reserving signHash once;
classify ambiguous provider failures as UNCERTAIN, never auto-retry.

Complete and cryptographically validate PDF Basic / PAdES B-B before
reserving publication; provide recovery of validated bytes without a
second publication reservation. Production CSC tokens remain blocked.

Validated in disposable Nextcloud 36 with synthetic CSC: 168 focused
PHPUnit tests, 1464 assertions, including prior signatures, DocMDP,
access denial, timeout/retry, and certificate/document substitution.
File publication and signer-facing endpoints remain separate work.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Use a database unique constraint on SignRequest ID independently of the
current actor identity, preventing duplicate external-signing attempts
when a guest authenticates through another context. Keep actor-bound
session discovery private and return only a redacted conflict to a
competing actor. Add an upgrade-safe, non-destructive migration.

Reproduced duplicate actor sessions before the fix and verified the
migration and 169 focused Nextcloud 36 SQLite tests (1469 assertions).

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…9599)

Create a server-side authorization context bound to the SignRequest and
current IUserSession. Enforce the experimental gate, existing signer and
workflow validators, exact identity method/value binding and signing
credential verification. A guest invitation UUID alone cannot list or
use remote credentials; authenticated users must match their bound UID.

Use a stable per-SignRequest internal actor ID so account/guest transitions
cannot bypass the durable session guard. Production CSC key consent stays
separate and blocked. Verify 54 focused tests and 555 assertions on an
isolated Nextcloud 36 environment; PHP 8.3 syntax and formatter clean.

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…blication

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…tion

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
…rience

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment