mirror of
https://github.com/documenso/documenso.git
synced 2026-06-22 04:12:06 +10:00
d5ce222482
Adds Cloud Signature Consortium (CSC) integration for AES/QES signing against a configured TSP. v1 ships as instance-wide configuration via environment variables, with per-envelope signature level selection, license gating, and an OAuth-driven signing flow (capture + FIFO signers, SAD session, blocking/in-progress recipient pages). Includes signature level compatibility checks (role, signing order, dictate next signer), envelope mutability assertions, Prisma migration for signature level and CSC tables, and docs for the new signing certificate options.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { DocumentSigningOrder } from '@prisma/client';
|
|
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
import { isTspEnvelope } from '../../types/signature-level';
|
|
|
|
type AssertCompatibleSigningOrderOptions = {
|
|
signatureLevel: string;
|
|
signingOrder: DocumentSigningOrder | null | undefined;
|
|
};
|
|
|
|
/**
|
|
* Reject `signingOrder = PARALLEL` on AES/QES envelopes.
|
|
*
|
|
* Parallel signing produces conflicting incremental PDF updates over the
|
|
* same base state, breaking the per-recipient `/ByteRange` invariant that
|
|
* lets each TSP signature verify independently. Sequential is the only safe
|
|
* order for TSP-signed envelopes.
|
|
*
|
|
* SES envelopes pass through unchanged — PARALLEL remains the SES default.
|
|
* A `null` / `undefined` signingOrder also passes through (the create-envelope
|
|
* caller decides the default).
|
|
*
|
|
* Schema-layer guard. {@link sendDocument} re-coerces at distribution time
|
|
* as a defence-in-depth backstop.
|
|
*/
|
|
export const assertCompatibleSigningOrder = ({
|
|
signatureLevel,
|
|
signingOrder,
|
|
}: AssertCompatibleSigningOrderOptions): void => {
|
|
if (!isTspEnvelope({ signatureLevel })) {
|
|
return;
|
|
}
|
|
|
|
if (signingOrder !== DocumentSigningOrder.PARALLEL) {
|
|
return;
|
|
}
|
|
|
|
throw new AppError(AppErrorCode.INVALID_BODY, {
|
|
message: `Envelopes signed at '${signatureLevel}' require signingOrder=SEQUENTIAL — PARALLEL breaks the per-recipient /ByteRange invariant required for TSP signatures to verify independently.`,
|
|
});
|
|
};
|