Giter VIP home page Giter VIP logo

openssl-cng-engine's People

Contributors

reiniert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openssl-cng-engine's Issues

Implementation is not in line with the documentation

On a few minor points, the implementation differs from what is documented. So far the following discrepancies have been identified:

  • Initialization of engine should work in conjunction with openssl tools
  • Working directory should not have to be set when debugging tests in VS
  • Following the procedures described, the rand method may have been uninitialized

RNG is not properly tested

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.

Assertion fails when using storeutl

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.

Add support for GCM IV_FIXED mode

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.

Create initial setup for documentation

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.

Issue Loading Engine

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.

C1083 error including openssl

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

Stub out RSA multi-prime key generation with functions that do not succeed

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.

Symmetric cipher test cases are incomplete

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

  • Tests for key sizes of 128 and 192 bits
  • Tests that include additional associated data to verify the different AEAD use cases

Support for mTLS authentication with CNG-stored keys?

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

Implement RSA-PSS

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.

Building engines as static libraries is not supported

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.

How to use openssl-cng-engine to open a secure server openssl s_server?

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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.