diff options
author | simon <simon.tretter@hokify.com> | 2020-02-15 20:55:59 +0300 |
---|---|---|
committer | Tobias Nießen <tniessen@tnie.de> | 2020-02-23 08:21:04 +0300 |
commit | 341c06f0889e5295d7a7a34c3e38296bd2c4ac18 (patch) | |
tree | 5d34942566a8ed7aafd7aaf687e88153409bb635 /src/node_crypto.cc | |
parent | fa1fc6bf9f257f7365454dc7a28bb4cd4385919f (diff) |
tls: expose SSL_export_keying_material
Fixes: https://github.com/nodejs/node/issues/31802
PR-URL: https://github.com/nodejs/node/pull/31814
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r-- | src/node_crypto.cc | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index d47cc4e1e82..e129c7f3f59 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1743,6 +1743,8 @@ void SSLWrap<Base>::AddMethods(Environment* env, Local<FunctionTemplate> t) { env->SetProtoMethodNoSideEffect(t, "verifyError", VerifyError); env->SetProtoMethodNoSideEffect(t, "getCipher", GetCipher); env->SetProtoMethodNoSideEffect(t, "getSharedSigalgs", GetSharedSigalgs); + env->SetProtoMethodNoSideEffect( + t, "exportKeyingMaterial", ExportKeyingMaterial); env->SetProtoMethod(t, "endParser", EndParser); env->SetProtoMethod(t, "certCbDone", CertCbDone); env->SetProtoMethod(t, "renegotiate", Renegotiate); @@ -2772,6 +2774,44 @@ void SSLWrap<Base>::GetSharedSigalgs(const FunctionCallbackInfo<Value>& args) { Array::New(env->isolate(), ret_arr.out(), ret_arr.length())); } +template <class Base> +void SSLWrap<Base>::ExportKeyingMaterial( + const FunctionCallbackInfo<Value>& args) { + CHECK(args[0]->IsInt32()); + CHECK(args[1]->IsString()); + + Base* w; + ASSIGN_OR_RETURN_UNWRAP(&w, args.Holder()); + Environment* env = w->ssl_env(); + + uint32_t olen = args[0].As<Uint32>()->Value(); + node::Utf8Value label(env->isolate(), args[1]); + + AllocatedBuffer out = env->AllocateManaged(olen); + + ByteSource key; + + int useContext = 0; + if (!args[2]->IsNull() && Buffer::HasInstance(args[2])) { + key = ByteSource::FromBuffer(args[2]); + + useContext = 1; + } + + if (SSL_export_keying_material(w->ssl_.get(), + reinterpret_cast<unsigned char*>(out.data()), + olen, + *label, + label.length(), + reinterpret_cast<const unsigned char*>( + key.get()), + key.size(), + useContext) != 1) { + return ThrowCryptoError(env, ERR_get_error(), "SSL_export_keying_material"); + } + + args.GetReturnValue().Set(out.ToBuffer().ToLocalChecked()); +} template <class Base> void SSLWrap<Base>::GetProtocol(const FunctionCallbackInfo<Value>& args) { |