| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eb20447 commit 6c9b19a
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -247,72 +247,89 @@ void GetRootCertificates(const FunctionCallbackInfo<Value>& args) { | |||
| 247 | 247 | Array::New(env->isolate(), result, arraysize(root_certs))); | |
| 248 | 248 | } | |
| 249 | 249 | ||
| 250 | - void SecureContext::Initialize(Environment* env, Local<Object> target) { | ||
| 251 | - Local<FunctionTemplate> t = env->NewFunctionTemplate(New); | ||
| 252 | - t->InstanceTemplate()->SetInternalFieldCount( | ||
| 253 | - SecureContext::kInternalFieldCount); | ||
| 254 | - t->Inherit(BaseObject::GetConstructorTemplate(env)); | ||
| 255 | - | ||
| 256 | - env->SetProtoMethod(t, "init", Init); | ||
| 257 | - env->SetProtoMethod(t, "setKey", SetKey); | ||
| 258 | - #ifndef OPENSSL_NO_ENGINE | ||
| 259 | - env->SetProtoMethod(t, "setEngineKey", SetEngineKey); | ||
| 260 | - #endif // !OPENSSL_NO_ENGINE | ||
| 261 | - env->SetProtoMethod(t, "setCert", SetCert); | ||
| 262 | - env->SetProtoMethod(t, "addCACert", AddCACert); | ||
| 263 | - env->SetProtoMethod(t, "addCRL", AddCRL); | ||
| 264 | - env->SetProtoMethod(t, "addRootCerts", AddRootCerts); | ||
| 265 | - env->SetProtoMethod(t, "setCipherSuites", SetCipherSuites); | ||
| 266 | - env->SetProtoMethod(t, "setCiphers", SetCiphers); | ||
| 267 | - env->SetProtoMethod(t, "setSigalgs", SetSigalgs); | ||
| 268 | - env->SetProtoMethod(t, "setECDHCurve", SetECDHCurve); | ||
| 269 | - env->SetProtoMethod(t, "setDHParam", SetDHParam); | ||
| 270 | - env->SetProtoMethod(t, "setMaxProto", SetMaxProto); | ||
| 271 | - env->SetProtoMethod(t, "setMinProto", SetMinProto); | ||
| 272 | - env->SetProtoMethod(t, "getMaxProto", GetMaxProto); | ||
| 273 | - env->SetProtoMethod(t, "getMinProto", GetMinProto); | ||
| 274 | - env->SetProtoMethod(t, "setOptions", SetOptions); | ||
| 275 | - env->SetProtoMethod(t, "setSessionIdContext", SetSessionIdContext); | ||
| 276 | - env->SetProtoMethod(t, "setSessionTimeout", SetSessionTimeout); | ||
| 277 | - env->SetProtoMethod(t, "close", Close); | ||
| 278 | - env->SetProtoMethod(t, "loadPKCS12", LoadPKCS12); | ||
| 279 | - #ifndef OPENSSL_NO_ENGINE | ||
| 280 | - env->SetProtoMethod(t, "setClientCertEngine", SetClientCertEngine); | ||
| 281 | - #endif // !OPENSSL_NO_ENGINE | ||
| 282 | - env->SetProtoMethodNoSideEffect(t, "getTicketKeys", GetTicketKeys); | ||
| 283 | - env->SetProtoMethod(t, "setTicketKeys", SetTicketKeys); | ||
| 284 | - env->SetProtoMethod(t, "setFreeListLength", SetFreeListLength); | ||
| 285 | - env->SetProtoMethod(t, "enableTicketKeyCallback", EnableTicketKeyCallback); | ||
| 286 | - env->SetProtoMethodNoSideEffect(t, "getCertificate", GetCertificate<true>); | ||
| 287 | - env->SetProtoMethodNoSideEffect(t, "getIssuer", GetCertificate<false>); | ||
| 288 | - | ||
| 289 | - #define SET_INTEGER_CONSTANTS(name, value) \ | ||
| 290 | - t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), name), \ | ||
| 291 | - Integer::NewFromUnsigned(env->isolate(), value)); | ||
| 292 | - SET_INTEGER_CONSTANTS("kTicketKeyReturnIndex", kTicketKeyReturnIndex); | ||
| 293 | - SET_INTEGER_CONSTANTS("kTicketKeyHMACIndex", kTicketKeyHMACIndex); | ||
| 294 | - SET_INTEGER_CONSTANTS("kTicketKeyAESIndex", kTicketKeyAESIndex); | ||
| 295 | - SET_INTEGER_CONSTANTS("kTicketKeyNameIndex", kTicketKeyNameIndex); | ||
| 296 | - SET_INTEGER_CONSTANTS("kTicketKeyIVIndex", kTicketKeyIVIndex); | ||
| 297 | - | ||
| 298 | - #undef SET_INTEGER_CONSTANTS | ||
| 299 | - | ||
| 300 | - Local<FunctionTemplate> ctx_getter_templ = | ||
| 301 | - FunctionTemplate::New(env->isolate(), | ||
| 302 | - CtxGetter, | ||
| 303 | - Local<Value>(), | ||
| 304 | - Signature::New(env->isolate(), t)); | ||
| 305 | - | ||
| 306 | - | ||
| 307 | - t->PrototypeTemplate()->SetAccessorProperty( | ||
| 308 | - FIXED_ONE_BYTE_STRING(env->isolate(), "_external"), | ||
| 309 | - ctx_getter_templ, | ||
| 310 | - Local<FunctionTemplate>(), | ||
| 311 | - static_cast<PropertyAttribute>(ReadOnly | DontDelete)); | ||
| 250 | + bool SecureContext::HasInstance(Environment* env, const Local<Value>& value) { | ||
| 251 | + return GetConstructorTemplate(env)->HasInstance(value); | ||
| 252 | + } | ||
| 312 | 253 | ||
| 313 | - env->SetConstructorFunction(target, "SecureContext", t); | ||
| 254 | + Local<FunctionTemplate> SecureContext::GetConstructorTemplate( | ||
| 255 | + Environment* env) { | ||
| 256 | + Local<FunctionTemplate> tmpl = env->secure_context_constructor_template(); | ||
| 257 | + if (tmpl.IsEmpty()) { | ||
| 258 | + tmpl = env->NewFunctionTemplate(New); | ||
| 259 | + tmpl->InstanceTemplate()->SetInternalFieldCount( | ||
| 260 | + SecureContext::kInternalFieldCount); | ||
| 261 | + tmpl->Inherit(BaseObject::GetConstructorTemplate(env)); | ||
| 262 | + tmpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "SecureContext")); | ||
| 263 | + | ||
| 264 | + env->SetProtoMethod(tmpl, "init", Init); | ||
| 265 | + env->SetProtoMethod(tmpl, "setKey", SetKey); | ||
| 266 | + env->SetProtoMethod(tmpl, "setCert", SetCert); | ||
| 267 | + env->SetProtoMethod(tmpl, "addCACert", AddCACert); | ||
| 268 | + env->SetProtoMethod(tmpl, "addCRL", AddCRL); | ||
| 269 | + env->SetProtoMethod(tmpl, "addRootCerts", AddRootCerts); | ||
| 270 | + env->SetProtoMethod(tmpl, "setCipherSuites", SetCipherSuites); | ||
| 271 | + env->SetProtoMethod(tmpl, "setCiphers", SetCiphers); | ||
| 272 | + env->SetProtoMethod(tmpl, "setSigalgs", SetSigalgs); | ||
| 273 | + env->SetProtoMethod(tmpl, "setECDHCurve", SetECDHCurve); | ||
| 274 | + env->SetProtoMethod(tmpl, "setDHParam", SetDHParam); | ||
| 275 | + env->SetProtoMethod(tmpl, "setMaxProto", SetMaxProto); | ||
| 276 | + env->SetProtoMethod(tmpl, "setMinProto", SetMinProto); | ||
| 277 | + env->SetProtoMethod(tmpl, "getMaxProto", GetMaxProto); | ||
| 278 | + env->SetProtoMethod(tmpl, "getMinProto", GetMinProto); | ||
| 279 | + env->SetProtoMethod(tmpl, "setOptions", SetOptions); | ||
| 280 | + env->SetProtoMethod(tmpl, "setSessionIdContext", SetSessionIdContext); | ||
| 281 | + env->SetProtoMethod(tmpl, "setSessionTimeout", SetSessionTimeout); | ||
| 282 | + env->SetProtoMethod(tmpl, "close", Close); | ||
| 283 | + env->SetProtoMethod(tmpl, "loadPKCS12", LoadPKCS12); | ||
| 284 | + env->SetProtoMethod(tmpl, "setTicketKeys", SetTicketKeys); | ||
| 285 | + env->SetProtoMethod(tmpl, "setFreeListLength", SetFreeListLength); | ||
| 286 | + env->SetProtoMethod(tmpl, "enableTicketKeyCallback", | ||
| 287 | + EnableTicketKeyCallback); | ||
| 288 | + | ||
| 289 | + env->SetProtoMethodNoSideEffect(tmpl, "getTicketKeys", GetTicketKeys); | ||
| 290 | + env->SetProtoMethodNoSideEffect(tmpl, "getCertificate", | ||
| 291 | + GetCertificate<true>); | ||
| 292 | + env->SetProtoMethodNoSideEffect(tmpl, "getIssuer", | ||
| 293 | + GetCertificate<false>); | ||
| 294 | + | ||
| 295 | + #ifndef OPENSSL_NO_ENGINE | ||
| 296 | + env->SetProtoMethod(tmpl, "setEngineKey", SetEngineKey); | ||
| 297 | + env->SetProtoMethod(tmpl, "setClientCertEngine", SetClientCertEngine); | ||
| 298 | + #endif // !OPENSSL_NO_ENGINE | ||
| 299 | + | ||
| 300 | + #define SET_INTEGER_CONSTANTS(name, value) \ | ||
| 301 | + tmpl->Set(FIXED_ONE_BYTE_STRING(env->isolate(), name), \ | ||
| 302 | + Integer::NewFromUnsigned(env->isolate(), value)); | ||
| 303 | + SET_INTEGER_CONSTANTS("kTicketKeyReturnIndex", kTicketKeyReturnIndex); | ||
| 304 | + SET_INTEGER_CONSTANTS("kTicketKeyHMACIndex", kTicketKeyHMACIndex); | ||
| 305 | + SET_INTEGER_CONSTANTS("kTicketKeyAESIndex", kTicketKeyAESIndex); | ||
| 306 | + SET_INTEGER_CONSTANTS("kTicketKeyNameIndex", kTicketKeyNameIndex); | ||
| 307 | + SET_INTEGER_CONSTANTS("kTicketKeyIVIndex", kTicketKeyIVIndex); | ||
| 308 | + #undef SET_INTEGER_CONSTANTS | ||
| 309 | + | ||
| 310 | + Local<FunctionTemplate> ctx_getter_templ = | ||
| 311 | + FunctionTemplate::New(env->isolate(), | ||
| 312 | + CtxGetter, | ||
| 313 | + Local<Value>(), | ||
| 314 | + Signature::New(env->isolate(), tmpl)); | ||
| 315 | + | ||
| 316 | + tmpl->PrototypeTemplate()->SetAccessorProperty( | ||
| 317 | + FIXED_ONE_BYTE_STRING(env->isolate(), "_external"), | ||
| 318 | + ctx_getter_templ, | ||
| 319 | + Local<FunctionTemplate>(), | ||
| 320 | + static_cast<PropertyAttribute>(ReadOnly | DontDelete)); | ||
| 321 | + | ||
| 322 | + env->set_secure_context_constructor_template(tmpl); | ||
| 323 | + } | ||
| 324 | + return tmpl; | ||
| 325 | + } | ||
| 314 | 326 | ||
| 315 | - env->set_secure_context_constructor_template(t); | ||
| 327 | + void SecureContext::Initialize(Environment* env, Local<Object> target) { | ||
| 328 | + env->SetConstructorFunction( | ||
| 329 | + target, | ||
| 330 | + "SecureContext", | ||
| 331 | + GetConstructorTemplate(env), | ||
| 332 | + Environment::SetConstructorFunctionFlag::NONE); | ||
| 316 | 333 | ||
| 317 | 334 | env->SetMethodNoSideEffect(target, "getRootCertificates", | |
| 318 | 335 | GetRootCertificates); | |
@@ -321,6 +338,17 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) { | |||
| 321 | 338 | IsExtraRootCertsFileLoaded); | |
| 322 | 339 | } | |
| 323 | 340 | ||
| 341 | + SecureContext* SecureContext::Create(Environment* env) { | ||
| 342 | + Local<Object> obj; | ||
| 343 | + if (!GetConstructorTemplate(env) | ||
| 344 | + ->InstanceTemplate() | ||
| 345 | + ->NewInstance(env->context()).ToLocal(&obj)) { | ||
| 346 | + return nullptr; | ||
| 347 | + } | ||
| 348 | + | ||
| 349 | + return new SecureContext(env, obj); | ||
| 350 | + } | ||
| 351 | + | ||
| 324 | 352 | SecureContext::SecureContext(Environment* env, Local<Object> wrap) | |
| 325 | 353 | : BaseObject(env, wrap) { | |
| 326 | 354 | MakeWeak(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,7 +34,11 @@ class SecureContext final : public BaseObject { | |||
| 34 | 34 | ||
| 35 | 35 | ~SecureContext() override; | |
| 36 | 36 | ||
| 37 | + static bool HasInstance(Environment* env, const v8::Local<v8::Value>& value); | ||
| 38 | + static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( | ||
| 39 | + Environment* env); | ||
| 37 | 40 | static void Initialize(Environment* env, v8::Local<v8::Object> target); | |
| 41 | + static SecureContext* Create(Environment* env); | ||
| 38 | 42 | ||
| 39 | 43 | SSL_CTX* operator*() const { return ctx_.get(); } | |
| 40 | 44 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,6 +98,7 @@ void NativeModuleLoader::InitializeModuleCategories() { | |||
| 98 | 98 | "tls", | |
| 99 | 99 | "_tls_common", | |
| 100 | 100 | "_tls_wrap", | |
| 101 | + "internal/tls", | ||
| 101 | 102 | "internal/http2/core", | |
| 102 | 103 | "internal/http2/compat", | |
| 103 | 104 | "internal/policy/manifest", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments