rticommunity / openssl-cng-engine Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
On a few minor points, the implementation differs from what is documented. So far the following discrepancies have been identified:
Currently, the Random Number Generator (RNG) is not properly tested due to complications with static initialization in OpenSSL, resulting in (perceived) memory leaks. This needs to be analyzed and improved.
When running with OpenSSL debug binaries, the storeutl
command runs into a failed assertion during shutdown:
> openssl storeutl -engine engine-ncrypt -certs cert:/LocalMachine/My
engine "engine-ncrypt" set.
0: Name: cert:/LocalMachine/My/9b85e433216f91999362fe38d8729ee74a098950
CN=RSAlice
1: Name: cert:/LocalMachine/My/1cdb52270cde175e62e876551bcd56b21bad84c4
CN=ECCharlie
Total found: 2
Assertion failed: lh_OSSL_STORE_LOADER_num_items(loader_register) == 0, file crypto\store\store_register.c, line 279
This could be an issue with the storeutl
tool not properly calling the right clean up methods, or with the engine implementation. The tests in gtest-engine-ncrypt
do not exhibit this behavior.
OpenSSL's SSL/TLS implementation uses a different mode for setting the IV when doing AES-GCM, where a number of bytes is kept fixed and the rest is randomly generated. This mode is selected via the (undocumented) control command EVP_CTRL_GCM_SET_IV_FIXED
.
To allow the CNG Engine users to leverage the bcrypt engine for the AES-GCM algorithm when doing SSL/TLS, this mode needs to be added.
Documentation will be hosted on Read the Docs for now. This issue is for setting up the initial configurations and layout. Chapter details will be created under their own issues.
Documentation contents are supposed to be added exclusively via its own branch develop-docs
to avoid merge conflicts.
I have built the CNG engine for OpenSSL 1.1.1s with VS2019 on a Windows 10 machine with no problems, but when I attempt to load the engine dynamically from the command line, I am seeing the following output:
C:\Program Files\OpenSSL\bin>openssl engine dynamic -pre SO_PATH:engine-bcrypt -pre LOAD
(dynamic) Dynamic engine loading support
[Success]: SO_PATH:engine-bcrypt
[Failure]: LOAD
I have tried adding the engine .dll to the OPENSSL_ENGINES path and also set OPENSSL_CONF to point to a configuration file in which I define the engine as laid out in Read the Docs. As there is no debug output I am wondering what may be the issue / how to see debug output with regards to the failure.
The (undocumented) function ENGINE_set_load_ssl_client_cert_function()
allows for a convenient but less complete mechanism for loading certificates and their keys from a store, as an alternative to using the STORE
API. This can be used, for example, via the s_client
and s_server
OpenSSL applications.
Hi there!
I'm attempting to build the engine with just Visual Studio Build tools 2019 (not full Visual Studio), and I'm looking for some help with these error messages:
C:\Users\adams\source\openssl-cng-engine\src\c_cmn_ossl.h(20,10): fatal error C1083: Cannot ope
n include file: 'openssl/ossl_typ.h': No such file or directory [C:\Users\adams\source\openssl-
cng-engine\msbuild\lib-common.vcxproj]
C:\Users\adams\source\openssl-cng-engine\src\c_cmn_ossl.h(20,10): fatal error C1083: Cannot ope
n include file: 'openssl/ossl_typ.h': No such file or directory [C:\Users\adams\source\openssl-
cng-engine\msbuild\lib-common.vcxproj]
I had to modify the build script to skip the VS_WHERE stuff, and hardcoded the VS_DEVCMD:
SET VS_DEVCMD=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat
Are the errors above a common thing, or is this more likely an issue with skipping full VS?
Thanks!
Adam
CNG does not seem to support the generation of multi-prime RSA keys. OpenSSL's RSA method struct does have functions for it, which are currently not overridden by the BCrypt engine.
To avoid inadvertent key generation by OpenSSL's internal functions, it seems required to override the multi-prime RSA key generation functions by stubs that do nothing but generating an error. This needs to be verified though.
This includes the initial contents of the "Welcome" and "About" sections.
This is intended as a blanket issue for minor improvements to the documentation.
Currently none of the projects builds or runs with the Address Sanitizer enabled.
None of the search functionality documented in OSSL_STORE_SEARCH is currently implemented by the ncrypt
engine.
Development happens off of the develop
branch which needs to be set up and populated.
Similar to RSA-PSS for signing, the RSA-OAEP is needed for encryption.
A standard mechanism within OpenSSL is to use the preprocessor symbol OPENSSL_NO_ERR
to indicate that error codes and their associated messages should not be compiled in.
Disabling error messages decreases the size of the resulting binary but also makes it harder to analyse error situations.
The functional tests for the symmetric cipher(s) are currently limited to 256 bits keys and they verify authenticated encryption and decryption only. Additionally needed are
I'm interesting in performing mutual TLS (mTLS)-based client authentication with CNG-stored private keys. The private keys will be stored in a Trusted Platform Module (TPM) for hardware-enforced non-exportability.
It's nice to see that this project can be used to access certificates in the Windows certificate store based on thumbprint with openssl storeutl -certs -out cert.pem cert:/CurrentUser/My/<thumbprint>
. The corresponding openssl storeutl -keys -out cert.key cert:/CurrentUser/My/<thumbprint>
seem to give an opaque NCrypt handle instead of the actual private key. This is kind of expected since the private key is non-exportable. However, I still don't really understand how to use it for crypto purposes like a mTLS handshake.
I've already tried using the public key & opaque NCrypt handle for mTLS authentication with openssl s_client -connect localhost:443 -cert cert.pem -key cert.key -state -debug
, but am then encountering a "unable to load client certificate private key file" error. I guess the reason is that s_client
isn't extended with awareness of the opaque NCrypt handle format(?)
Is there any support for using the opaque NCrypt handle to perform a mTLS handshake, either in this repo or associated OpenSSL repo(s)?
Implementing RSA-PSS is not possible using the standard RSA signing method implemented in libcrypto
. It should be possible to work around this using a new EVP_PKEY_METHOD
though.
Although engines are often intended to be dynamically loaded/loadable, this may not always be the desired configuration. In stead, statically linkable versions may be needed. The Visual Studio solution does not include any option for that.
Microsoft's source-code annotation language (SAL) seems a useful extension that allows for better source code analysis. Its usage in this code base should be explored.
OpenSSL's TLS implementation relies on the bug reported in OpenSSL Issue 12609. Until this is fixed, bcrypt-engine
has to be adjusted to similarly ignore the siglen
parameter. Otherwise, uninitialized memory may be accessed:
openssl-cng-engine/src/e_bcrypt_pkey.c
Line 90 in 974393f
Hi
I would like add inthe documentation how to use a server using CNG Store. This would be very useful for newbies who would want to use a openssl server without coding.
1.>Open command in Admin mode
2.> make sure to set the path of the engine-ncrypt.dll in the path variable
3.> notepad ncrypt.conf
openssl_conf = openssl_init
[openssl_init]
engines = engine_section
[engine_section]
ncrypt = ncrypt_section
[ncrypt_section]
dynamic_path = engine-ncrypt
init = 1
debug_level = 2
default_algorithms = ALL
4.> set OPENSSL_CONF=ncrypt.conf
to test if engine is loaded or not…
5.> openssl engine dynamic -pre SO_PATH:engine-ncrypt -pre LOAD
C:\WINDOWS\system32>openssl engine dynamic -pre SO_PATH:engine-ncrypt -pre LOAD
(dynamic) Dynamic engine loading support
[Success]: SO_PATH:engine-ncrypt
[Success]: LOAD
Loaded: (engine-ncrypt) CryptoAPI: Next Gen (CNG) NCrypt STORE Engine
6.#How to get certificate thumbprint
openssl storeutl -engine engine-ncrypt -certs cert:/LocalMachine/test345
C:\WINDOWS\system32>openssl storeutl -engine engine-ncrypt -certs cert:/LocalMachine/test345
engine "engine-ncrypt" set.
0: Name: cert:/LocalMachine/test345/6a167fb45ffb4da9f723baf038ccd06a071edb1c
C=IN, S=KAR, L=BAN, O=ABC, OU=bility, CN=aazing.example.com, E=[email protected]
Total found: 1
#How to get public certificate from cert uri
C:\Users\INRAK103\Downloads>openssl storeutl -engine engine-ncrypt -certs cert:/LocalMachine/test345/6a167fb45ffb4da9f723baf038ccd06a071edb1c > ncrypt.pem [delete engine “engine-encrypt set, certificate, Total found: 1”
engine "engine-ncrypt" set.
0: Certificate
-----BEGIN CERTIFICATE-----
MIIDkTCCAnkCFHIJRb0rRA7Q0zGwa9k43BRWt0nOMA0GCSqGSIb3DQEBCwUAMIGD
MQswCQYDVQQGEwJJTjEMMAoGA1UECAwDS0FSMQwwCgYDVQQHDANCQU4xDDAKBgNV
BAoMA0FCQjEQMA4GA1UECwwHYWJpbGl0eTEXMBUGA1UEAwwOY2EuYWJpbGl0eS5j
b20xHzAdBgkqhkiG9w0BCQEWEGNhLnJhZ2hhQGFiYi5jb20wHhcNMjEwNDA2MTMw
ODQ1WhcNMjYwNDA1MTMwODQ1WjCBhTELMAkGA1UEBhMCSU4xDDAKBgNVBAgMA0tB
UjEMMAoGA1UEBwwDQkFOMQwwCgYDVQQKDANBQkIxEDAOBgNVBAsMB2FiaWxpdHkx
HDAaBgNVBAMME2thYXppbmcuZXhhbXBsZS5jb20xHDAaBgkqhkiG9w0BCQEWDXJh
Z2hhQGFiYi5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDEwVkP
sjdN9NBP/P0CGkvFbaWQbSNH13qecM7m10VhzxQDlLJEfS5y4ZS+SsgutMSX+7Kz
Xqq1HucyTInFn2i9AEJiJnUuCcH0cJNBi5yB9AYYJQeRjOPvI/cptHUFvA6BUdo9
TJuNtyrc/q2qUEFR7sgUgCx6SutZUglq6lYRBXc03INu9DkZ4GAk3QvbDnX1jOP4
MGw2Z18w8NxfVmsbaGVh4ssfgQWtvG3ucxy5tvDVnk0FQwkTdNp1h/EzvFmIA1n2
ZubOQ0n3vKNRoJa60yr+JA8rD2rJ++JJsleqYUsafaVzRgQMAo0VqjZ1Z0Eq18MV
nwlYWPxm/vYzKE2jAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAHIaoFOpFSvFMtzi
hlUVkYainVWtK8AvuHV3VR1Z5KTqbY4WJEa0I8+DRCh3gvPlgkIuaXGTBUvRAic0
1i9FT6h/lIgzWSOF+NZvMLtinQm8ND5dRgrEs0SgF8ytvu1v0QvtP5losljLH3hS
m6E8/tO5BWLWf2pfzG2BC+S5HomNuPlZwbGoYs7h3BiW7g7wL2TiLUUEdhBHDyu
JnpzLr53fsdd77K6QvLh8Vb6cy+qUST+eSRuns8WB/AJAaWRVftBR0LtbCcY8S1
QswoiuNtl8GxOUowMMHFEHBDU8wCauixGBuf8RoFsD2g6+ENWlvtP42ztaFPYkg
I7/MJAs=
-----END CERTIFICATE-----
Total found: 1
#How to get a encrypted key from the store
openssl storeutl -engine engine-ncrypt -keys cert:/LocalMachine/test345/6a167fb45ffb4da9f723baf038ccd06a071edb1c
#We cannot provide both key and cert point to the store. Instead export the public certificate to a file and then point key to the cert store.
openssl s_server -accept 9200 -status -msg -engine engine-ncrypt -keyform engine -key cert:/LocalMachine/test345/6a167fb45ffb4da9f723baf038ccd06a071edb1c -cert ncrypt.pem -tlsextdebug
C:\Users\INRAK103\Downloads>openssl s_server -accept 9200 -status -msg -engine engine-ncrypt -keyform engine -key cert:/LocalMachine/test345/6a167fb45ffb4da9f723baf038ccd06a071edb1c -cert ncrypt.pem -tlsextdebug
engine "engine-ncrypt" set.
Calling cng_store_load_privkey uri=cert:/LocalMachine/test345/6a167fb45ffb4da9f723baf038ccd06a071edb1c
Using default temp DH parameters
ACCEPT
openssl s_client -connect aazing.example.com:9200 -CAfile myCA.pem
Note: In windows hosts file map this host name to loopback ip.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.