1 // Copyright Joyent, Inc. and other Node contributors.
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:
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
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.
22 #ifndef SRC_NODE_CRYPTO_CLIENTHELLO_H_
23 #define SRC_NODE_CRYPTO_CLIENTHELLO_H_
27 #include <stddef.h> // size_t
28 #include <stdlib.h> // NULL
32 class ClientHelloParser {
34 ClientHelloParser() : state_(kEnded),
46 inline uint8_t session_size() const { return session_size_; }
47 inline const uint8_t* session_id() const { return session_id_; }
48 inline bool has_ticket() const { return has_ticket_; }
49 inline uint8_t servername_size() const { return servername_size_; }
50 inline const uint8_t* servername() const { return servername_; }
53 uint8_t session_size_;
54 const uint8_t* session_id_;
56 uint8_t servername_size_;
57 const uint8_t* servername_;
59 friend class ClientHelloParser;
62 typedef void (*OnHelloCb)(void* arg, const ClientHello& hello);
63 typedef void (*OnEndCb)(void* arg);
65 void Parse(const uint8_t* data, size_t avail);
68 inline void Start(OnHelloCb onhello_cb, OnEndCb onend_cb, void* onend_arg);
70 inline bool IsPaused() const;
71 inline bool IsEnded() const;
74 static const uint8_t kSSL2TwoByteHeaderBit = 0x80;
75 static const uint8_t kSSL2HeaderMask = 0x3f;
76 static const size_t kMaxTLSFrameLen = 16 * 1024 + 5;
77 static const size_t kMaxSSLExFrameLen = 32 * 1024;
78 static const uint8_t kServernameHostname = 0;
89 kChangeCipherSpec = 20,
92 kApplicationData = 23,
102 kTLSSessionTicket = 35
105 bool ParseRecordHeader(const uint8_t* data, size_t avail);
106 void ParseHeader(const uint8_t* data, size_t avail);
107 void ParseExtension(ExtensionType type,
110 bool ParseTLSClientHello(const uint8_t* data, size_t avail);
111 #ifdef OPENSSL_NO_SSL2
112 bool ParseSSL2ClientHello(const uint8_t* data, size_t avail);
113 #endif // OPENSSL_NO_SSL2
116 OnHelloCb onhello_cb_;
121 size_t extension_offset_;
122 uint8_t session_size_;
123 const uint8_t* session_id_;
124 uint16_t servername_size_;
125 const uint8_t* servername_;
126 uint16_t tls_ticket_size_;
127 const uint8_t* tls_ticket_;
132 #endif // SRC_NODE_CRYPTO_CLIENTHELLO_H_