Hi @Marco Silveira ,
Thank you for the detailed write-up and for clearly separating your observations from the supported contract you are looking for. I also noticed that you have already ruled out the reopened-handle AllowArchiving result as an ACL test, and that your inventory shows ncrypt.dll 10.0.26100.1591 and ncryptprov.dll 10.0.26100.1. Those are the same versions I have on my test machine, which makes the export-policy test below easier to compare. While looking into this, I also found a related thread. In that thread, the same readback masks were reproduced on build 26300.9457 for a machine-scoped key under a restricted LocalService service SID. Open and sign succeeded there, owner and DACL changes returned NTE_PERM (0x80090010), delete returned E_ACCESSDENIED (0x80070005), and private export returned NTE_NOT_SUPPORTED (0x80090029).
On question 3, I could not find a documented mechanism that lets a key ACL express "sign and read public properties, but nothing else" in terms of published Software KSP rights. Key Storage Property Identifiers only describes NCRYPT_SECURITY_DESCR_PROPERTY as "A pointer to a SECURITY_DESCRIPTOR structure that contains access control information for the key". Generic Access Rights states that "Each type of securable object maps these bits to a set of its standard and object-specific access rights", but it does not list a mapping for CNG keys. Given that, I would suggest moving the boundary away from the key's mask semantics and into a narrow signing broker. In that design, only one dedicated service holds a handle to the persisted key, and its service SID is the only non-SYSTEM trustee in the key's protected DACL. The broker exposes a single operation: it accepts the bounded challenge format, hashes it according to your protocol, calls NCryptSignHash, and returns the signature together with the public key. It never exposes delete, property-set, export, arbitrary-hash or arbitrary-key-name operations. The callers' authority is then defined by an interface that you control and can review, rather than by undocumented low-order bits. This matches the purpose described in Service Changes for Windows Vista: "A service can isolate objects, such as files or registry keys, for its exclusive use by securing them with an access control entry that contains a service SID." One detail may be worth keeping in your qualification. According to SERVICE_SID_INFO, when SERVICE_SID_TYPE_RESTRICTED is used, the World SID S-1-1-0 is also added to the restricted SID list. Because of that, neither the key's DACL nor the broker's IPC endpoint DACL should contain an Everyone ACE if a different service must be excluded. The broker does not make the mask itself documented; it only reduces how much your boundary depends on it.
On question 4, I ran a test on my side. Please treat the results below as observed behavior on one build, not as a provider contract. My environment was build 26200.9457 (DisplayVersion 25H2) with ncrypt.dll 10.0.26100.1591 and ncryptprov.dll 10.0.26100.1. My session was not elevated, so I used user-scoped persisted ECDSA_P256 keys in the Microsoft Software Key Storage Provider. The same non-elevated user who owned each key created and tested it. This means I did not reproduce your machine-scoped key, SYSTEM provisioning or restricted service SID. Because the caller was the key's creator, the key's DACL should not be the reason for any refusal in these tests.
I first finalized a key with Export Policy 0 and then called NCryptSetProperty on NCRYPT_EXPORT_POLICY_PROPERTY with the values 1 (NCRYPT_ALLOW_EXPORT_FLAG), 2 (NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG) and 3. Every call returned NTE_BAD_KEY_STATE (0x8009000B). This happened both on the original handle immediately after NCryptFinalizeKey and on a handle reopened with NCryptOpenKey. On the reopened handle, the result was the same with dwFlags set to 0, NCRYPT_PERSIST_FLAG and NCRYPT_SILENT_FLAG. The policy read back as 0 on the same handle and again after another reopen. An ECCPRIVATEBLOB export size query kept returning NTE_NOT_SUPPORTED (0x80090029). The opposite direction behaved the same way. I finalized one key with policy 1 and another with policy 3, and setting either policy to 0 on a reopened handle returned NTE_BAD_KEY_STATE, with the policy unchanged. As controls, setting the policy before finalization succeeded. For the key finalized with policy 3, the ECCPRIVATEBLOB export size query also succeeded; I only queried the size, so no private bytes were written. One more observation may help with your error classification. The key finalized with policy 1 also returned NTE_NOT_SUPPORTED for an ECCPRIVATEBLOB export. On this build, that status code therefore reflected the export policy rather than an access-control decision, which is consistent with your choice not to treat it as an access denial.
My reading of these results is that, on this build, the Software KSP appears to reject any change to the export policy after finalization. It does so because of the key state, in both directions and on both original and reopened handles. If the same holds for your configuration, there would be no export-policy modification on a finalized key that can serve as a valid ACL negative test. In my tests the request was rejected for key state even though the caller had full access to the key, so a refusal under the restricted SID could not be attributed to the ACL. However, Key Storage Property Identifiers only documents the handle restriction for the archiving flags ("This flag only applies to the original key handle on which it is set."). It does not state an immutability guarantee for NCRYPT_ALLOW_EXPORT_FLAG or NCRYPT_ALLOW_PLAINTEXT_EXPORT_FLAG. I therefore cannot present this result as a documented guarantee or as the behavior of other builds.
For questions 1, 2 and 5, and for the guarantee part of question 4, I could not find a public Microsoft document that defines any of the following:
- the Software KSP generic mapping;
- the meaning of the object-specific bits in 0xD01F01FF and 0x80120089;
- the rights checked by NCryptOpenKey, NCryptSignHash, NCryptDeleteKey or security-descriptor changes;
- the Windows and provider versions those behaviors cover.
The API references for NCryptOpenKey, NCryptSignHash, NCryptDeleteKey and NCryptSetProperty document parameters, flags and return values, but not the access bits they check. AccessCheck requires the object's GENERIC_MAPPING, so it cannot fill that gap on its own.
Without that information, the most defensible verification I can suggest is a combination of two checks. The first is a structural readback through NCRYPT_SECURITY_DESCR_PROPERTY: owner, group, DACL protection, ACE types, trustees and the raw masks recorded per build. The second is a set of positive and negative operational tests under the real restricted token and under a different service SID, reported as observations. These points need an authoritative answer from the Windows/CNG team, so I'd suggest opening a case through Windows Developer Support. In that case, you could ask specifically for:
- the Software KSP generic mapping and object-specific rights;
- the required rights for each NCrypt operation;
- the export-policy rules after finalization;
- the build range these rules apply to.
Including your SDDL, the readback masks, your OS and DLL inventory, and the status codes you observed should help them address each point directly.
I hope the test results and the broker approach help with the parts that can be settled now. If my response was helpful, I'd really appreciate it if you could follow this guide so that others with the same question can benefit.
Thank you.