Long-term signatures (B-LTA)
Sign at PAdES B-T, B-LT and B-LTA, add document timestamps with your own time-stamp authority, and validate B-LTA files in the browser with NexPDF for the web.
License module
Signature levels and document timestamps need the signatures module (Business tier and above).
Verification needs the same module.
PAdES B-LTA keeps a signature verifiable for decades. On top of a timestamped signature with its validation data (B-LT), it adds a document timestamp: an RFC 3161 timestamp over the whole file, in an invisible signature field. Before the timestamp authority's certificate expires, you add another one (an archive timestamp), and so on.
Every level above B-B needs a timestamp authority (TSA), and B-LT and B-LTA also fetch OCSP
responses and CRLs. The WebAssembly engine makes no network calls itself: it signs, then builds
each request, and the SDK sends them with fetch and gives the answers back to the engine.
CORS
A browser reaches only authorities that allow cross-origin requests, and most public TSA and OCSP
servers do not. Pass a fetch that goes through your own server, or a tsa function (see
Your own TSA).
Sign at a chosen level
doc.signOnline(p12, password, options) signs at any level and resolves to the signed PDF:
level | What you get | Needs |
|---|---|---|
B-B | Signature only (the default) | |
B-T | Plus a signature timestamp | tsaUrl or tsa |
B-LT | Plus certificates, OCSP responses and CRLs (DSS) | tsaUrl or tsa |
B-LTA | Plus a document timestamp | tsaUrl or tsa |
const p12 = new Uint8Array(await p12File.arrayBuffer());
const signed = await doc.signOnline(p12, password, {
level: 'B-LTA',
tsaUrl: 'https://tsa.example.com',
fetch: (url, init) => fetch(`/pki-proxy?u=${encodeURIComponent(url)}`, init), // your server
reason: 'Approved',
});The options are those of sign (name, reason, location, contact, field, appearance,
reserved) plus level, tsaUrl, tsa, hash (SHA-256, SHA-384 or SHA-512), ltv (also
add the DSS at B-B or B-T), timestamp (the B-LTA document timestamp's hash, field and
reserved), fetch, headers (extra headers for the TSA, such as Authorization) and
maxRounds (rounds of OCSP, CRL and issuer requests, default 16).
For external signing (HSM, smart card, signing service), the last step at any level is
nex.completeExternalSignatureOnline(prepared, cert, signature, { algorithm, level, tsaUrl }). See
Digital signatures.
Raise a signed file
On the bytes of a signed PDF, each level is one call of the engine object:
| Call | Does |
|---|---|
nex.timestampSignature(pdf, { tsaUrl }) | B-T: a signature timestamp on the last signature (before any other change) |
nex.addLtvOnline(pdf) | B-LT: OCSP responses, CRLs and certificates of every signature into the DSS |
nex.timestampDocument(pdf, { tsaUrl }) | A document timestamp; with ltv: true the DSS is added first (B-LTA, archive renewal) |
nex.upgradeSignature(pdf, level, options) | Raises a freshly signed B-B file to level |
let pdf = doc.sign(p12, password, { reason: 'Approved' }); // B-B
pdf = await nex.timestampSignature(pdf, { tsaUrl }); // B-T
pdf = await nex.addLtvOnline(pdf); // B-LT
pdf = await nex.timestampDocument(pdf, { tsaUrl }); // B-LTAtimestampDocument also takes field (default Timestamp<n>), reserved (bytes for the token,
default 16384) and hash. To renew an archive, call it again with ltv: true before the last
timestamp's certificate expires.
Your own TSA
Instead of tsaUrl, pass tsa: a function that receives the RFC 3161 request (DER bytes) and
returns the TSA's response (the DER body a TSA answers), or a Promise of it. Use it for an
authority behind your own client, a signing service or a test TSA. When both are given, tsa is
used. If it throws, the call fails with "TSA callback failed".
const tsa = async (request: Uint8Array) => {
const res = await fetch('/api/timestamp', { method: 'POST', headers: { 'Content-Type': 'application/timestamp-query' }, body: request });
return new Uint8Array(await res.arrayBuffer());
};
const signed = await doc.signOnline(p12, password, { level: 'B-T', tsa });signOnline, completeExternalSignatureOnline, timestampSignature, timestampDocument and
upgradeSignature take tsa. It is the JavaScript form of the native SDKs' TSA callback.
The engine steps
The helpers above are built on engine functions that are exported too (from
@nexdevit/nexpdf-web/engine, or on nex.wasm), for hosts that send the requests themselves:
| Level | Steps |
|---|---|
| B-T | signatureTimestampRequest(pdf, hash) (a TimeStampReq over the last signature, POST as application/timestamp-query), then addSignatureTimestamp(pdf, token) |
| B-LT | ltvRequestsJson(pdf, responsesJson) lists the HTTP requests still needed ([{"method","url","content_type","body"}], body in base64); call it again with the answers until it returns [], then addLtvWithResponses(pdf, responsesJson) |
| Document timestamp | doc.raw.prepareDocumentTimestamp(optionsJson) (the document with an empty timestamp field), documentTimestampRequest(prepared, hash), POST, then completeDocumentTimestamp(prepared, token) |
C_FUNCTIONS maps each C function to its name in the package.
Validate B-LTA
nex.wasm.validateLtaJson(pdf, trustRootsPem) checks, for each document timestamp, whether the DSS
of the revision it timestamps holds every certificate and revocation entry needed for the earlier
signatures, their TSAs and earlier document timestamps. OCSP responses are verified: their
signature, the responder (the issuing CA or a delegated id-kp-OCSPSigning certificate), the
responder's chain to your roots, thisUpdate and nextUpdate around the protecting timestamp, and
the status.
const lta = JSON.parse(nex.wasm.validateLtaJson(pdf, rootsPem));
console.log(lta.complete);
for (const t of lta.timestamps) {
console.log(t.field, t.time, t.valid, t.has_dss, t.complete, t.covers);
for (const i of t.issues) console.log(' ', i.field, i.role, i.subject, i.kind);
}Issue kinds: missing-certificate, missing-revocation, revoked, ocsp-bad-signature,
ocsp-unauthorized-responder, ocsp-untrusted-responder, ocsp-not-current and
ocsp-unknown-status.
Verify
nex.verifySignatures(bytes) reports every signature and every document timestamp, offline. Two
fields are new in 1.1:
| Field | Meaning |
|---|---|
document_timestamp | true for a document timestamp. Then signer is the TSA, digest_ok checks the message imprint and trusted says whether the TSA chain ends in a trusted root |
pades_level | B-B, B-T, B-LT or B-LTA |
const data = new Uint8Array(await signedFile.arrayBuffer());
for (const s of nex.verifySignatures(data)) {
const kind = s.document_timestamp ? 'timestamp' : 'signature';
console.log(kind, s.signer, s.pades_level, s.digest_ok && s.signature_ok);
}See Digital signatures for signing with PKCS#12 files and external devices.