From 6e08bb94e8b1aaf913cf88106cb59f9d2ae85925 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Fri, 12 Sep 2014 13:27:22 +0100 Subject: [PATCH] crypto: export externals to internal structs Export External getters for a internal structs: SSL, SSL_CTX. --- src/node_crypto.cc | 32 ++++++++++++++++++++++++++++++++ src/node_crypto.h | 4 ++++ src/node_internals.h | 15 +++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 5d8a9f5de0..44ed4e09a0 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -81,6 +81,7 @@ using v8::Boolean; using v8::Context; using v8::EscapableHandleScope; using v8::Exception; +using v8::External; using v8::False; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -286,6 +287,11 @@ void SecureContext::Initialize(Environment* env, Handle target) { "getIssuer", SecureContext::GetCertificate); + NODE_SET_EXTERNAL( + t->PrototypeTemplate(), + "_external", + CtxGetter); + target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext"), t->GetFunction()); env->set_secure_context_constructor_template(t); @@ -956,6 +962,16 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo& args) { } +void SecureContext::CtxGetter(Local property, + const PropertyCallbackInfo& info) { + HandleScope scope(info.GetIsolate()); + + SSL_CTX* ctx = Unwrap(info.Holder())->ctx_; + Local ext = External::New(info.GetIsolate(), ctx); + info.GetReturnValue().Set(ext); +} + + template void SecureContext::GetCertificate(const FunctionCallbackInfo& args) { HandleScope scope(args.GetIsolate()); @@ -1008,6 +1024,11 @@ void SSLWrap::AddMethods(Environment* env, Handle t) { NODE_SET_PROTOTYPE_METHOD(t, "getNegotiatedProtocol", GetNegotiatedProto); NODE_SET_PROTOTYPE_METHOD(t, "setNPNProtocols", SetNPNProtocols); #endif // OPENSSL_NPN_NEGOTIATED + + NODE_SET_EXTERNAL( + t->PrototypeTemplate(), + "_external", + SSLGetter); } @@ -1846,6 +1867,17 @@ int SSLWrap::TLSExtStatusCallback(SSL* s, void* arg) { #endif // NODE__HAVE_TLSEXT_STATUS_CB +template +void SSLWrap::SSLGetter(Local property, + const PropertyCallbackInfo& info) { + HandleScope scope(info.GetIsolate()); + + SSL* ssl = Unwrap(info.Holder())->ssl_; + Local ext = External::New(info.GetIsolate(), ssl); + info.GetReturnValue().Set(ext); +} + + void Connection::OnClientHelloParseEnd(void* arg) { Connection* conn = static_cast(arg); diff --git a/src/node_crypto.h b/src/node_crypto.h index 3c46e0c11e..1a719b9058 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -105,6 +105,8 @@ class SecureContext : public BaseObject { static void LoadPKCS12(const v8::FunctionCallbackInfo& args); static void GetTicketKeys(const v8::FunctionCallbackInfo& args); static void SetTicketKeys(const v8::FunctionCallbackInfo& args); + static void CtxGetter(v8::Local property, + const v8::PropertyCallbackInfo& info); template static void GetCertificate(const v8::FunctionCallbackInfo& args); @@ -237,6 +239,8 @@ class SSLWrap { void* arg); #endif // OPENSSL_NPN_NEGOTIATED static int TLSExtStatusCallback(SSL* s, void* arg); + static void SSLGetter(v8::Local property, + const v8::PropertyCallbackInfo& info); inline Environment* ssl_env() const { return env_; diff --git a/src/node_internals.h b/src/node_internals.h index d38a3f019f..253bd38d96 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -216,6 +216,21 @@ NODE_DEPRECATED("Use ThrowUVException(isolate)", return ThrowUVException(isolate, errorno, syscall, message, path); }) +inline void NODE_SET_EXTERNAL(v8::Handle target, + const char* key, + v8::AccessorGetterCallback getter) { + v8::Isolate* isolate = v8::Isolate::GetCurrent(); + v8::HandleScope handle_scope(isolate); + v8::Local prop = v8::String::NewFromUtf8(isolate, key); + target->SetAccessor(prop, + getter, + NULL, + v8::Handle(), + v8::DEFAULT, + static_cast(v8::ReadOnly | + v8::DontDelete)); +} + } // namespace node #endif // SRC_NODE_INTERNALS_H_