Using OpenSSL with Windows cert store
pwfran98 at wp.pl
Tue Apr 25 07:14:34 UTC 2023
> Use an Engine (I'd recommend a Provider, but you say you're stuck with OpenSSL 1.0.2 for whatever reason) that uses CNG to do all the cryptography. If the engine provides all the cryptographic functions you need for TLS, then OpenSSL will just do the non-cryptographic parts of TLS (which is most of it: the record protocol, negotiation, non-cryptographic steps of certificate chain building and verification, and so on), and use the engine for actual cryptography. Then, if Windows is in FIPS mode, or you restrict it to FIPS-validated providers, you're all set and you don't have to worry about key extraction or using the OpenSSL FIPS module.
Yes, agreed, this would be the best option.
>> As far as I can see I don't have access to ECC-capable CAPI provider, so simply
>> using OpenSSL with capi engine will not work.
> Yes, I misremembered. I thought there were ECC CAPI providers, but the additional providers I was thinking of were the ones that supported reasonable-length RSA keys and additional symmetric algorithms. You'd need to use CNG, so you'll have to write CNG regardless.
>> So far I think I would use Windows API (CNG ?) to extract certificates and
>> (exportable) keys from Windows store and load them into OpenSSL.
> Again, this seems like the wrong approach to me. You'll have to write CNG code and awkwardly wire it together with OpenSSL 1.0.2, *and* have to use the OpenSSL FOM. So much more straightforward, general, and flexible to just write a CNG engine to do the cryptography under OpenSSL. Yes, the engine interface isn't tremendously well documented, but the existing CAPI engine, and other engines such as PKCS#11, show how it's done.
I fully agree that creating CNG-based engine/provider for OpenSSL would
be the best option,
but I don't think I can afford it for time, resources and formal reasons.
>> Are there any working examples of doing this ? Especially, accessing
>> Personal/My store using CNG ?
> Probably. I don't know of any offhand.
>> Assuming private keys are exportable is it possible to export them in
>> DER/PKCS8 or other format easily importable to OpenSSL ?
> CNG wants to export the key as one of Microsoft's beloved BLOB types. See the documentation for NCryptExportKey. Working with the BLOBs is a bit of a pain, but it can be done; years ago I wrote some code to convert between BLOBs and OpenSSL in-memory data structures for some symmetric key type (the details escape me).
> There may be other CNG functions for key export, or for converting BLOBs into something reasonable. I don't know the CNG API well. (The .NET cryptographic APIs are better, but you probably don't want to be switching between managed and native code, or doing IPC to some managed-code key service. Though having said that, obviously many applications *do* go the route of using a key service.)
Thanks for help.
More information about the openssl-users