gost-engine / engine

A reference implementation of the Russian GOST crypto algorithms for OpenSSL
Apache License 2.0
379 stars 174 forks source link

ENGINE_load_private_key can't load key.pem file #441

Closed GauriSpears closed 1 year ago

GauriSpears commented 1 year ago

Debian, OpenSSL 3.0.8, master gost-engine. I'm trying to embed gost TLS support into Node.JS so I recompiled it with shared OpenSSL support. Node.JS loads private key in its tls module only this way: EVPKeyPointer key(ENGINE_load_private_key(engine.get(), *key_name, nullptr, nullptr)); But when I use it for 'gost' and '/path/to/key.pem' I get an error:

library: 'engine routines',
  reason: 'no load function',
  code: 'ERR_OSSL_ENGINE_NO_LOAD_FUNCTION'

As far as I understand It's because gost-engine doesn't implement load function. Can you fix it?

beldmit commented 1 year ago

Yiu should not load the key via Engine method. Openssl 3 still supports engines and loading via smth like https://riptutorial.com/openssl/example/16739/load-private-key . The engine should be loaded via Openssl config file.

GauriSpears commented 1 year ago

Thanks, now I clearly see that it's Node.JS issue! It uses PEM_read_bio_PrivateKey both in src/crypto/crypto_keys.cc/ParsePrivateKey for Sign.sign() routine and in src/crypto/crypto_context.cc/SecureContext::SetKey for tls.createSecureContext calls. But it works only in first place.