Verifying Signatures Programmatically Before You Ship
You will learn how to build automated verification gates into your release pipelines so that unsigned, incorrectly signed, or broken binaries and documents never reach production.
Why Verification Belongs in the Pipeline
Generating a signature via the OneSigner REST API, watched folders, or OneSignTool does not guarantee that the resulting artefact is ready for customers. Build agents can drop output files, timestamps can fail to resolve due to network partitions, or intermediate certificates can be omitted. Relying on manual spot checks inevitably leads to expired timestamps or broken file integrity slipping past release engineers. By adding explicit verification commands to your build scripts right after the signing step, you catch structural and cryptographic failures immediately.
Whether you are producing Windows executables signed with Authenticode or invoices signed with PAdES, programmatic checks provide an unambiguous exit code that can fail a GitHub Actions workflow, Azure DevOps pipeline, or GitLab CI job before deployment steps execute.
Verifying Windows Authenticode Signatures
For Windows binaries such as .exe, .dll, .msi, .cab, .sys, .ocx, .appx, and .msix, Windows provides built-in utilities to inspect signature validity. While signtool.exe verify is the standard tool for checking files during local development, automated environments often benefit from PowerShell cmdlets that return structured boolean results or throw catchable exceptions.
To verify a signed executable in PowerShell, query the digital signature status of the target file using Get-AuthenticodeSignature:
$path = "C:\Builds\MyApp.exe"
$sig = Get-AuthenticodeSignature -FilePath $path
if ($sig.Status -ne 'Valid') {
Write-Error "Signature verification failed for $path with status: $($sig.Status)"
exit 1
}
Write-Host "Signature valid. Signed by: $($sig.SignerCertificate.Subject)"
This script checks the cryptographic integrity of the Authenticode signature, verifies that the certificate chain resolves to a trusted root in the Windows certificate store, and confirms that the file has not been altered since it was signed. If your build agents run on machines without a graphical interface, this check executes identically in headless Windows Server environments.
Verifying PAdES PDF Signatures
PDF documents generated through the OneSigner REST API or watched folders carry PAdES signatures designed to be validated by Adobe Acrobat and other standards-compliant readers. Because PDF signature structures embed the signed document revision and cryptographic digest directly inside the container, standard OS file checks are insufficient.
When automating PDF verification in server-side scripts, you must inspect the signature dictionary, verify the embedding integrity, and confirm that the cryptographic timestamp is intact. If you encounter issues with trust chains or unexpected alterations, consult your PDF library documentation for troubleshooting steps.
For programmatic validation in .NET or Python pipelines, use a dedicated PDF library that evaluates signature dictionaries against trusted trust stores. A typical validation check verifies three distinct criteria:
- The cryptographic hash matches the signed byte range of the PDF.
- The signer certificate was valid at the time of signing.
- A trusted RFC 3161 timestamp is present to protect against subsequent certificate expiration.
Integrating Verification with OneSignTool and CI/CD
When using OneSignTool as an Azure Key Vault-compatible proxy during code signing builds, the file hash is sent to your local OneSigner service while the private key remains secure on the USB hardware token. Once OneSignTool completes the signing operation and writes the signed binary back to your build workspace, immediately follow up with your verification command.
Below is an example step in a build script that chains signing and verification together:
# 1. Sign the application using AzureSignTool or OneSignTool (compatible with Azure Key Vault flags)
AzureSignTool sign ^
-kvu "https://onesigner.local:9440" ^
-kva "your-tenant-token" ^
-kvc "YourCertificateName" ^
-tr "http://timestamp.digicert.com" ^
-td sha256 ^
-f "dist\app.exe"
if %errorlevel% neq 0 (
echo Signing failed.
exit /b 1
}
# 2. Immediately verify the output before archiving
powershell -Command "$s = Get-AuthenticodeSignature 'dist\app.exe'; if ($s.Status -ne 'Valid') { exit 1 }"
if %errorlevel% neq 0 (
echo Post-sign verification failed.
exit /b 1
}
echo Build and signature verification completed successfully.
Handling Common Verification Edge Cases
Automated pipelines frequently fail verification due to subtle environment differences rather than actual tampering. Watch out for these common scenarios:
- Missing Timestamp: If a build pipeline omits the RFC 3161 timestamp URL during signing, the signature will validate successfully today but fail immediately the moment the signing certificate expires. Always require an explicit timestamp server.
- Untrusted Root on Build Agents: Clean virtual machine build agents may lack commercial cross-signed roots or specialized CA certificates in their local
Cert:\LocalMachine\Rootstore. Ensure your provisioning scripts install necessary intermediate and root certificates before running verification. - File Lock Contention: Ensure that any post-processing tools release file handles on the binary before your verification step attempts to read its signature headers.
Next Steps
Review your current CI/CD YAML configurations and add a mandatory verification step immediately following your signing tasks.