diff options
author | simon <simon.tretter@hokify.com> | 2020-02-15 20:55:59 +0300 |
---|---|---|
committer | Shelley Vohr <shelley.vohr@gmail.com> | 2020-02-27 20:59:31 +0300 |
commit | acb3aff6748e82212b6e35276a1d753595799fe4 (patch) | |
tree | f8c946bb42666851ca93ceccfeaee3d6980302a1 /src/node_crypto.cc | |
parent | 2046652b4e20ad2ed98545239730b8f6cff1824c (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) { |