I am investigating a Windows CNG key-access issue using the Microsoft Software Key Storage Provider on Windows 11.
Problem
A non-production ECDSA P-256 machine key is successfully created, configured, finalized, and read back using its original key handle. However, after closing that handle, NCryptOpenKey fails with 0x80090016 (NTE_BAD_KEYSET).
Configuration
- Provider: Microsoft Software Key Storage Provider
Key algorithm: ECDSA P-256
Machine key: NCRYPT_MACHINE_KEY_FLAG
Export policy: 0 (non-exportable)
Usage: NCRYPT_ALLOW_SIGNING_FLAG
Reopen flags: NCRYPT_MACHINE_KEY_FLAG | NCRYPT_SILENT_FLAG
Caller: Same elevated Windows user before and after closing the handle
The key has a protected DACL with two allow ACEs:
BUILTIN\Administrators: 0x000E0000 (READ_CONTROL | WRITE_DAC | WRITE_OWNER)
Dedicated publisher account: 0x00020000 (READ_CONTROL)
No additional ACEs are present.
Observed results
NCryptCreatePersistedKey succeeds.
Key configuration and security descriptor assignment succeed.
NCryptFinalizeKey succeeds.
Before closing the original handle, NCRYPT_UNIQUE_NAME_PROPERTY, key properties, security descriptor, and public key blob are read successfully.
NCryptFreeObject succeeds.
NCryptOpenKey fails with NTE_BAD_KEYSET (0x80090016).
The provider-issued unique name identifies an existing 1,380-byte machine-key backing file. Its owner and protected DACL match the configured descriptor.
Windows Security auditing records successful key creation and key-file write operations (Events 5061 and 5058), followed by a failed Open Key operation (Event 5061).
Questions
What is the supported minimum access-rights model for opening and using a persisted machine key with Microsoft Software KSP?
During NCryptOpenKey, does the key-storage access check run under the caller's token, SYSTEM/LSA, or another security context?
Can a protected DACL containing only READ_CONTROL, WRITE_DAC, and WRITE_OWNER cause this reopen failure, even though key creation and finalization succeed?
How should a dedicated publisher be granted permission to open/sign while preventing unauthorized key deletion or security descriptor changes?
Is there a documented diagnostic method to identify the exact failed access check inside Microsoft Software KSP?
I am seeking a documented least-privilege solution, not an unrestricted Full Control workaround.
The affected test keys have been preserved without retries, ACL modifications, or cleanup.I am investigating a Windows CNG key-access issue using the Microsoft Software Key Storage Provider on Windows 11.
Problem
A non-production ECDSA P-256 machine key is successfully created, configured, finalized, and read back using its original key handle. However, after closing that handle, NCryptOpenKey fails with 0x80090016 (NTE_BAD_KEYSET).
Configuration
Provider: Microsoft Software Key Storage Provider
Key algorithm: ECDSA P-256
Machine key: NCRYPT_MACHINE_KEY_FLAG
Export policy: 0 (non-exportable)
Usage: NCRYPT_ALLOW_SIGNING_FLAG
Reopen flags: NCRYPT_MACHINE_KEY_FLAG | NCRYPT_SILENT_FLAG
Caller: Same elevated Windows user before and after closing the handle
The key has a protected DACL with two allow ACEs:
BUILTIN\Administrators: 0x000E0000 (READ_CONTROL | WRITE_DAC | WRITE_OWNER)
Dedicated publisher account: 0x00020000 (READ_CONTROL)
No additional ACEs are present.
Observed results
NCryptCreatePersistedKey succeeds.
Key configuration and security descriptor assignment succeed.
NCryptFinalizeKey succeeds.
Before closing the original handle, NCRYPT_UNIQUE_NAME_PROPERTY, key properties, security descriptor, and public key blob are read successfully.
NCryptFreeObject succeeds.
NCryptOpenKey fails with NTE_BAD_KEYSET (0x80090016).
The provider-issued unique name identifies an existing 1,380-byte machine-key backing file. Its owner and protected DACL match the configured descriptor.
Windows Security auditing records successful key creation and key-file write operations (Events 5061 and 5058), followed by a failed Open Key operation (Event 5061).
Questions
What is the supported minimum access-rights model for opening and using a persisted machine key with Microsoft Software KSP?
During NCryptOpenKey, does the key-storage access check run under the caller's token, SYSTEM/LSA, or another security context?
Can a protected DACL containing only READ_CONTROL, WRITE_DAC, and WRITE_OWNER cause this reopen failure, even though key creation and finalization succeed?
How should a dedicated publisher be granted permission to open/sign while preventing unauthorized key deletion or security descriptor changes?
Is there a documented diagnostic method to identify the exact failed access check inside Microsoft Software KSP?
I am seeking a documented least-privilege solution, not an unrestricted Full Control workaround.
The affected test keys have been preserved without retries, ACL modifications, or cleanup.