HotXLS Docs

Multiple OPC signature operations

The explicit byte-array APIs in lxSignatureOpcIssuer inspect a bounded set of attached package signatures, verify a caller-selected signature, or hand back an individual result for every discovered signature

Enterprise edition: Discovery and verification of multiple signatures, trust evaluation, appending and replacing signatures are available solely in HotXLS Enterprise, in the lxSignatureOpcIssuer unit of the HotXLSEnterprise package (HotXLSLazEnterprise.lpk for Lazarus); Delphi and Lazarus applications add lxSignatureOpcIssuer to a uses clause, and statically linked C++Builder applications call XlsEnableXlsxSigning() once. These functions moved across from lxSignatureOpcIntegrity to lxSignatureOpcIssuer with unchanged signatures

Discover an unverified inventory

XlsDiscoverSignatureOpcPackage(Bytes, Inventory) returns TXLSSignatureOpcDiscoveryStatus; xsodDiscovered means the origin and signature-part relationships make up a supported structural inventory

Inventory.OriginPart and Inventory.SignatureParts are unauthenticated discovery data: discovery neither verifies signature XML, identifies a verified signer, establishes authenticated content coverage nor evaluates certificate trust

Names follow the origin relationship order, which unsigned relationship edits may reorder; use an explicit part name whenever the application wants a particular signature rather than reading meaning into an array position

Verify an explicit signature part

XlsVerifySelectedSignatureOpcPackage(Bytes, SignaturePart, Details) demands an explicit attached signature-part name and verifies that signature's RSA-SHA256 value together with its selected package References

On xsoiIntegrityVerified, Details.SignaturePart, Certificate, CheckedReferences and Coverage belong to the actual verified signature; the integrity result remains xsstUntrusted

Within a discovered signed package, a valid but unattached name returns xsoiSignatureNotFound; an empty or malformed selector fails and never asks for the first signature by implication

Canonical case-insensitive package identity resolves to the actual stored part name reported on success; selection is capped at 4096 UTF-16 code units before its private copy is taken

A malformed or invalid unselected signature can sit in the structural inventory whilst a different, explicitly selected signature verifies; successful selection establishes only that signature and its reported coverage

Verify every signature with individual results

XlsVerifyAllSignaturesOpcPackage(Bytes, Reports) returns xsoiIntegrityVerified only when every admitted signature verifies; failing that, its aggregate result is the first failure in inventory order

Each TXLSSignatureOpcVerification retains its structurally discovered SignaturePart, individual Status and verified Integrity result when successful

A failed individual result carries empty authenticated identity, certificate and coverage; its structural report name still shows which attempted signature failed, and checking carries on for the other signatures within the shared resource bounds

Structural discovery or outer allocation failure clears the report array rather than publishing a partial inventory; callers must inspect both the aggregate status and each returned report

Keep requested and aggregate results separate

The caller supplies the requested part name; this example logs structural names apart from individual verification results and never picks the first inventory entry automatically

uses
  System.SysUtils, System.Classes, lxSignatureOpcIntegrity;

procedure LogPackageSignatureResults(const PackageBytes: TBytes;
  const RequestedPart: WideString; Log: TStrings);
var
  Inventory: TXLSSignatureOpcInventory;
  Discovery: TXLSSignatureOpcDiscoveryStatus;
  Selected: TXLSSignatureOpcIntegrityResult;
  Reports: TXLSSignatureOpcVerifications;
  SelectedStatus, AggregateStatus: TXLSSignatureOpcIntegrityStatus;
  I: Integer;
begin
  Discovery := XlsDiscoverSignatureOpcPackage(PackageBytes, Inventory);
  Log.Add('Discovery status: ' + IntToStr(Ord(Discovery)));
  if Discovery <> xsodDiscovered then
    Exit;
  for I := 0 to High(Inventory.SignatureParts) do
    Log.Add('Unverified inventory: ' + String(Inventory.SignatureParts[I]));

  SelectedStatus := XlsVerifySelectedSignatureOpcPackage(
    PackageBytes, RequestedPart, Selected);
  Log.Add('Requested verification: ' + IntToStr(Ord(SelectedStatus)));
  if SelectedStatus = xsoiIntegrityVerified then
    Log.Add('Verified selected part: ' + String(Selected.SignaturePart));

  AggregateStatus := XlsVerifyAllSignaturesOpcPackage(PackageBytes, Reports);
  Log.Add('Aggregate verification: ' + IntToStr(Ord(AggregateStatus)));
  for I := 0 to High(Reports) do
    Log.Add(String(Reports[I].SignaturePart) + ': ' +
      IntToStr(Ord(Reports[I].Status)));
end;

Apply trust to the verified selection

XlsVerifySelectedSignatureOpcPackageWithTrust(Bytes, SignaturePart, Policy, Details) composes explicit selected verification with the existing caller-owned trust policy

The supplied anchors, intermediates, UTC verification time, EKU and revocation policy apply to the certificate that actually passed the selected signature; no caller-supplied alternate leaf may stand in for that identity

xsotTrustedSelection describes that verified selection and its authenticated coverage, without claiming that every signature, every workbook part or the whole package is trusted

The certificate-chain backend keeps its existing Windows qualification and explicit unavailable status on unsupported targets; this increment adds no aggregate certificate trust and touches none of the process certificate stores

Structural ownership and shared limits

The explicit APIs admit at most one signature origin and 32 signature parts; every internal signature relationship must resolve to the corresponding content type, and attached targets and physical signature parts must pair up one-to-one

Duplicate targets, orphan signature parts, missing targets and invalid ownership are rejected rather than silently omitted from the inventory

All-signature verification shares a single opened package, its aggregate read budget and 8388608 structural work units across the complete inventory, instead of reopening the package with a fresh budget per signature

The existing 64 MiB package input and aggregate-read limits, the 16 MiB per-part limit and the XML, Reference and cryptographic profile bounds stay in force; resource refusal is an explicit result, and once a shared budget runs out a later signature need not verify

Input byte arrays remain caller owned; selector text is copied before an aliased result field is cleared, and authenticated details are published only once the selected signature and References verify

Append while preserving every verified signature

XlsAppendVerifiedSignatureOpcPackage(Bytes, Certificate, Options, Signer, Output, Details) adds one caller-signed signature to a package carrying one through 31 already valid signatures, keeping the original origin and every old signature

The operation verifies all existing signatures before staging, rechecks them against the actual placeholder infrastructure, and verifies the completed output before publication; old signature XML, ordinary part bytes and existing media bindings stay untouched

Options is the existing TXLSSignatureOpcIssueOptions with explicit raw, canonical XML or relationship-transform selections and a valid UTC claimed signing time; selections may also name parts of the verified original-signature inventory, enabling counter-signatures over existing signatures, consecutive counter-signature chains and mixed signature/content selections, whilst each appended signature records only its direct selections and unverified signature parts remain invalid selections; the supplied certificate and caller-owned RSA-SHA256 signer keep the existing issuing contract

TXLSSignatureOpcAppendSignDigest receives a TXLSSignatureOpcAppendRequest containing OriginalPackageSha256, StagedPackageSha256, the allocated SignaturePart, deep-copied verified OriginalSignatures and the new NewSignature request

NewSignature.InputPackageSha256 identifies the exact placeholder-stage package whose selection produced the requested digest; it differs from both the original package hash and the final output hash

The callback reports the existing TXLSSignatureOpcSignerStatus; its returned bytes must be the RSA signature over the supplied SHA-256 digest made with the supplied certificate's key, and no private key or certificate-store ownership passes to the library

TXLSSignatureOpcAppendResult contains Status, SignerCalled, exact InputPackageSha256, StagedPackageSha256 and OutputPackageSha256, the new SignaturePart, verified OriginalSignatures and FinalSignatures, and the new signature's Integrity result

Successful append returns xsapAppended from TXLSSignatureOpcAppendStatus; xsapUnsignedSource leaves the initial signing to the existing unsigned issuer, and an already-full 32-signature source returns xsapResourceLimit before calling the signer

Adding a signature relationship or content-type binding can invalidate an old signature that authenticates shared infrastructure; the real staged verification returns xsapWouldInvalidate before the signer is called, for the qualified interference profile

Other failures report xsapInvalidSource, xsapInvalidSelection, xsapInvalidCertificate, xsapSignerCancelled, xsapSignerFailed or xsapVerificationFailed as applicable; every failure keeps the previous output and clears authenticated result identity and coverage, whilst preserving the current status and whether the signer was called

Shared array values and input/output aliases are supported; the storage of the Output variable itself must not overlap the Details record

The transaction keeps the 64 MiB input/output limit, the 16 MiB per-part limit and one 8388608-unit editor/verifier work budget; at most seven bounded package opens admit at most 448 MiB of aggregate reads across phases, whilst nested parser, Reference and crypto bounds retain their original invocation semantics

Each signature phase shares its package read budget across all signatures; an admitted 31-signature source performs no more than 94 signature verifications across the three phases

This byte-array operation supports repeated append and preserves all admitted signatures; it adds no certificate trust, whole-workbook coverage, multi-signature Workbook load/save, selected replacement or mutation/re-signing

Replace one explicitly authorized signature

XlsReplaceSelectedSignatureOpcPackage(Bytes, NewCertificate, Authorization, Options, Signer, Output, Details) replaces one selected signature whilst preserving every unselected signature and the existing physical package topology

The existing TXLSSignatureOpcReplaceAuthorization binds ExpectedPackageSha256, explicit ExpectedSignaturePart and ExpectedCertificateSha256 to the actual verified original selection; neither an empty selector nor an implicit first-signature fallback is admitted

Canonical ASCII case aliases resolve to the actual stored physical name, which the finished output retains; a missing selector in an otherwise verified signed source returns xspsSignatureNotFound, whilst mismatched package/certificate authority returns xspsIdentityMismatch

All original signatures verify before replacement authority is exercised; every unselected signature verifies against the actual placeholder stage before the signer is invoked, and every final signature verifies before publication

The selected physical name, origin edges, relationship identifiers and content-type bytes stay unchanged; every part apart from the selected signature XML is byte-compared with the original, retaining unselected certificates, authenticated selections and ordinary content

Options: TXLSSignatureOpcIssueOptions explicitly selects the new raw, canonical XML or relationship-transform coverage; the replaced signature may authenticate a different requested selection, but all unselected signatures must stay valid

TXLSSignatureOpcSelectedReplaceSignDigest receives a TXLSSignatureOpcSelectedReplaceRequest with OriginalPackageSha256, OriginalSignaturePart, OriginalCertificateSha256, exact StagedPackageSha256, deep-copied verified OriginalSignatures and the isolated NewSignature request

NewSignature.InputPackageSha256 identifies the actual placeholder-stage bytes from which the requested digest was derived, and the existing caller-owned RSA-SHA256 callback contract supplies the new signature without any private-key ownership changing hands

TXLSSignatureOpcSelectedReplaceResult reports Status, SignerCalled, exact InputPackageSha256, StagedPackageSha256 and OutputPackageSha256, the retained SignaturePart, original OriginalCertificateSha256, verified OriginalSignatures and FinalSignatures, and the newly verified selected Integrity

TXLSSignatureOpcSelectedReplaceStatus returns xspsReplaced only after final cryptographic verification and the unchanged-part audit; xspsUnsignedSource leaves unsigned input to its separate issuing path

When an unselected signature authenticates the selected signature XML, placeholder replacement produces xspsWouldInvalidate before the signer is called; a real countersignature control distinguishes replacing the depended-on signature from successfully replacing its dependent signature

Other refusals include xspsInvalidSource, xspsInvalidSelection, xspsInvalidCertificate, xspsResourceLimit, xspsSignerCancelled, xspsSignerFailed and xspsVerificationFailed; failed operations keep the previous output and clear authenticated result identity/coverage whilst retaining status and whether the signer was invoked

A valid 32-signature package can be replaced without its signature count growing; one 8388608-unit main verifier/editor budget spans at most seven bounded package opens, admitting at most 448 MiB of aggregate reads across phases and at most 95 signature verifications

Each phase shares its package read budget across signatures; the 64 MiB input/output, 16 MiB per-part and existing nested parser, Reference and crypto bounds remain in force

Shared array values and source/output aliases are supported, yet the storage of the Output variable itself must not overlap Details; callback report arrays and nested selections have isolated storage

Replacement grants neither certificate trust nor whole-workbook coverage, and does not widen ordinary Workbook multi-signature load/save or mutation/re-signing admission

Edit ordinary content and replace one signature

XlsEditAndReplaceSelectedSignatureOpcPackage(Bytes, NewCertificate, Authorization, Options, Edits, Signer, Output, Details) combines explicit existing-part edits with replacing one caller-authorised original signature

The existing TXLSSignatureOpcEdits carries one to 256 physical part names and replacement byte arrays; every edited part must exist and be covered by the requested new signature's authentication

The operation rejects signature XML, origin infrastructure, relationship parts, content-type edits, absent parts and duplicate ASCII case aliases; it preserves the existing physical names, the part count, the relationships and the media types

All original signatures verify before the exact original package hash, the explicit selected signature name and the actual original certificate hash authorise any change

Every unselected signature must still verify against the genuinely edited placeholder package ahead of Signer is called; changes that invalidate another signature return xspsWouldInvalidate without invoking the signer

The existing TXLSSignatureOpcSelectedReplaceRequest binds the verified original signatures and exact original identity to the genuinely edited StagedPackageSha256 and the new signing digest; callback reports and nested selections have isolated storage

Final publication requires all signatures to verify, the selected certificate and requested coverage to match, and every part apart from the selected signature XML to equal either its exact authorised edit bytes or its unchanged original bytes

Edits accepts at most 16 MiB per part and 64 MiB of aggregate copied payload, with at most 4096 characters per name; the existing 64 MiB input/output and parser/reference/crypto limits stay in force

The shared 8388608-unit work budget charges new name comparisons by character length; fixed phases keep the selected-replacement ceilings of seven bounded package opens, 448 MiB admitted reads and 95 signature verifications

Combined work and output-package limits may refuse before any individual item maximum is reached; allocation-before-copy preflight rejects an oversized plan even where several caller entries share one array value

Invalid edits or coverage return xspsInvalidSelection, excessive plans return xspsResourceLimit, and original authority, signing and verification keep the existing selected-replacement statuses; failure preserves the previous output and clears authenticated result identity and coverage

Input/output and edit-data/output aliases work through private copies; the storage of the Output variable itself must not overlap Details

The earlier XlsReplaceSelectedSignatureOpcPackage keeps its no-content-edit contract; this newer operation neither coordinates re-signing several invalidated signatures, creates nor removes parts, repairs relationship graphs, widens Workbook lifecycle admission nor establishes certificate trust

Authorized batch content-edit replacement

XlsEditAndReplaceSelectedSignaturesOpcPackage replaces 1 through 32 explicitly authorised existing signatures in a single transaction, with optional edits to at most 256 existing ordinary parts; an empty edit list serves certificate and coverage renewal

Each TXLSSignatureOpcReplacementPlan supplies the original package, physical signature-part and certificate identity, a replacement certificate, explicit options and the existing selected-replacement signing callback

All original signatures and selected authorities verify before staging; every unselected signature must verify against the common stage, and all replacement manifests plus the union of edited-part coverage are validated before the first callback

Callbacks receive the same common stage hash with independent original reports, selected coverage, canonical SignedInfo and digest buffers; plans, certificates, edits and nested relationship selectors are copied ahead of the callbacks

All replacements verify before the exact part inventory, order, media bindings and authorised or unchanged payload bytes are audited and a single output is published

Cancellation, provider failure and verification failure keep the caller's previous output and clear authenticated result fields whilst reporting actual SignerCalls; input, certificate and edit-data array value aliases are supported, while Output variable storage must not overlap Details

Signature, origin, relationship and content-type infrastructure cannot be edited like ordinary parts, and replacement references cannot bind staged signature placeholders

The operation keeps the 64 MiB package, 16 MiB part, 64 KiB certificate and 64 MiB aggregate edit-byte limits; each plan admits at most 256 references, the batch at most 4,096 relationship selectors and 1 MiB of bounded names and selector text

One shared 8 × 1,024 × 1,024 operation-work budget covers the complete transaction; this is no total-memory or per-byte hashing guarantee

Part additions and removals, graph repair, dependency-ordered signature chains, broader Workbook and VBA integration, timestamps, provider extensions and certificate trust all remain separate requirements

Compatibility and remaining lifecycle work

The original no-selector XlsVerifySignatureOpcPackage and XlsVerifySignatureOpcPackageWithTrust keep their single-signature profile; a multiple-signature package makes neither API choose a signature implicitly

Explicit package-byte verification, preserve-all append and authorised selected replacement complement the original APIs; ordinary verified Workbook loading, unsigned issuing, replacement, mutation and re-signing keep their existing ownership profiles

Broader signature dependency chains, part additions/removals and relationship repair, broader Workbook lifecycle integration, additional VBA profiles, timestamps, certificate/key-provider extensions and the remaining trust/platform qualification stay open requirements