Using OpenSSL with Windows cert store

Michael Wojcik Michael.Wojcik at
Mon Apr 24 13:54:24 UTC 2023

> -----Original Message-----
> From: openssl-users <openssl-users-bounces at> On Behalf Of
> Pawel Frankowski
> Sent: Monday, 24 April, 2023 02:37
> What do you mean exactly by "why not Do The Right Thing and let Windows
> handle the cryptography, in FIPS mode?" ? Could you please elaborate ?

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.

> 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.

> 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.)

Michael Wojcik

More information about the openssl-users mailing list