Signing one file with a USB token is easy: run the tool, type the PIN in the pop-up, done. Signing two hundred invoices overnight, or every build in a pipeline, is where it falls apart. The token's driver shows a PIN window for every signature, or once per session, and nobody is there to type it. Builds hang, scheduled jobs time out, and someone ends up sitting next to the machine pressing Enter. This post explains why the prompt appears and the realistic ways to sign unattended without weakening the token's protection more than necessary.
Why the token keeps asking
A hardware token is designed to prove that a person authorised each use of the key. The PIN check lives in the token's middleware, not in your signing tool:
- Windows CSP/KSP drivers (SafeNet Authentication Client, Feitian, many national CA drivers) show their own PIN dialog when an application opens the key. Whether they cache the PIN, and for how long, is the driver's decision.
- Some certificates are marked "sensitive". SafeNet, for example, can require the PIN on every access for qualified certificates, regardless of caching settings.
- YubiKey PIV slots have PIN policies. The Digital Signature slot (9c) requires the PIN for every signature by design, while the Authentication slot (9a) asks once per session. Which slot your CA put the certificate in decides how often you are asked.
- Some drivers ignore a PIN supplied by the application and always show their own window, so passing a PIN through the API has no effect.
And there is a second, separate problem: services and CI agents usually run outside the interactive desktop (Windows Session 0), where the token is not visible and where no dialog can ever be shown. In that context you do not get a prompt at all; you get errors such as "the context was acquired as silent" or "keyset does not exist".
Option 1: let the driver cache the PIN (SafeNet Single Logon)
SafeNet Authentication Client has a Single Logon setting: open SafeNet Authentication Client Tools, click the gear icon to switch to Advanced View, go to Client Settings > Advanced, tick Enable Single Logon, set Automatic logoff after token inactivity to Never, click Save, then log off and on again (or restart). The PIN is then asked once per Windows session.
- Good for: a person signing a batch at their desk.
- Limits: you still type the PIN after every logon, restart, and sometimes after the screen locks. It does not work for an agent running as a service. And while the session is open, anyone with access to the machine can sign without the PIN. Sectigo's own guidance warns that anyone with physical access to the logged-in computer can then sign, and recommends disabling it for standard, non-batch signing.
Option 2: pass the PIN to signtool through the CSP
For SafeNet eTokens there is a widely used trick (described by several signing-tool vendors, but not part of Microsoft's signtool documentation): give signtool the public certificate file, the CSP name and a key container string that embeds the PIN:
signtool sign /f codesign.cer /csp "eToken Base Cryptographic Provider" ^
/kc "[{{<TOKEN_PIN>}}]=<key container name>" ^
/fd sha256 /tr http://timestamp.digicert.com /td sha256 MyApp.exe
The container name is shown in SafeNet Authentication Client (certificate details) or by certutil -user -scinfo.
- Good for: a single build machine with a SafeNet token, in a user session.
- Limits: SafeNet-specific and dependent on the SAC version; other vendors' CSPs do not understand this syntax. Some setups need the reader name in front of the PIN (
[<reader name>{{<PIN>}}]=<container>). The PIN appears in the command line, build logs and process listings unless you are careful. It still needs the interactive session.
Option 3: sign through PKCS#11 instead of the Windows CSP
Almost every token vendor also ships a PKCS#11 module (a DLL such as eTPKCS11.dll for SafeNet, or the vendor's own module for Feitian, Bit4id and national CA tokens). PKCS#11 lets the application log in to the token with the PIN directly, without the Windows dialog. Tools that sign Authenticode through PKCS#11 include the open-source jsign (with store types such as ETOKEN, PIV, YUBIKEY or a generic PKCS11 configuration and the PIN as --storepass) and osslsigncode with a PKCS#11 engine or provider.
jsign --storetype ETOKEN --storepass env:TOKEN_PIN ^
--tsaurl http://timestamp.digicert.com --tsmode RFC3161 MyApp.exe
The env: prefix makes jsign read the PIN from an environment variable, so it does not appear on the command line. Add --alias "<certificate alias>" only if the token holds more than one certificate (jsign lists the aliases if it is needed). The ETOKEN store type uses the SafeNet Authentication Client's PKCS#11 module; use YUBIKEY or PIV for a YubiKey.
- Good for: unattended signing with any token whose vendor ships a PKCS#11 module; it also works where the Windows driver ignores application-supplied PINs.
- Limits: you need the correct module DLL, and the process still has to run where the token is visible. Store the PIN in a secret store, never in the repository.
Option 4: put the token behind a signing service
All three options above still require the build to run on the machine the token is plugged into, in a logged-in session. That conflicts with modern CI, where runners are ephemeral, often cloud-hosted, and run as services. The architecture that solves it is to separate the two:
- One dedicated Windows machine holds the token, stays logged in (locked screen is fine) and runs a small signing service that knows the PIN.
- Build runners send the file's hash (or the file) over HTTPS with an access token, and get a signature back.
- The service queues requests so that a token that signs one operation at a time is not overloaded.
Cloud key-vault style signing tools (AzureSignTool and similar) already speak a protocol for this, so the client side needs no custom code.
Security rules that apply to every option
- Never retry a rejected PIN in a loop. Tokens lock after a small number of wrong attempts. A YubiKey PIV PIN locks after 3 by default and needs the PUK; a locked EV token may need to be reissued by the CA. A script that retries on failure can destroy the token in seconds.
- Keep the PIN out of code, command lines and logs: put it in a secret store (Windows DPAPI, your CI secret store) or in a configuration file that only the signing service and administrators can read.
- Protect the signing machine like a key: limited admin accounts, disk encryption, no general web browsing, physical security for the token.
- Log every signature with what was signed and by whom. Unattended signing removes the human check, so the log is your audit trail.
- Restrict what may be signed: allowed file types, allowed callers, and separate credentials per team or partner that can be revoked individually.
Which option to choose
| Situation | Practical choice |
|---|---|
| A person signs a batch now and then | Driver PIN caching (Single Logon), turned off afterwards |
| One build machine with the token attached | PKCS#11 signing with the PIN from a secret store; agent running in a user session |
| Cloud or multiple CI runners, scheduled jobs, several teams | A signing service in front of the token |
How OneSigner handles it
OneSigner is the signing-service option for Windows. The token stays in one machine; you enter the PIN once per signing profile in the Config app, where it is kept in the service configuration (restrict that file to SYSTEM and administrators) and supplied automatically. The service runs as LocalSystem but performs the token operation inside the logged-in user's session (Auto-Logon is available for unattended servers). For third-party CSP/KSP drivers it signs through the vendor's PKCS#11 module first, so no vendor PIN window pops up, and it stops after one rejected PIN instead of burning retries. PDFs are signed through watched folders, the REST API or the portal; code is signed from CI with OneSignTool or AzureSignTool. See signing fails in Session 0 and the Azure Key Vault compatible proxy, or try it with your own token in the 30-day trial.



