This is part of my attempt to run the [Niko Home Control programming software](https://appdb.winehq.org/objectManager.php?sClass=application&iId=21635) under Wine. This (.NET 8 / Electron app) is performing mTLS with a [Connected controller voor Niko Home Control II](https://products.niko.eu/nl-be/article/550-00003). Doing this, it calls `CertSetCertificateContextProperty` with `CERT_NCRYPT_KEY_HANDLE_PROP_ID`. Wine currently does not implement setting this property so it falls through to the default case, with the \``FIXME("%ld: stub\n", dwPropId);` that lead me to try to implement it. This patch seems to work for the Niko Home Control app so I added test to contribute it upstream. According to [the documentation](https://learn.microsoft.com/en-us/windows/win32/api/wincrypt/nf-wincrypt-cer...), `dwKeySpec` should be set to `CERT_NCRYPT_KEY_SPEC`. This value didn't seem to be defined yet in Wine so I added its definition. [Its value seems to be \`0xffffffff\`](https://android.googlesource.com/toolchain/mingw/+/refs/heads/main/mingw-w64...). I added tests. Before the changes in `dlls/crypt32/cert.c`, running the tests with `wine 11.5-1` (current version on ArchLinux) the tests give 7 failures: ``` $ wine dlls/crypt32/tests/x86_64-windows/crypt32_test-stripped.exe cert 0024:fixme:crypt:add_cert_to_store Unimplemented add disposition 0 0024:fixme:crypt:add_cert_to_store Unimplemented add disposition 0 0024:fixme:crypt:Collection_release Unimplemented flags 2 0024:fixme:crypt:CertContext_SetProperty 78: stub cert.c:553: Test failed: CertSetCertificateContextProperty failed: 80092004 cert.c:559: Test failed: CertGetCertificateContextProperty failed: 80092004 cert.c:560: Test failed: Expected hCryptProv 0xBEEF1234, got 0 cert.c:562: Test failed: Expected dwKeySpec CERT_NCRYPT_KEY_SPEC, got 2 cert.c:569: Test failed: CertGetCertificateContextProperty failed: 80092004 cert.c:570: Test failed: Expected handle 0xBEEF1234, got 0 0024:fixme:crypt:CertContext_SetProperty 78: stub cert.c:587: Test failed: CertSetCertificateContextProperty failed: 80092004 0024:fixme:crypt:CertAddCertificateLinkToStore (00007FFFFE871940, 00007FFFFE8530D8, 00000001, 00007FFFFE1FFB50): semi-stub 0024:fixme:crypt:Collection_release Unimplemented flags 2 0024:fixme:crypt:ProvStore_release Unimplemented flags 2 0024:fixme:crypt:CRYPT_RegCloseStore Unimplemented flags: 00000002 0024:fixme:crypt:ProvStore_release Unimplemented flags 2 0024:fixme:crypt:CRYPT_RegCloseStore Unimplemented flags: 00000002 0024:fixme:bcrypt:BCryptOpenAlgorithmProvider algorithm L"_SHOULDNOTEXIST_" not supported 0024:fixme:cryptasn:CryptDecodeObjectEx Unimplemented decoder for lpszStructType OID 1 0024:fixme:cryptasn:CryptDecodeObjectEx Unimplemented decoder for lpszStructType OID 1 0024:fixme:crypt:CryptVerifyCertificateSignatureEx unimplemented for NULL signer 0024:fixme:cryptasn:CRYPT_GetBuiltinEncoder Unimplemented encoder for lpszStructType OID 0 0024:fixme:cryptasn:CryptDecodeObjectEx Unimplemented decoder for lpszStructType OID 1 0024:fixme:crypt:CertGetPublicKeyLength unimplemented for DH public keys 0024:fixme:cryptasn:CryptDecodeObjectEx Unimplemented decoder for lpszStructType OID 7 0020:cert: 649 tests executed (0 marked as todo, 0 as flaky, 7 failures), 0 skipped. ``` After applying my patches like so ``` sudo cp dlls/crypt32/x86_64-windows/crypt32.dll /usr/lib/wine/x86_64-windows/crypt32.dll sudo cp dlls/crypt32/crypt32.so /usr/lib/wine/x86_64-unix/crypt32.so ``` I get 0 failures: ``` $ wine dlls/crypt32/tests/x86_64-windows/crypt32_test-stripped.exe cert 0024:fixme:crypt:add_cert_to_store Unimplemented add disposition 0 0024:fixme:crypt:add_cert_to_store Unimplemented add disposition 0 0024:fixme:crypt:Collection_release Unimplemented flags 2 0024:fixme:crypt:CertAddCertificateLinkToStore (00007FFFFE872F70, 00007FFFFE854988, 00000001, 00007FFFFE1FFB50): semi-stub 0024:fixme:crypt:Collection_release Unimplemented flags 2 0024:fixme:crypt:ProvStore_release Unimplemented flags 2 0024:fixme:crypt:CRYPT_RegCloseStore Unimplemented flags: 00000002 0024:fixme:crypt:ProvStore_release Unimplemented flags 2 0024:fixme:crypt:CRYPT_RegCloseStore Unimplemented flags: 00000002 0024:fixme:bcrypt:BCryptOpenAlgorithmProvider algorithm L"_SHOULDNOTEXIST_" not supported 0024:fixme:cryptasn:CryptDecodeObjectEx Unimplemented decoder for lpszStructType OID 1 0024:fixme:cryptasn:CryptDecodeObjectEx Unimplemented decoder for lpszStructType OID 1 0024:fixme:crypt:CryptVerifyCertificateSignatureEx unimplemented for NULL signer 0024:fixme:cryptasn:CRYPT_GetBuiltinEncoder Unimplemented encoder for lpszStructType OID 0 0024:fixme:cryptasn:CryptDecodeObjectEx Unimplemented decoder for lpszStructType OID 1 0024:fixme:crypt:CertGetPublicKeyLength unimplemented for DH public keys 0024:fixme:cryptasn:CryptDecodeObjectEx Unimplemented decoder for lpszStructType OID 7 0020:cert: 649 tests executed (0 marked as todo, 0 as flaky, 0 failures), 0 skipped. ``` Let me know if there is anything else I can do to help, this is my first contribution to this project. -- v2: Try fixing the tests to match Windows behavior https://gitlab.winehq.org/wine/wine/-/merge_requests/10521