CodeSign React Native Reference Documentation
CodeSign
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
Chilkat.CodeSign
Apply Authenticode signatures to EXE, DLL, MSI, PowerShell, and VBScript
files using a certificate and associated private key.
Check whether a signed executable has a valid signature and whether the
signing certificate chain can be trusted.
Extract details about the Authenticode signature, including signer
information and signature-related metadata.
Get the certificate used to sign the executable and inspect it with
Remove an existing Authenticode signature from a signed file when
an unsigned output file is required.
Use detailed diagnostic output to troubleshoot signing, certificate,
trust-chain, timestamping, or validation problems.
For an extended overview, see
CodeSign Class Overview.
Sign, verify, inspect, and remove Authenticode signatures on Windows executables, installers, and scripts.
Chilkat.CodeSign works directly with Authenticode signatures on
Windows executable files such as .exe and .dll, and,
starting in v11.7.0, on Windows Installer packages (.msi),
PowerShell files (.ps1, .psm1, .psd1), and
VBScript files (.vbs).
It provides functionality for applying a code-signing signature, validating
whether a signed executable can be trusted, extracting signature information,
retrieving the signer certificate, and removing an existing signature.
Sign executables, installers, and scripts
Validate trust
Inspect signatures
Retrieve signer certificates
Chilkat.Cert.
Remove signatures
Diagnostics
Object Creation
// npm install @chilkat/react-native react-native-nitro-modules
// (React Native 0.76+ with the New Architecture; then `pod install` for iOS. The Chilkat
// native library is downloaded and verified during the native build -- see the package README.)
import { Chilkat, CodeSign } from '@chilkat/react-native'
// Once per app start, before any other Chilkat call:
Chilkat.unlockBundle('Anything for 30-day trial') // shorthand for new Global().unlockBundle(..)
const codeSign = new CodeSign()
// ... the native object is released when `codeSign` is garbage collected, or now with codeSign.dispose()Creates the underlying native Chilkat object. CodeSign is a Nitro Module HybridObject: use it from the JavaScript thread only (it cannot be passed to a Worklet or another runtime). Every member is synchronous and blocks the JavaScript thread until Chilkat returns; a method that can take a while also exists as a ...Async twin returning a Promise, which runs the same call on a native worker thread so the UI keeps rendering. While such a call is pending, every other call on this object throws, except abort() and assigning onPercentDone / onProgressInfo.
Releases the native object immediately instead of waiting for garbage collection (useful for a large BinData or an open socket). Calling it more than once is harmless; any other use of the object afterwards throws. An object with a pending ...Async call cannot be disposed until the promise settles.
Errors
A method that can fail throws a plain Error: a method whose only outcome is success or failure returns void and throws on failure; a method producing a string or an object returns it and throws where Chilkat would have returned null. The error's message is "Class.method(...): reason", where the reason is the last informative line of the object's lastErrorText, which holds the full Chilkat log of the failed call. A ...Async twin rejects its promise with the same Error instead of throwing. Properties never throw, and methods that answer a question (has..., is..., ...) return a plain boolean.
try {
codeSign.someMethod(...)
} catch (e) {
console.log((e as Error).message) // CodeSign.someMethod(...): <reason>
console.log(codeSign.lastErrorText) // the full Chilkat log of the failed call
}
// The same call without blocking the JavaScript thread:
try {
await codeSign.someMethodAsync(...)
} catch (e) {
console.log((e as Error).message) // CodeSign.someMethodAsync: <reason>
}
Properties
DebugLogFilePath
debugLogFilePath: string
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
HeartbeatMs
heartbeatMs: number
Specifies the approximate interval, in milliseconds, between AbortCheck event callbacks during supported operations. An event handler can request that the current operation be aborted.
The default is 0, which disables AbortCheck callbacks. Setting a positive value enables periodic callbacks when an operation is sufficiently long-running; methods that finish quickly may complete without generating one.
LastErrorHtml
readonly lastErrorHtml: string
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
readonly lastErrorText: string
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
readonly lastErrorXml: string
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
lastMethodSuccess: boolean
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
UncommonOptions
uncommonOptions: string
Provides a comma-separated list of specialized compatibility or validation options. The default is an empty string, which is appropriate for normal use.
| Option | Effect |
|---|---|
codesign-allow-expired-cert | Prevents Authenticode verification from failing solely because the signing certificate is expired. |
codesign-allow-cert-padding | Starting in v11.7.0. Prevents verification of an EXE or DLL from failing solely because the PE certificate table fails the strict check (extra data or entries outside the verified signature). The failed check is still reported in LastErrorText. Use only for files known to carry such data, such as some installers that store configuration data in the certificate table. |
codesign-allow-expired-cert is not a substitute for timestamping. A signature carrying a valid trusted timestamp should ordinarily remain verifiable after the signing certificate expires without this option.VerboseLogging
verboseLogging: boolean
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
readonly version: string
Methods
AddSignature
Adds a Microsoft Authenticode signature to the file specified by path. The file is modified in place. cert supplies the code-signing certificate and must provide access to its associated private key. options supplies the signing configuration as JSON.
Starting in v11.7.0, Windows Installer packages, PowerShell files, and VBScript files can be signed in addition to Windows executables and DLLs. The supported file types are:
| File type | Extensions | Where the signature is stored |
|---|---|---|
| Windows PE images | .exe, .dll, and other PE files such as .sys and .ocx | The PE certificate table. PE files are identified from the file content, not the extension. |
| Windows Installer packages (starting in v11.7.0) | .msi | The package's digital signature stream. |
| PowerShell scripts, modules, and data files (starting in v11.7.0) | .ps1, .psm1, .psd1 | A comment block appended to the file (# SIG # Begin signature block ... # SIG # End signature block). The file's text encoding (UTF-8, UTF-8 with BOM, or UTF-16) is kept. |
| VBScript files (starting in v11.7.0) | .vbs | A comment block appended to the file ('' SIG '' Begin signature block ... '' SIG '' End signature block). |
Any other file type (for example .js, .cab, or .cat) causes the method to return false, with LastErrorText explaining that the file type is not supported, and the file is not modified. The file must already exist; this method does not create it.
Starting in v11.7.0, if the file is already Authenticode-signed, the existing signature is removed and replaced by the new one. (Before v11.7.0, signing an already-signed EXE or DLL added a second signature entry instead of replacing the first.)
signtool verify, Get-AuthenticodeSignature, and the file's Digital Signatures properties, report the signature as invalid (TRUST_E_BAD_DIGEST, 0x80096010). This is a limitation of signed MSI files on Windows, not a Chilkat defect: an MSI signed by Microsoft's signtool with the same ECDSA certificate is rejected in the same way, and its signed content is identical to the signature Chilkat produces. Use an RSA code-signing certificate to sign MSI packages. ECDSA certificates work for EXE, DLL, PowerShell, and VBScript files.Common options options include:
| JSON member | Purpose |
|---|---|
hashAlg | Selects the file-digest algorithm, such as sha256. |
timestampToken.enabled | Enables an RFC 3161 timestamp token. |
timestampToken.tsaUrl | Specifies the timestamp authority URL. |
timestampToken.requestTsaCert | Requests inclusion of the timestamp authority certificate. |
timestampToken.hashAlg | Selects the timestamp-request digest algorithm, such as sha256. |
{
"hashAlg": "sha256",
"timestampToken": {
"enabled": true,
"tsaUrl": "http://timestamp.example.com",
"requestTsaCert": true,
"hashAlg": "sha256"
}
}
Returns normally on success; throws an Error on failure.
AddSignatureAsync
Asynchronous form of AddSignature: the same call on a native worker thread, so the JavaScript thread (and the UI) stays responsive. Takes the same arguments and resolves with the same result. While the returned Promise is pending, every other call on this object throws (the object is busy), except abort(), which cancels the call, and assigning the onPercentDone / onProgressInfo callbacks, which report its progress.
Note: the onPercentDone and onProgressInfo callbacks run on the JavaScript thread while the promise is pending, so they can update the UI directly. A rejection's message is "Class.methodAsync: reason"; the full log is in lastErrorText.
Returns a Promise that resolves with the synchronous method's result (undefined for a void method) and rejects with an Error where the synchronous method would throw.
GetSignerCert
Retrieves the X.509 signer certificate discovered by the most recent call to VerifySignature on this CodeSign object. If the certificate is fully available, cert is loaded with it and the method returns true. Otherwise, the method returns false.
The returned object contains the public certificate only; it does not provide the signer's private key. Call this method after VerifySignature and use the same CodeSign instance.
Starting in v11.7.0, the signer certificate is available only after a call to VerifySignature that returned true. After a failed verification, this method returns false.
VerifySignature and the returned signature information when making a trust decision.Returns normally on success; throws an Error on failure.
RemoveSignature
Removes the embedded Authenticode signature from the file specified by path: a Windows executable or DLL, or, starting in v11.7.0, a Windows Installer package (.msi), PowerShell file (.ps1, .psm1, .psd1), or VBScript file (.vbs). The file is modified in place. Returns true if the signature is successfully removed; otherwise returns false.
For PowerShell and VBScript files, the signature comment block is removed from the end of the file. For MSI packages, the digital signature stream and the extended signature stream (MsiDigitalSignatureEx) are removed.
Returns normally on success; throws an Error on failure.
VerifySignature
Verifies the embedded Microsoft Authenticode signature of the file specified by path: a Windows executable or DLL, or, starting in v11.7.0, a Windows Installer package (.msi), PowerShell file (.ps1, .psm1, .psd1), or VBScript file (.vbs). See AddSignature for the supported file types. Other file types cause the method to return false. Structured information about the signature, signer, certificate chain, digest algorithms, timestamp, and validation result is written to sigInfo.
Returns true when the signature satisfies the applicable Authenticode validation checks under the current Windows trust configuration. This includes confirming that the signed portions of the file have not changed and evaluating the signing certificate and timestamp information, as applicable. An unsigned file or a signature that does not validate causes the method to return false. Inspect sigInfo and LastErrorText for details.
Starting in v11.7.0, verification of an EXE or DLL also includes a strict check of the PE certificate table: it must hold exactly one signature entry, containing exactly the signature that was verified, with no extra data. Data in the certificate table is not covered by the Authenticode signature (see CVE-2013-3900), so anything hidden there would be unsigned. A file that fails this check causes the method to return false unless the codesign-allow-cert-padding option is set in UncommonOptions.
MSI packages signed with an ECDSA certificate: this method can return true for such a package, while Windows itself reports the signature as invalid. This is a limitation of signed MSI files on Windows, not a Chilkat defect; see the note in AddSignature.
Returns normally on success; throws an Error on failure.
Events
While a method runs, CodeSign reports progress through two optional callback properties. Assign a function to receive the event, or undefined to stop receiving it. The callbacks are delivered on the JavaScript thread, so they are useful with the ...Async methods: during a synchronous call the JavaScript thread is busy inside Chilkat, and the events can only arrive after it returns.
const codeSign = new CodeSign()
codeSign.onPercentDone = (pct) => setProgress(pct) // pct is 0..100
codeSign.onProgressInfo = (name, value) => console.log(`${name}: ${value}`)
codeSign.heartbeatMs = 250 // let abort() take effect within a quarter second
const pending = codeSign.someMethodAsync(...)
cancelButton.onPress = () => codeSign.abort() // the promise then rejects
await pendingPercentDone fires when an operation's completion percentage is known; ProgressInfo delivers named progress values (what is reported depends on the class and method). There is no AbortCheck callback: to cancel a pending ...Async call, call abort() on the object. Chilkat notices the request at its next progress check, which happens at least every heartbeatMs milliseconds on the classes that have that property (0, the default, disables the heartbeat, so set it for a responsive cancel), and the promise rejects with Chilkat's abort error. abort() is harmless when nothing is pending.
PercentDone
onPercentDone?: (pctDone: number) => void
This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).
The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.
To abort the operation, set the abort output argument to true. This will cause the method to terminate and return a failure status or corresponding failure value.
Example:
codeSign.onPercentDone = (pct) => {
// pct ranges from 0 to 100.
setProgress(pct) // runs on the JavaScript thread: React state may be updated directly
}
await codeSign.someMethodAsync(...)
// To stop an operation from within the callback, call codeSign.abort()ProgressInfo
onProgressInfo?: (name: string, value: string) => void
This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.
Note: Some Chilkat methods don't fire any ProgressInfo events.
Example:
codeSign.onProgressInfo = (name, value) => console.log(`${name}: ${value}`)
await codeSign.someMethodAsync(...)