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