GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/out/../src/node_crypto_clienthello.h Lines: 2 2 100.0 %
Date: 2016-11-30 Branches: 0 0 0.0 %

Line Branch Exec Source
1
#ifndef SRC_NODE_CRYPTO_CLIENTHELLO_H_
2
#define SRC_NODE_CRYPTO_CLIENTHELLO_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "node.h"
7
8
#include <stddef.h>  // size_t
9
#include <stdlib.h>  // nullptr
10
11
namespace node {
12
13
class ClientHelloParser {
14
 public:
15
  ClientHelloParser() : state_(kEnded),
16
                        onhello_cb_(nullptr),
17
                        onend_cb_(nullptr),
18
                        cb_arg_(nullptr),
19
                        session_size_(0),
20
                        session_id_(nullptr),
21
                        servername_size_(0),
22
                        servername_(nullptr),
23
                        ocsp_request_(0),
24
                        tls_ticket_size_(0),
25
610
                        tls_ticket_(nullptr) {
26
610
    Reset();
27
  }
28
29
  class ClientHello {
30
   public:
31
    inline uint8_t session_size() const { return session_size_; }
32
    inline const uint8_t* session_id() const { return session_id_; }
33
    inline bool has_ticket() const { return has_ticket_; }
34
    inline uint8_t servername_size() const { return servername_size_; }
35
    inline const uint8_t* servername() const { return servername_; }
36
    inline int ocsp_request() const { return ocsp_request_; }
37
38
   private:
39
    uint8_t session_size_;
40
    const uint8_t* session_id_;
41
    bool has_ticket_;
42
    uint8_t servername_size_;
43
    const uint8_t* servername_;
44
    int ocsp_request_;
45
46
    friend class ClientHelloParser;
47
  };
48
49
  typedef void (*OnHelloCb)(void* arg, const ClientHello& hello);
50
  typedef void (*OnEndCb)(void* arg);
51
52
  void Parse(const uint8_t* data, size_t avail);
53
54
  inline void Reset();
55
  inline void Start(OnHelloCb onhello_cb, OnEndCb onend_cb, void* onend_arg);
56
  inline void End();
57
  inline bool IsPaused() const;
58
  inline bool IsEnded() const;
59
60
 private:
61
  static const size_t kMaxTLSFrameLen = 16 * 1024 + 5;
62
  static const size_t kMaxSSLExFrameLen = 32 * 1024;
63
  static const uint8_t kServernameHostname = 0;
64
  static const uint8_t kStatusRequestOCSP = 1;
65
  static const size_t kMinStatusRequestSize = 5;
66
67
  enum ParseState {
68
    kWaiting,
69
    kTLSHeader,
70
    kPaused,
71
    kEnded
72
  };
73
74
  enum FrameType {
75
    kChangeCipherSpec = 20,
76
    kAlert = 21,
77
    kHandshake = 22,
78
    kApplicationData = 23,
79
    kOther = 255
80
  };
81
82
  enum HandshakeType {
83
    kClientHello = 1
84
  };
85
86
  enum ExtensionType {
87
    kServerName = 0,
88
    kStatusRequest = 5,
89
    kTLSSessionTicket = 35
90
  };
91
92
  bool ParseRecordHeader(const uint8_t* data, size_t avail);
93
  void ParseHeader(const uint8_t* data, size_t avail);
94
  void ParseExtension(const uint16_t type,
95
                      const uint8_t* data,
96
                      size_t len);
97
  bool ParseTLSClientHello(const uint8_t* data, size_t avail);
98
99
  ParseState state_;
100
  OnHelloCb onhello_cb_;
101
  OnEndCb onend_cb_;
102
  void* cb_arg_;
103
  size_t frame_len_;
104
  size_t body_offset_;
105
  size_t extension_offset_;
106
  uint8_t session_size_;
107
  const uint8_t* session_id_;
108
  uint16_t servername_size_;
109
  const uint8_t* servername_;
110
  uint8_t ocsp_request_;
111
  uint16_t tls_ticket_size_;
112
  const uint8_t* tls_ticket_;
113
};
114
115
}  // namespace node
116
117
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
118
119
#endif  // SRC_NODE_CRYPTO_CLIENTHELLO_H_