Pular para o conteúdo principal

Archival extension - Rest PKI Core

A signed document stays verifiable for as long as the timestamp that protects it can be trusted, and a timestamp stops being trustworthy when the certificate of the authority that issued it expires. The archival extension adds a new archive timestamp to an already signed file, before the current one expires, so that the signature keeps its validity over time. The archival inspection is its read-only counterpart: it tells whether a file can be extended and until when its current archive timestamp is valid, without changing the file. Both are available since Rest PKI Core 5.4.0.

FileWhat is extended
PDFA new PAdES document timestamp is added to the end of the file, in an incremental revision
XMLThe last signature that has an archive timestamp (XAdES with archive timestamp, such as AD-RA) gets a new archive timestamp

CMS files (.p7s, .p7m) can't be extended: they fail with UnsupportedContentType.

tip

From this point on we'll describe calls to Rest PKI Core. Make sure you've read the Get Started article to be able to keep up. The application's API key needs a role that allows signing and inspecting signatures, such as Worker (see Choosing roles).

A typical flow​

  1. Start from a signed file that already has an archive timestamp: a PDF that ends with a document timestamp (such as a PDF stamp) or an XAdES file with an archive timestamp.
  2. From time to time, call the inspection and read archiveTimestampInfo.dateExpires.
  3. Before that date, call the extension and store the file it returns in place of the previous one. The response has the new dateExpires: repeat from step 2 with the new file.

Each extension protects the file for as long as the new timestamp's authority certificate is valid, so the cycle can go on for as long as you need to keep the document. An archive timestamp that has already expired can't be extended: the call fails with ArchiveTimestampExpired.

Extending a file​

On .NET, call IRestPkiService.ExtendArchivalSignatureV2Async() with the signed file, as a file reference, and, optionally, the security context:

var result = await restPkiService.ExtendArchivalSignatureV2Async(
FileReference.FromFile(@"C:\AppData\Documents\contract.pdf"),
securityContextId: new Guid("201856ce-273c-4058-a872-8937bd547d36")
);

// result.File is a reference to the extended file
// result.ArchiveTimestampInfo describes the new archive timestamp
Console.WriteLine($"Extended until {result.ArchiveTimestampInfo.DateExpires}");

using (var stream = await result.File.OpenReadAsync()) {
// save the extended file
}

If calling the API directly, do:

POST {endpoint}/api/v2/signature/archival-extension
{
"file": {
"content": "JVBERi0xLjcK...",
"name": "contract.pdf",
"mimeType": "application/pdf"
},
"securityContextId": "201856ce-273c-4058-a872-8937bd547d36"
}

The request has these fields (in .NET, the parameters of the method, with the same names):

FieldDescription
fileThe signed PDF or XML file. Required. Rest PKI Core tells the format by the file's MIME type, as in signature inspection: without a mimeType, it is taken from the file name's extension. A file whose type can't be found fails with MimeTypeRequired, and an unrecognized one with UnrecognizedSignedFileMimeType
securityContextIdThe security context that decides which certificates are trusted and which timestamp tier issues the new timestamp. If omitted, Rest PKI Core uses the subscription's default security context or, without one, the instance's

There are no other options: every successful call adds one new archive timestamp.

The result​

The response has the extended file and the information of the new archive timestamp:

{
"file": {
"url": "https://..."
},
"archiveTimestampInfo": {
"timestampModel": { },
"dateIssued": "2026-11-23T10:15:00-03:00",
"dateExpires": "2029-06-30T23:59:59-03:00"
}
}
FieldDescription
fileThe extended file, as a file reference. It always comes as a url from which you can download it for a limited time. In .NET, result.File is a FileReference
archiveTimestampInfo.dateIssuedWhen the authority issued the new timestamp
archiveTimestampInfo.dateExpiresWhen the new timestamp expires, which is when the validity of the timestamp authority's certificate ends. Extend the file again before this date
archiveTimestampInfo.timestampModelThe details of the new timestamp, such as its signer and certificates. Always filled

What is checked​

Before issuing the timestamp, Rest PKI Core checks that the file can be extended.

PDF. The last signer of the PDF, in the order of the file, must be a document timestamp that has not expired. If the PDF ends with a signature of a person, or has no signature, the call fails with NoArchivalSignature; if that document timestamp has already expired, with ArchiveTimestampExpired. Rest PKI Core then validates this latest document timestamp against the security context. If it is not valid, the call fails with InvalidArchiveExtension, along with the validation results, and no timestamp is issued or billed. The signatures before the latest document timestamp are not validated: a new signature added after it starts a new archival, it is not an extension. The new document timestamp is added to the PDF in an incremental revision, together with the validation data of the certificate of the authority that issued the latest document timestamp. An invalid PDF fails with InvalidPdf, and a password-protected one with ProtectedPdfError.

XML. The file must have a signature with an archive timestamp, otherwise it fails with NoArchivalSignature. The latest archive timestamp must not be expired (ArchiveTimestampExpired), and the signature must be valid against the security context, with at least one valid archive timestamp, otherwise the call fails with InvalidArchiveExtension, along with the validation results. An XML file that can't be read fails with InvalidXml.

These errors are answered with HTTP 422 and an error code in the body (authentication and role failures keep their usual 401 and 403). They are:

CodeWhen
MimeTypeRequired, UnrecognizedSignedFileMimeTypeRest PKI Core can't tell the file's type, or doesn't recognize it
UnsupportedContentTypeThe file is a CMS file (.p7s, .p7m), which can't be extended
InvalidPdf, ProtectedPdfError, InvalidXmlThe file can't be read, or the PDF is password-protected
NoArchivalSignatureThe PDF doesn't end with a document timestamp, or the XML has no signature with an archive timestamp
ArchiveTimestampExpiredThe latest archive timestamp has already expired
InvalidArchiveExtensionThe latest document timestamp (PDF) or the signature (XML) is not valid against the security context, or the timestamp has no signer or doesn't carry its authority's certificate. The error has the validationResults when they apply
ArchivalExtensionValidationFailedThe timestamp that was just issued didn't pass validation against the security context
TimestampTierDisabled, TimestampTierRestrictedThe timestamp tier of the security context is disabled or can't be used by your subscription
SecurityContextNotFoundThe securityContextId doesn't exist
TransactionLimitReachedThe subscription reached its limit of transactions for this operation (see Billing)

The page Error codes lists the most common codes of the API.

Inspecting a file​

The inspection runs the same checks as the extension, with the same error codes, and doesn't add a timestamp or change the file. A successful response means the file passes the checks and returns the information of its active archive timestamp.

On .NET, call IRestPkiService.InspectArchivalSignatureAsync():

var result = await restPkiService.InspectArchivalSignatureAsync(
FileReference.FromFile(@"C:\AppData\Documents\contract.pdf"),
securityContextId: new Guid("201856ce-273c-4058-a872-8937bd547d36")
);

var expires = result.ArchiveTimestampInfo.DateExpires;
if (expires - DateTimeOffset.Now < TimeSpan.FromDays(90)) {
// time to extend the file
}

If calling the API directly, do:

POST {endpoint}/api/signature/archival-inspection
{
"file": {
"content": "JVBERi0xLjcK...",
"name": "contract.pdf",
"mimeType": "application/pdf"
},
"securityContextId": "201856ce-273c-4058-a872-8937bd547d36"
}

The request takes the same two fields as the extension's: file and securityContextId. An abridged response, for a PDF:

{
"archiveTimestampInfo": {
"timestampModel": { },
"dateIssued": "2026-11-23T10:15:00-03:00",
"dateExpires": "2029-06-30T23:59:59-03:00"
},
"signers": [
{
"signingTime": "2026-10-12T14:30:00-03:00",
"signatureFieldName": "Signature1",
"isDocumentTimestamp": false,
"validationResults": null
},
{
"signingTime": "2026-11-23T10:15:00-03:00",
"signatureFieldName": "Signature2",
"isDocumentTimestamp": true,
"validationResults": {
"passedChecks": [],
"errors": [],
"warnings": []
}
}
]
}
FieldDescription
archiveTimestampInfoThe active archive timestamp of the file, with dateIssued, dateExpires and timestampModel. This is the timestamp the extension would extend
signersThe signers of the file, as in signature inspection. Only one has validationResults: in a PDF, the document timestamp at the end of the file; in an XML, the signature that has the active archive timestamp. The others have null

The active archive timestamp is, in a PDF, the document timestamp at the end of the file and, in an XML, the latest archive timestamp of the last signature that has one.

A file that doesn't pass the checks fails with the same errors listed above. A successful inspection doesn't guarantee that the extension will succeed: it can still fail for reasons outside the file, such as a reached transaction limit or the timestamp authority being unavailable. The inspection uses the same timestamp tier access check, so it fails with TimestampTierDisabled or TimestampTierRestricted when the extension would.

The timestamp tier​

The new archive timestamp is issued by a timestamp tier of the instance. The request doesn't name it: Rest PKI Core uses the one set on the security context of the call. When the security context has no timestamp tier, Rest PKI Core picks the tier from the roots it trusts (the ICP-Brasil tier, or the Lacuna Test one) and, failing that, the instance's default tier. If none can be used, the call fails with SecurityContextNotConfiguredForTimestamping.

To control which tier extends your files, create a security context with the Timestamp tier you want and pass its ID in securityContextId.

Billing​

Each successful extension is counted as a PDF archival signature extension or an XML archival signature extension transaction, and also as a Timestamp transaction, for the timestamp that was issued. The call fails when the subscription reached its limit of either. If the timestamp is issued but the extension then fails, the timestamp is still billed.

An inspection is counted as one Signature inspection transaction, and only when it succeeds.

Client libraries​

The .NET library has the methods ExtendArchivalSignatureV2Async() and InspectArchivalSignatureAsync() from version 5.4.0 of the Lacuna.RestPkiCore.Client package. For the other languages, call the routes directly, as described in Calling the API directly.

Moving from the previous extension route​

Earlier versions had POST api/signature/archival-extension, which extended only XML files and, in .NET, ExtendArchivalSignatureAsync(). Both are now obsolete in favor of the routes above, and the old route answers UnsupportedContentType for any file that isn't XML. Use POST api/v2/signature/archival-extension for PDF and XML files.

See also​

View as Markdown