crypto: avoid throwing key brand checks by panva · Pull Request #65503 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions lib/internal/crypto/keys.js
18 changes: 18 additions & 0 deletions src/crypto/crypto_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1695,12 +1695,15 @@ void NativeKeyObject::Initialize(Environment* env, Local<Object> target) {
NativeKeyObject::CreateNativeKeyObjectClass);
SetMethod(
env->context(), target, "getKeyObjectSlots", NativeKeyObject::GetSlots);
SetMethodNoSideEffect(
env->context(), target, "isKeyObject", NativeKeyObject::IsKeyObject);
}

void NativeKeyObject::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(NativeKeyObject::CreateNativeKeyObjectClass);
registry->Register(NativeKeyObject::GetSlots);
registry->Register(NativeKeyObject::IsKeyObject);
registry->Register(NativeKeyObject::New);
}

Expand All @@ -1709,6 +1712,12 @@ bool NativeKeyObject::HasInstance(Environment* env, Local<Value> value) {
return !t.IsEmpty() && t->HasInstance(value);
}

void NativeKeyObject::IsKeyObject(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_EQ(args.Length(), 1);
args.GetReturnValue().Set(HasInstance(env, args[0]));
}

void NativeKeyObject::New(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_EQ(args.Length(), 1);
Expand Down Expand Up @@ -1839,12 +1848,15 @@ void NativeCryptoKey::Initialize(Environment* env, Local<Object> target) {
NativeCryptoKey::CreateCryptoKeyClass);
SetMethod(
env->context(), target, "getCryptoKeySlots", NativeCryptoKey::GetSlots);
SetMethodNoSideEffect(
env->context(), target, "isCryptoKey", NativeCryptoKey::IsCryptoKey);
}

void NativeCryptoKey::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(NativeCryptoKey::CreateCryptoKeyClass);
registry->Register(NativeCryptoKey::GetSlots);
registry->Register(NativeCryptoKey::IsCryptoKey);
registry->Register(NativeCryptoKey::New);
}

Expand All @@ -1861,6 +1873,12 @@ bool NativeCryptoKey::HasInstance(Environment* env, Local<Value> value) {
return IsNativeCryptoKey(env, value);
}

void NativeCryptoKey::IsCryptoKey(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_EQ(args.Length(), 1);
args.GetReturnValue().Set(HasInstance(env, args[0]));
}

MaybeLocal<Value> NativeCryptoKey::Create(Environment* env,
const KeyObjectData& data,
Local<Value> algorithm,
Expand Down
2 changes: 2 additions & 0 deletions src/crypto/crypto_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class NativeKeyObject : public BaseObject {
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CreateNativeKeyObjectClass(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsKeyObject(const v8::FunctionCallbackInfo<v8::Value>& args);

// True if `value` is a real NativeKeyObject instance. Uses the
// FunctionTemplate stored on the Environment as a brand check.
Expand Down Expand Up @@ -277,6 +278,7 @@ class NativeCryptoKey : public BaseObject {
static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
static void CreateCryptoKeyClass(
const v8::FunctionCallbackInfo<v8::Value>& args);
static void IsCryptoKey(const v8::FunctionCallbackInfo<v8::Value>& args);

static v8::MaybeLocal<v8::Value> Create(Environment* env,
const KeyObjectData& data,
Expand Down
2 changes: 2 additions & 0 deletions typings/internalBinding/crypto.d.ts
Loading