Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory safe TLS in Node.js #7

Open
kevinburke1 opened this issue Feb 13, 2021 · 0 comments
Open

Memory safe TLS in Node.js #7

kevinburke1 opened this issue Feb 13, 2021 · 0 comments

Comments

@kevinburke1
Copy link

kevinburke1 commented Feb 13, 2021

Node ships with its own vendored OpenSSL in deps/openssl. Still you can try to compile in your own with the --shared-openssl, --shared-openssl-include and --shared-openssl-libpath flags. I tried compiling in mesalink in place of OpenSSL and got this error:

In file included from ../src/node.cc:45:
In file included from ../src/node_crypto.h:31:
In file included from ../src/crypto/crypto_aes.h:6:
In file included from ../src/crypto/crypto_cipher.h:6:
In file included from ../src/crypto/crypto_keys.h:6:
../src/crypto/crypto_util.h:17:10: fatal error: 'openssl/ec.h' file not found
#include <openssl/ec.h>
         ^~~~~~~~~~~~~~
1 error generated.
make[1]: *** [libnode.target.mk:467: /Users/kevin/src/github.com/nodejs/node/out/Release/obj.target/libnode/src/node.o] Error 1
rm ccd3dc533142c730cad81819404fde1dda793e8d.intermediate
make: *** [Makefile:104: node] Error 2

The interface to OpenSSL is contained entirely in src/crypto which has this nice README: https://github.com/nodejs/node/tree/master/src/crypto#nodejs-srccrypto-documentation

There is a note in there about how the Electron distribution ships with BoringSSL so in terms of replacing OpenSSL that might be the first place to look, in terms of how they made in more portable.

This might be a good place to start in src/crypto/crypto_x509.cc, trying to replace SSL_get_certificate with a safer parser.

void X509Certificate::Verify(const FunctionCallbackInfo<Value>& args) {
  X509Certificate* cert;
  ASSIGN_OR_RETURN_UNWRAP(&cert, args.Holder());

  CHECK(args[0]->IsObject());
  KeyObjectHandle* key;
  ASSIGN_OR_RETURN_UNWRAP(&key, args[0]);
  CHECK_EQ(key->Data()->GetKeyType(), kKeyTypePublic);

  args.GetReturnValue().Set(
      X509_verify(
          cert->get(),
          key->Data()->GetAsymmetricKey().get()) > 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant