This is the hands-on companion to our chapter on the ADCS-on-Luna KSP service-account gotcha. That chapter explains why a CA built against a Luna HSM dies at its first cold restart when the key storage provider is only registered for the installing admin. This one is the walkthrough: registering the Luna KSP for both the admin and the CA service context, verifying it in the right security context, getting the CA key onto the HSM, and proving the whole thing survives a reboot before anyone calls it production.
Before you start, you need: a Windows Server that will host (or already hosts) the ADCS role; a Luna Network HSM partition assigned to that server with a working NTLS connection; the partition’s Crypto Officer credentials; and local Administrator rights on the server. Command syntax below is verified against Thales’s Luna 7.x client documentation — where a detail varies by client version we say so, and you should confirm against the doc set for your exact client (thalesdocs.com, under Luna HSM Client > SDK > Microsoft > KSP for CNG).
Step 1: Install the Luna client with the KSP component
The KSP is an optional feature of the Luna HSM Client installer, not part of the default footprint in every version. Run the client installer on the CA server and ensure the KSP (CNG) component is selected — if the client is already installed without it, re-run the installer and modify the feature set. A successful install gives you a KSP folder under the client directory (by default C:\Program Files\SafeNet\LunaClient\KSP) containing the two registration utilities:
KspConfig.exe— the graphical registration toolkspcmd.exe— the command-line equivalent, better for runbooks and repeatable builds
Confirm the plumbing underneath before touching the KSP: NTLS must be up and the partition visible. From the client directory:
vtl verify
If no slots come back, stop here — the KSP can’t fix a transport problem. Our chapter on NTLS vs STC and DR failover covers the usual causes.
Step 2: Register the cryptographic library
The KSP needs to know where the PKCS#11 library lives. This is a one-off, machine-wide step. In KspConfig.exe (run elevated), double-click Register Or View Security Library, browse to cryptoki.dll in the client install directory, and click Register. Command-line equivalent:
cd "C:\Program Files\SafeNet\LunaClient\KSP"
kspcmd library /s "C:\Program Files\SafeNet\LunaClient\cryptoki.dll"
Step 3: Register the slot — twice
This is the step the whole series exists for. Slot registration is per Windows account, and an ADCS build needs it done at least twice: once for the administrative account performing the install, and once for NT AUTHORITY\SYSTEM, which is what the Certificate Services service runs as.
In KspConfig.exe, double-click Register HSM Slots. For the first registration, select your admin account in Register For User and your machine or AD domain in Domain, select the partition, enter the Crypto Officer challenge, and click Register Slot. Then repeat with Register For User set to SYSTEM and Domain set to NT AUTHORITY, same partition, same challenge. Don’t be alarmed if the Registered Slots view seems to show a single entry afterwards — Thales’s documentation confirms both registrations exist even when the display collapses them.
Command-line equivalent — kspcmd registers for the current user by default, and takes /u and /d to register for another account:
:: Register for the account you are logged on as (prompts for the CO challenge)
kspcmd password /s <partition_label>
:: Register for the CA service context
kspcmd password /s <partition_label> /u SYSTEM /d "NT AUTHORITY"
:: Confirm what is registered
kspcmd viewslots
Two version-dependent notes. Supplying the challenge inline with /c (instead of at the prompt) requires Luna HSM Client 10.4.0 or later. The same release adds a nonAdminUser option (backed by the NAUaccess registry value under the SafeNet KSP hive) if a non-administrator account must use the KSP — irrelevant for stock ADCS, occasionally needed for other CNG consumers on the same box.
If your environment runs a service under a named domain account rather than Local System, the rule generalises: register the slot with /u <account> /d <domain> for whatever identity the process actually runs as.
Step 4: Verify in both contexts with certutil
Verification done only in your own admin window is the exact mistake this series warns about, so test both contexts. Your own account first:
certutil -csplist
Look for Provider Name: SafeNet Key Storage Provider with no errors against it. Then repeat as SYSTEM — Sysinternals PsExec is the standard way to get a SYSTEM shell:
psexec -s -i cmd.exe
whoami
:: expect: nt authority\system
certutil -csplist
If the SafeNet provider passes for you but errors under SYSTEM, go back to Step 3 — the SYSTEM registration is missing or was made with the wrong challenge. Do not proceed to CA installation until both contexts pass; every later symptom gets harder to read.
Step 5: Create the CA key on the HSM — or migrate an existing one
New CA: install the ADCS role as normal, and at the cryptography step of CA configuration select the SafeNet provider from the Select a cryptographic provider list (it appears in the algorithm#provider form, e.g. RSA#SafeNet Key Storage Provider), then choose your key length and hash algorithm. Key generation lands directly on the partition. Leave Allow administrator interaction when the private key is accessed by the CA unticked unless you genuinely intend to gate every key use — for an unattended issuing CA you almost never want it.
Existing CA with a software key: Thales ships a migration utility, ms2Luna.exe, in the KSP directory. It takes the CA certificate’s thumbprint and moves the key material from Microsoft software storage into the partition via the KSP. After migration, repoint the certificate’s key association at the SafeNet provider and verify:
:: Migrate the key (prompts per the utility; requires the CA cert thumbprint)
ms2Luna.exe
:: Re-associate the CA certificate with the SafeNet KSP
certutil -repairstore -csp "SafeNet Key Storage Provider" My <Thumbprint>
:: Confirm the provider and container now point at the HSM
certutil -verifystore My <Thumbprint>
certutil -verifykeys
certutil -verifykeys must report the CA keys verify successfully before you go any further. Then restart the service and watch it come up clean:
net stop certsvc
net start certsvc
One scoping note: migration moves the key for this CA. If you’re standing up a whole PKI tier on Luna — offline root downwards — the ceremony and design questions live in our Luna HSM design and operational guide.
Step 6: The reboot test — before production sign-off
A service restart is not the same test as a reboot. A restart reuses a warm machine with NTLS already established; a reboot forces the full cold path — Luna client services starting, NTLS coming up, certsvc starting as SYSTEM and opening its key from nothing. That cold path is exactly what a patch window exercises at 2am, so exercise it now, while it’s cheap:
- Reboot the server with no one logged on. Wait, then confirm
certsvcis running and Event ID 100 is absent from the Application log. - Issue a test certificate end-to-end (or for a root, sign a CRL:
certutil -crl) to prove the key is actually usable, not just visible. - Repeat the entire procedure — Steps 1 through 6 — on every standby, DR or rebuilt node. KSP registrations are local configuration: they do not replicate and are not captured by a CA database backup.
If the service fails on boot but starts fine manually, you have a start-ordering race: certsvc beat the Luna client to a working NTLS connection. Configure the CA service to start delayed, or make it dependent on the Luna client service, so the transport is up first — the exact service name to depend on varies by client version, so confirm it in your installed services list rather than copying one from a forum post.
Troubleshooting: symptom, cause, fix
| Symptom | Likely cause | Fix |
|---|---|---|
Event ID 100, 0x80090016 NTE_BAD_KEYSET, “Keyset does not exist” at service start | Slot not registered for NT AUTHORITY\SYSTEM (or registration lost to a client reinstall) | Re-run Step 3 for SYSTEM; verify with certutil -csplist under PsExec, then start the service |
Event ID 100, 0x8009001d NTE_PROVIDER_DLL_FAIL, “Provider DLL failed to initialize correctly” | Security library not registered, KSP component missing, or client install damaged | Re-run Steps 1–2; confirm cryptoki.dll path; re-verify both contexts |
Registration worked for your account but kspcmd/KspConfig errors on the challenge | Wrong Crypto Officer challenge, or partition policy locking the CO after failed attempts | Confirm credentials with the HSM admin; check partition lockout state before retrying |
| CA ran for months, fails after CO challenge rotation | KSP registrations cache the challenge; every account’s copy is now stale | Re-register the slot for every account (admin and SYSTEM) with the new challenge |
vtl verify shows no slots; CKR_TOKEN_NOT_PRESENT-class errors | NTLS/transport down — not a KSP problem | Fix the client-appliance trust first; see the NTLS vs STC chapter |
| Service starts manually but not on boot | certsvc races the Luna client services at startup | Delayed start or service dependency so NTLS is up before the CA starts |
| Works on the primary node, fails on standby/DR node | KSP registration is per machine and per account; it was never done there | Run the full procedure on every node, then reboot-test each one |
Where this leaves you
Your CA’s key is on the HSM, the service account can see it, and you’ve proven it across a cold reboot rather than assuming it. The remaining single point of failure is the appliance itself: one Luna behind an issuing CA means one hardware failure stops issuance estate-wide, and solving that with an HA group raises its own questions about what replicates and what doesn’t. That’s where the series goes next. The full sequence is at The Luna Field Guide.
Securitribe designs, deploys and operates Thales Luna HSM estates — partitions, HA, key ceremonies and DR that stand up to audit.
Explore Cryptographic HSM SolutionsBook a strategy call →