22 #ifndef SRC_TLS_WRAP_H_ 23 #define SRC_TLS_WRAP_H_ 25 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 36 #include <openssl/ssl.h> 47 class TLSWrap :
public AsyncWrap,
48 public crypto::SSLWrap<TLSWrap>,
53 static void Initialize(v8::Local<v8::Object> target,
54 v8::Local<v8::Value> unused,
55 v8::Local<v8::Context> context);
57 void* Cast()
override;
59 bool IsAlive()
override;
60 bool IsClosing()
override;
63 int ReadStart()
override;
64 int ReadStop()
override;
66 int DoShutdown(ShutdownWrap* req_wrap)
override;
67 int DoWrite(WriteWrap* w,
70 uv_stream_t* send_handle)
override;
71 const char* Error()
const override;
72 void ClearError()
override;
74 void NewSessionDoneCb();
76 size_t self_size()
const override {
return sizeof(*this); }
78 void clear_stream() { stream_ =
nullptr; }
81 static const int kClearOutChunkSize = 16384;
84 static const int kMaxHelloLength = 16384;
87 static const int kInitialClientBufferLength = 4096;
90 static const int kSimultaneousBufferCount = 10;
95 explicit WriteItem(WriteWrap* w) : w_(w) {
102 ListNode<WriteItem> member_;
105 TLSWrap(Environment* env,
108 crypto::SecureContext* sc);
110 static void SSLInfoCallback(
const SSL* ssl_,
int where,
int ret);
113 static void EncOutCb(WriteWrap* req_wrap,
int status);
117 bool InvokeQueued(
int status,
const char* error_str =
nullptr);
119 inline void Cycle() {
121 if (++cycle_depth_ > 1)
124 for (; cycle_depth_ > 0; cycle_depth_--) {
131 AsyncWrap* GetAsyncWrap()
override;
132 bool IsIPCPipe()
override;
135 static void OnAfterWriteImpl(WriteWrap* w,
void*
ctx);
136 static void OnAllocImpl(
size_t size, uv_buf_t*
buf,
void*
ctx);
137 static void OnReadImpl(ssize_t nread,
139 uv_handle_type pending,
141 static void OnAfterWriteSelf(WriteWrap* w,
void*
ctx);
142 static void OnAllocSelf(
size_t size, uv_buf_t*
buf,
void*
ctx);
143 static void OnReadSelf(ssize_t nread,
145 uv_handle_type pending,
147 static void OnDestructImpl(
void*
ctx);
149 void DoRead(ssize_t nread,
const uv_buf_t*
buf, uv_handle_type pending);
152 v8::Local<v8::Value> GetSSLError(
int status,
int* err,
const char** msg);
154 static void OnClientHelloParseEnd(
void* arg);
155 static void Wrap(
const v8::FunctionCallbackInfo<v8::Value>& args);
156 static void Receive(
const v8::FunctionCallbackInfo<v8::Value>& args);
157 static void Start(
const v8::FunctionCallbackInfo<v8::Value>& args);
158 static void SetVerifyMode(
const v8::FunctionCallbackInfo<v8::Value>& args);
159 static void EnableSessionCallbacks(
160 const v8::FunctionCallbackInfo<v8::Value>& args);
161 static void EnableCertCb(
162 const v8::FunctionCallbackInfo<v8::Value>& args);
163 static void DestroySSL(
const v8::FunctionCallbackInfo<v8::Value>& args);
165 #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 166 static void GetServername(
const v8::FunctionCallbackInfo<v8::Value>& args);
167 static void SetServername(
const v8::FunctionCallbackInfo<v8::Value>& args);
168 static int SelectSNIContextCallback(SSL*
s,
int* ad,
void* arg);
169 #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 171 crypto::SecureContext* sc_;
175 crypto::NodeBIO* clear_in_;
177 typedef ListHead<WriteItem, &WriteItem::member_> WriteItemList;
178 WriteItemList write_item_queue_;
179 WriteItemList pending_write_items_;
193 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 195 #endif // SRC_TLS_WRAP_H_
void Initialize(Local< Object > target, Local< Value > unused, Local< Context > context, void *priv)
int Start(Isolate *isolate, IsolateData *isolate_data, int argc, const char *const *argv, int exec_argc, const char *const *exec_argv)