From c2b23f9148c10401897a0e6ed460823490f322ff Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 15 Feb 2020 18:55:59 +0100 Subject: [PATCH] tls: expose SSL_export_keying_material via tlsSocket.exportKeyingMaterial --- doc/api/errors.md | 11 +- doc/api/tls.md | 34 ++++++ lib/_tls_wrap.js | 21 +++- lib/internal/errors.js | 2 + src/node_crypto.cc | 40 +++++++ src/node_crypto.h | 2 + .../parallel/test-tls-exportkeyingmaterial.js | 102 ++++++++++++++++++ 7 files changed, 209 insertions(+), 3 deletions(-) create mode 100644 test/parallel/test-tls-exportkeyingmaterial.js diff --git a/doc/api/errors.md b/doc/api/errors.md index b186275807aee7..d64afba591a4b7 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1831,7 +1831,7 @@ recommended to use 2048 bits or larger for stronger security. A TLS/SSL handshake timed out. In this case, the server must also abort the connection. - + ### `ERR_TLS_INVALID_CONTEXT` + +The TLS socket must be connected and securily established. Ensure the 'secure' +event is emitted, before you continue. + ### `ERR_TLS_INVALID_PROTOCOL_METHOD` diff --git a/doc/api/tls.md b/doc/api/tls.md index fee6e33d610581..3341e6e9ea514b 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -1094,6 +1094,39 @@ See [SSL_get_shared_sigalgs](https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html) for more information. +### `tlsSocket.exportKeyingMaterial(length, label[, context])` + + +* `length` {number} number of bytes to retrieve from keying material +* `label` {string} an application specific label, typically this will be a +value from the +[IANA Exporter Label Registry](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#exporter-labels). +* `context` {Buffer} Optionally provide a context. + +* Returns: {Buffer} requested bytes of the keying material + +Keying material is used for validations to prevent different kind of attacks in +network protocols, for example in the specifications of IEEE 802.1X. + +Example + +```js +const keyingMaterial = tlsSocket.exportKeyingMaterial( + 128, + 'client finished'); + +/** + Example return value of keyingMaterial: + +*/ +``` +See the OpenSSL [`SSL_export_keying_material`][] documentation for more +information. + ### `tlsSocket.getTLSTicket()`