GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/tls_wrap.h Lines: 11 11 100.0 %
Date: 2019-01-07 12:15:22 Branches: 4 4 100.0 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
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:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
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.
21
22
#ifndef SRC_TLS_WRAP_H_
23
#define SRC_TLS_WRAP_H_
24
25
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
27
#include "node.h"
28
#include "node_crypto.h"  // SSLWrap
29
30
#include "async_wrap.h"
31
#include "env.h"
32
#include "stream_wrap.h"
33
#include "v8.h"
34
35
#include <openssl/ssl.h>
36
37
#include <string>
38
39
namespace node {
40
41
// Forward-declarations
42
class WriteWrap;
43
namespace crypto {
44
class SecureContext;
45
class NodeBIO;
46
}
47
48
class TLSWrap : public AsyncWrap,
49
                public crypto::SSLWrap<TLSWrap>,
50
                public StreamBase,
51
                public StreamListener {
52
 public:
53
  ~TLSWrap() override;
54
55
  static void Initialize(v8::Local<v8::Object> target,
56
                         v8::Local<v8::Value> unused,
57
                         v8::Local<v8::Context> context,
58
                         void* priv);
59
60
  int GetFD() override;
61
  bool IsAlive() override;
62
  bool IsClosing() override;
63
64
  // JavaScript functions
65
  int ReadStart() override;
66
  int ReadStop() override;
67
68
  ShutdownWrap* CreateShutdownWrap(
69
      v8::Local<v8::Object> req_wrap_object) override;
70
  int DoShutdown(ShutdownWrap* req_wrap) override;
71
  int DoWrite(WriteWrap* w,
72
              uv_buf_t* bufs,
73
              size_t count,
74
              uv_stream_t* send_handle) override;
75
  const char* Error() const override;
76
  void ClearError() override;
77
78
  void NewSessionDoneCb();
79
80
  void MemoryInfo(MemoryTracker* tracker) const override;
81
82
2
  SET_MEMORY_INFO_NAME(TLSWrap)
83
2
  SET_SELF_SIZE(TLSWrap)
84
85
 protected:
86
7213
  inline StreamBase* underlying_stream() {
87
7213
    return static_cast<StreamBase*>(stream_);
88
  }
89
90
  static const int kClearOutChunkSize = 16384;
91
92
  // Maximum number of bytes for hello parser
93
  static const int kMaxHelloLength = 16384;
94
95
  // Usual ServerHello + Certificate size
96
  static const int kInitialClientBufferLength = 4096;
97
98
  // Maximum number of buffers passed to uv_write()
99
  static const int kSimultaneousBufferCount = 10;
100
101
  TLSWrap(Environment* env,
102
          Kind kind,
103
          StreamBase* stream,
104
          crypto::SecureContext* sc);
105
106
  static void SSLInfoCallback(const SSL* ssl_, int where, int ret);
107
  void InitSSL();
108
  void EncOut();
109
  bool ClearIn();
110
  void ClearOut();
111
  bool InvokeQueued(int status, const char* error_str = nullptr);
112
113
4599
  inline void Cycle() {
114
    // Prevent recursion
115
4599
    if (++cycle_depth_ > 1)
116
4606
      return;
117
118
9185
    for (; cycle_depth_ > 0; cycle_depth_--) {
119
4599
      ClearIn();
120
4599
      ClearOut();
121
4597
      EncOut();
122
    }
123
  }
124
125
  AsyncWrap* GetAsyncWrap() override;
126
  bool IsIPCPipe() override;
127
128
  // Resource implementation
129
  void OnStreamAfterWrite(WriteWrap* w, int status) override;
130
  uv_buf_t OnStreamAlloc(size_t size) override;
131
  void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override;
132
133
  v8::Local<v8::Value> GetSSLError(int status, int* err, std::string* msg);
134
135
  static void OnClientHelloParseEnd(void* arg);
136
  static void Wrap(const v8::FunctionCallbackInfo<v8::Value>& args);
137
  static void Receive(const v8::FunctionCallbackInfo<v8::Value>& args);
138
  static void Start(const v8::FunctionCallbackInfo<v8::Value>& args);
139
  static void SetVerifyMode(const v8::FunctionCallbackInfo<v8::Value>& args);
140
  static void EnableSessionCallbacks(
141
      const v8::FunctionCallbackInfo<v8::Value>& args);
142
  static void EnableCertCb(
143
      const v8::FunctionCallbackInfo<v8::Value>& args);
144
  static void DestroySSL(const v8::FunctionCallbackInfo<v8::Value>& args);
145
  static void GetServername(const v8::FunctionCallbackInfo<v8::Value>& args);
146
  static void SetServername(const v8::FunctionCallbackInfo<v8::Value>& args);
147
  static int SelectSNIContextCallback(SSL* s, int* ad, void* arg);
148
149
  crypto::SecureContext* sc_;
150
  BIO* enc_in_ = nullptr;
151
  BIO* enc_out_ = nullptr;
152
  std::vector<uv_buf_t> pending_cleartext_input_;
153
  size_t write_size_ = 0;
154
  WriteWrap* current_write_ = nullptr;
155
  WriteWrap* current_empty_write_ = nullptr;
156
  bool write_callback_scheduled_ = false;
157
  bool started_ = false;
158
  bool established_ = false;
159
  bool shutdown_ = false;
160
  std::string error_;
161
  int cycle_depth_ = 0;
162
163
  // If true - delivered EOF to the js-land, either after `close_notify`, or
164
  // after the `UV_EOF` on socket.
165
  bool eof_ = false;
166
167
 private:
168
  static void GetWriteQueueSize(
169
      const v8::FunctionCallbackInfo<v8::Value>& info);
170
};
171
172
}  // namespace node
173
174
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
175
176
#endif  // SRC_TLS_WRAP_H_