1 // Copyright Joyent, Inc. and other Node contributors.
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to permit
8 // persons to whom the Software is furnished to do so, subject to the
9 // following conditions:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 // USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef SRC_TLS_WRAP_H_
23 #define SRC_TLS_WRAP_H_
26 #include "node_crypto.h" // SSLWrap
28 #include "async-wrap.h"
31 #include "stream_wrap.h"
34 #include <openssl/ssl.h>
38 // Forward-declarations
45 class TLSCallbacks : public crypto::SSLWrap<TLSCallbacks>,
46 public StreamWrapCallbacks,
49 static void Initialize(v8::Handle<v8::Object> target,
50 v8::Handle<v8::Value> unused,
51 v8::Handle<v8::Context> context);
53 int DoWrite(WriteWrap* w,
56 uv_stream_t* send_handle,
58 void AfterWrite(WriteWrap* w);
59 void DoAlloc(uv_handle_t* handle,
60 size_t suggested_size,
62 void DoRead(uv_stream_t* handle,
65 uv_handle_type pending);
66 int DoShutdown(ShutdownWrap* req_wrap, uv_shutdown_cb cb);
69 static const int kClearOutChunkSize = 1024;
71 // Write callback queue's item
74 WriteItem(WriteWrap* w, uv_write_cb cb) : w_(w), cb_(cb) {
86 TLSCallbacks(Environment* env,
88 v8::Handle<v8::Object> sc,
89 StreamWrapCallbacks* old);
92 static void SSLInfoCallback(const SSL* ssl_, int where, int ret);
95 static void EncOutCb(uv_write_t* req, int status);
98 void InvokeQueued(int status);
100 inline void Cycle() {
106 v8::Local<v8::Value> GetSSLError(int status, int* err);
107 static void OnClientHelloParseEnd(void* arg);
109 static void Wrap(const v8::FunctionCallbackInfo<v8::Value>& args);
110 static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
111 static void SetVerifyMode(const v8::FunctionCallbackInfo<v8::Value>& args);
112 static void EnableSessionCallbacks(
113 const v8::FunctionCallbackInfo<v8::Value>& args);
114 static void EnableHelloParser(
115 const v8::FunctionCallbackInfo<v8::Value>& args);
117 #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
118 static void GetServername(const v8::FunctionCallbackInfo<v8::Value>& args);
119 static void SetServername(const v8::FunctionCallbackInfo<v8::Value>& args);
120 static int SelectSNIContextCallback(SSL* s, int* ad, void* arg);
121 #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
123 crypto::SecureContext* sc_;
124 v8::Persistent<v8::Object> sc_handle_;
128 uv_write_t write_req_;
130 size_t write_queue_size_;
131 QUEUE write_item_queue_;
132 WriteItem* pending_write_item_;
137 #ifdef SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
138 v8::Persistent<v8::Value> sni_context_;
139 #endif // SSL_CTRL_SET_TLSEXT_SERVERNAME_CB
144 #endif // SRC_TLS_WRAP_H_