GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_crypto_clienthello.h Lines: 5 5 100.0 %
Date: 2019-02-26 22:23:30 Branches: 0 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_NODE_CRYPTO_CLIENTHELLO_H_
23
#define SRC_NODE_CRYPTO_CLIENTHELLO_H_
24
25
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
26
27
#include <stddef.h>  // size_t
28
#include <stdint.h>
29
30
namespace node {
31
namespace crypto {
32
33
// Parse the client hello so we can do async session resumption. OpenSSL's
34
// session resumption uses synchronous callbacks, see SSL_CTX_sess_set_get_cb
35
// and get_session_cb.
36
class ClientHelloParser {
37
 public:
38
  inline ClientHelloParser();
39
40
  class ClientHello {
41
   public:
42
20
    inline uint8_t session_size() const { return session_size_; }
43
20
    inline const uint8_t* session_id() const { return session_id_; }
44
20
    inline bool has_ticket() const { return has_ticket_; }
45
18
    inline uint8_t servername_size() const { return servername_size_; }
46
38
    inline const uint8_t* servername() const { return servername_; }
47
48
   private:
49
    uint8_t session_size_;
50
    const uint8_t* session_id_;
51
    bool has_ticket_;
52
    uint8_t servername_size_;
53
    const uint8_t* servername_;
54
55
    friend class ClientHelloParser;
56
  };
57
58
  typedef void (*OnHelloCb)(void* arg, const ClientHello& hello);
59
  typedef void (*OnEndCb)(void* arg);
60
61
  void Parse(const uint8_t* data, size_t avail);
62
63
  inline void Reset();
64
  inline void Start(OnHelloCb onhello_cb, OnEndCb onend_cb, void* onend_arg);
65
  inline void End();
66
  inline bool IsPaused() const;
67
  inline bool IsEnded() const;
68
69
 private:
70
  static const size_t kMaxTLSFrameLen = 16 * 1024 + 5;
71
  static const size_t kMaxSSLExFrameLen = 32 * 1024;
72
  static const uint8_t kServernameHostname = 0;
73
  static const size_t kMinStatusRequestSize = 5;
74
75
  enum ParseState {
76
    kWaiting,
77
    kTLSHeader,
78
    kPaused,
79
    kEnded
80
  };
81
82
  enum FrameType {
83
    kChangeCipherSpec = 20,
84
    kAlert = 21,
85
    kHandshake = 22,
86
    kApplicationData = 23,
87
    kOther = 255
88
  };
89
90
  enum HandshakeType {
91
    kClientHello = 1
92
  };
93
94
  enum ExtensionType {
95
    kServerName = 0,
96
    kTLSSessionTicket = 35
97
  };
98
99
  bool ParseRecordHeader(const uint8_t* data, size_t avail);
100
  void ParseHeader(const uint8_t* data, size_t avail);
101
  void ParseExtension(const uint16_t type,
102
                      const uint8_t* data,
103
                      size_t len);
104
  bool ParseTLSClientHello(const uint8_t* data, size_t avail);
105
106
  ParseState state_;
107
  OnHelloCb onhello_cb_;
108
  OnEndCb onend_cb_;
109
  void* cb_arg_;
110
  size_t frame_len_ = 0;
111
  size_t body_offset_ = 0;
112
  size_t extension_offset_ = 0;
113
  uint8_t session_size_ = 0;
114
  const uint8_t* session_id_ = nullptr;
115
  uint16_t servername_size_ = 0;
116
  const uint8_t* servername_ = nullptr;
117
  uint16_t tls_ticket_size_ = -1;
118
  const uint8_t* tls_ticket_ = nullptr;
119
};
120
121
}  // namespace crypto
122
}  // namespace node
123
124
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
125
126
#endif  // SRC_NODE_CRYPTO_CLIENTHELLO_H_