Skip to Content
NexPDF

Long-term signatures (B-LTA)

Sign at PAdES B-LTA on iOS and Android, add RFC 3161 document timestamps, renew archive timestamps and timestamp with your own TSA or HSM, with NexPDF for React Native.

English

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 call on this page resolves to the complete new file as base64. Keep that string as it is. The engine runs natively on the device and reaches the timestamp authority (TSA) and the OCSP and CRL servers itself, so the device needs network access to them.

Sign at a chosen level

sign (and signPkcs12) and NexPdf.api.completeExternalSignature take a level option:

levelWhat you getNeeds
B-BSignature only
B-TPlus a signature timestamptsa_url
B-LTPlus certificates, OCSP responses and CRLs (DSS)tsa_url
B-LTAPlus a document timestamptsa_url
import { NexPdf } from '@nexdevit/nexpdf-react-native';

const doc = await NexPdf.open(contractBase64);
const signed = await doc.sign(p12Base64, 'p12-password', {
  reason: 'Approved',
  level: 'B-LTA',
  tsa_url: 'http://timestamp.example.com',
  timestamp: { hash: 'SHA-256', field: 'Timestamp1' },   // optional
});

timestamp configures the document timestamp: hash, field and reserved (bytes kept for the token).

Add a document timestamp

doc.addDocumentTimestamp(optionsJson) timestamps an open document, and NexPdf.api.addDocumentTimestampBytes(base64, optionsJson) timestamps the bytes of a file, for example straight from a signing call.

const lta = await NexPdf.api.addDocumentTimestampBytes(signedBase64, JSON.stringify({   // a B-T signature
  tsa_url: 'http://timestamp.example.com',
  ltv: true,
}));
OptionDefaultMeaning
tsa_urlrequiredThe RFC 3161 timestamp authority
hashSHA-256SHA-256, SHA-384 or SHA-512
fieldTimestamp1Name of the timestamp's signature field
reserved16384Bytes reserved for the token
ltvFirst add the certificates, OCSP responses and CRLs of every earlier signature and timestamp to the DSS

With ltv, the same call turns a B-T signature into B-LTA, and renews the archive timestamp of a B-LTA file. Run it again before the last timestamp's certificate expires.

Your own TSA or HSM

React Native has no TSA callback binding: the bridge cannot call back into JavaScript from the engine, so nexpdf_set_tsa_callback is not exposed. Use a tsa_url, or do the network part in your own code: the three steps below for a document timestamp, and online signing in steps for the signature timestamp and the validation data.

When the timestamp comes from your own service, do it in three steps with no state in between:

const doc = await NexPdf.open(signedBase64);
const prepared = await doc.prepareDocumentTimestamp('{"field":"Archive2"}');   // options without tsa_url

const request = await NexPdf.api.documentTimestampRequest(prepared, 'SHA-256');  // DER TimeStampReq, base64
const token = await myTsa.timestamp(request);    // your call: POST as application/timestamp-query, base64 reply

const stamped = await NexPdf.api.completeDocumentTimestamp(prepared, token);

token is the DER TimeStampResp or TimeStampToken, as base64. It must verify and match the document.

Online signing in steps

When your application makes the HTTP calls itself, add the signature timestamp (B-T) and the validation data (B-LT) in steps. Sign at B-B first ("reserved" leaves room for the timestamp).

B-T. NexPdf.api.signatureTimestampRequest(base64, hash) returns the DER TimeStampReq over the value of the last signature (a null hash is SHA-256; the signature must cover the whole file). POST it to the TSA as application/timestamp-query and store the answer with NexPdf.api.addSignatureTimestamp(base64, token), before any other change to the file. The signed bytes are not changed; the token must verify and be issued for that signature.

B-LT. NexPdf.api.ltvRequestsJson(base64, responsesJson) lists the HTTP requests still needed for the DSS, [{"method","url","content_type","body"}] with body in base64. Fetch them, give the answers back (each object plus "response":"<base64>", or "error":"HTTP 404" for one that failed) and call again until it returns []. Then NexPdf.api.addLtvWithResponses(base64, responsesJson) adds the DSS; missing answers count as failed. For B-LTA, add a document timestamp after that.

All bytes travel as base64.

const request = await NexPdf.api.signatureTimestampRequest(signedBase64, null);   // a B-B signature
const token = await myTsa.timestamp(request);     // your call: POST as application/timestamp-query, base64 reply
const bt = await NexPdf.api.addSignatureTimestamp(signedBase64, token);

let answers: string | null = null;
for (;;) {
  const needed = JSON.parse(await NexPdf.api.ltvRequestsJson(bt, answers));
  if (needed.length === 0) break;
  answers = JSON.stringify(await fetchAll(needed));   // your HTTP code: each object plus response or error
}
const blt = await NexPdf.api.addLtvWithResponses(bt, answers);

Verify

NexPdf.verifySignatures reports every signature and every document timestamp. Two fields are new in 1.1:

FieldMeaning
document_timestamptrue for a document timestamp. Then signer is the TSA, digest_ok checks the message imprint and trusted checks the TSA chain against your roots
pades_levelB-B, B-T, B-LT or B-LTA
for (const s of await NexPdf.verifySignatures(lta)) {
  const kind = s.document_timestamp ? 'timestamp' : 'signature';
  console.log(kind, s.signer, s.pades_level, s.digest_ok && s.signature_ok);
}

Validate B-LTA

NexPdf.api.validateLtaJson(base64, trustRootsPem) checks, for every document timestamp, whether the DSS of the revision it timestamps holds every certificate and revocation entry for the earlier signatures, their TSAs and earlier document timestamps. OCSP responses are verified: signature, responder (the issuing CA or a certificate it delegated with id-kp-OCSPSigning), responder chain to your roots, thisUpdate/nextUpdate around the timestamp that protects the DSS, and status. The PEM roots are optional (roots that need not be in the DSS).

const lta = JSON.parse(await NexPdf.api.validateLtaJson(ltaBase64, rootsPem));
console.log('complete:', lta.complete);
for (const ts of lta.timestamps) {
  for (const issue of ts.issues) console.log(ts.field, issue.field, issue.role, issue.kind);
}

Each timestamp has field, time, valid, has_dss, complete, covers (the fields it protects) and issues. An issue has field, role (signer, signature-timestamp or document-timestamp), subject and kind: missing-certificate, missing-revocation, revoked, ocsp-bad-signature, ocsp-unauthorized-responder, ocsp-untrusted-responder, ocsp-not-current or ocsp-unknown-status.

See Digital signatures for signing with PKCS#12 files and external keys.

On this page