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: 10 10 100.0 %
Date: 2017-06-14 Branches: 0 0 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 "node.h"
28
29
#include <stddef.h>  // size_t
30
#include <stdlib.h>  // nullptr
31
32
namespace node {
33
34
class ClientHelloParser {
35
 public:
36
10738
  ClientHelloParser() : state_(kEnded),
37
                        onhello_cb_(nullptr),
38
                        onend_cb_(nullptr),
39
                        cb_arg_(nullptr),
40
                        session_size_(0),
41
                        session_id_(nullptr),
42
                        servername_size_(0),
43
                        servername_(nullptr),
44
                        ocsp_request_(0),
45
                        tls_ticket_size_(0),
46
10738
                        tls_ticket_(nullptr) {
47
10738
    Reset();
48
10738
  }
49
50
  class ClientHello {
51
   public:
52
23
    inline uint8_t session_size() const { return session_size_; }
53
23
    inline const uint8_t* session_id() const { return session_id_; }
54
23
    inline bool has_ticket() const { return has_ticket_; }
55
20
    inline uint8_t servername_size() const { return servername_size_; }
56
43
    inline const uint8_t* servername() const { return servername_; }
57
23
    inline int ocsp_request() const { return ocsp_request_; }
58
59
   private:
60
    uint8_t session_size_;
61
    const uint8_t* session_id_;
62
    bool has_ticket_;
63
    uint8_t servername_size_;
64
    const uint8_t* servername_;
65
    int ocsp_request_;
66
67
    friend class ClientHelloParser;
68
  };
69
70
  typedef void (*OnHelloCb)(void* arg, const ClientHello& hello);
71
  typedef void (*OnEndCb)(void* arg);
72
73
  void Parse(const uint8_t* data, size_t avail);
74
75
  inline void Reset();
76
  inline void Start(OnHelloCb onhello_cb, OnEndCb onend_cb, void* onend_arg);
77
  inline void End();
78
  inline bool IsPaused() const;
79
  inline bool IsEnded() const;
80
81
 private:
82
  static const size_t kMaxTLSFrameLen = 16 * 1024 + 5;
83
  static const size_t kMaxSSLExFrameLen = 32 * 1024;
84
  static const uint8_t kServernameHostname = 0;
85
  static const uint8_t kStatusRequestOCSP = 1;
86
  static const size_t kMinStatusRequestSize = 5;
87
88
  enum ParseState {
89
    kWaiting,
90
    kTLSHeader,
91
    kPaused,
92
    kEnded
93
  };
94
95
  enum FrameType {
96
    kChangeCipherSpec = 20,
97
    kAlert = 21,
98
    kHandshake = 22,
99
    kApplicationData = 23,
100
    kOther = 255
101
  };
102
103
  enum HandshakeType {
104
    kClientHello = 1
105
  };
106
107
  enum ExtensionType {
108
    kServerName = 0,
109
    kStatusRequest = 5,
110
    kTLSSessionTicket = 35
111
  };
112
113
  bool ParseRecordHeader(const uint8_t* data, size_t avail);
114
  void ParseHeader(const uint8_t* data, size_t avail);
115
  void ParseExtension(const uint16_t type,
116
                      const uint8_t* data,
117
                      size_t len);
118
  bool ParseTLSClientHello(const uint8_t* data, size_t avail);
119
120
  ParseState state_;
121
  OnHelloCb onhello_cb_;
122
  OnEndCb onend_cb_;
123
  void* cb_arg_;
124
  size_t frame_len_;
125
  size_t body_offset_;
126
  size_t extension_offset_;
127
  uint8_t session_size_;
128
  const uint8_t* session_id_;
129
  uint16_t servername_size_;
130
  const uint8_t* servername_;
131
  uint8_t ocsp_request_;
132
  uint16_t tls_ticket_size_;
133
  const uint8_t* tls_ticket_;
134
};
135
136
}  // namespace node
137
138
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
139
140
#endif  // SRC_NODE_CRYPTO_CLIENTHELLO_H_