From 70398dbf60f09487b0cb1eddf0dfa0d013aac43f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Mon, 11 May 2020 17:55:37 +0000 Subject: [PATCH] crypto: allow KeyObjects in postMessage This change allows sharing KeyObjects between threads via postMessage. The receiver acquires a new KeyObject and a new KeyObjectHandle, but refers to the same KeyObjectData: +-------------------+ | NativeKeyObject 1 | ------------------------------------------+ +-------------------+ | ^ | extends | | | +-------------------+ +-------------------+ | | KeyObject 1 (JS) | -> | KeyObjectHandle 1 | --------------+ | +-------------------+ +-------------------+ | | | | | | | | | | | | +-------------------+ | | | NativeKeyObject 2 | ------------------------------------+ | | +-------------------+ | | | ^ | | | extends | | | | | | | +-------------------+ +-------------------+ | | | | KeyObject 2 (JS) | -> | KeyObjectHandle 2 | --------+ | | | +-------------------+ +-------------------+ | | | | | | | | | | | | | | | | | | | | | | | | +-------------------+ | | | | | NativeKeyObject 3 | ------------------------------+ | | | | +-------------------+ | | | | | ^ | | | | | extends | | | | | | v v v v v +-------------------+ +-------------------+ +---------------+ | KeyObject 3 (JS) | -> | KeyObjectHandle 3 | -> | KeyObjectData | +-------------------+ +-------------------+ +---------------+ Co-authored-by: Anna Henningsen PR-URL: https://github.com/nodejs/node/pull/33360 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- doc/api/crypto.md | 9 ++ doc/api/worker_threads.md | 8 +- lib/internal/crypto/keys.js | 13 +- src/env.h | 3 + src/node_crypto.cc | 117 +++++++++++++----- src/node_crypto.h | 67 ++++++++-- .../test-crypto-key-objects-messageport.js | 87 +++++++++++++ 7 files changed, 252 insertions(+), 52 deletions(-) create mode 100644 test/parallel/test-crypto-key-objects-messageport.js diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 208f415a35847b..d83f1190cb78b7 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1214,6 +1214,10 @@ This can be called many times with new data as it is streamed.