OLD | NEW |
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* vim: set ts=2 et sw=2 tw=80: */ | 2 /* vim: set ts=2 et sw=2 tw=80: */ |
3 /* This Source Code Form is subject to the terms of the Mozilla Public | 3 /* This Source Code Form is subject to the terms of the Mozilla Public |
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, | 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ | 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | 6 |
7 #ifndef tls_parser_h_ | 7 #ifndef tls_parser_h_ |
8 #define tls_parser_h_ | 8 #define tls_parser_h_ |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 #include <string.h> | 12 #include <string.h> |
13 #include <arpa/inet.h> | 13 #include <arpa/inet.h> |
14 #include "databuffer.h" | 14 #include "databuffer.h" |
15 | 15 |
16 const uint8_t kTlsChangeCipherSpecType = 0x14; | 16 const uint8_t kTlsChangeCipherSpecType = 0x14; |
17 const uint8_t kTlsHandshakeType = 0x16; | 17 const uint8_t kTlsHandshakeType = 0x16; |
18 | 18 |
19 const uint8_t kTlsHandshakeCertificate = 0x0b; | 19 const uint8_t kTlsHandshakeCertificate = 0x0b; |
20 const uint8_t kTlsHandshakeServerKeyExchange = 0x0c; | 20 const uint8_t kTlsHandshakeServerKeyExchange = 0x0c; |
21 | 21 |
22 const uint8_t kTlsFakeChangeCipherSpec[] = { | 22 const uint8_t kTlsFakeChangeCipherSpec[] = {kTlsChangeCipherSpecType, // Type |
23 kTlsChangeCipherSpecType, // Type | 23 0xfe, 0xff, // Version |
24 0xfe, 0xff, // Version | 24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
25 0x00, 0x00, 0x00, 0x00, | 25 0x00, |
26 0x00, 0x00, 0x00, 0x10, // Fictitious sequence # | 26 0x10, // Fictitious sequence # |
27 0x00, 0x01, // Length | 27 0x00, 0x01, // Length |
28 0x01 // Value | 28 0x01 // Value |
29 }; | 29 }; |
30 | 30 |
31 class TlsParser { | 31 class TlsParser { |
32 public: | 32 public: |
33 TlsParser(const unsigned char *data, size_t len) | 33 TlsParser(const unsigned char *data, size_t len) |
34 : buffer_(data, len), offset_(0) {} | 34 : buffer_(data, len), offset_(0) {} |
35 | 35 |
36 bool Read(unsigned char *val); | 36 bool Read(unsigned char *val); |
37 | 37 |
38 // Read an integral type of specified width. | 38 // Read an integral type of specified width. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 private: | 74 private: |
75 size_t remaining() const { return buffer_.len() - offset_; } | 75 size_t remaining() const { return buffer_.len() - offset_; } |
76 const uint8_t *ptr() const { return buffer_.data() + offset_; } | 76 const uint8_t *ptr() const { return buffer_.data() + offset_; } |
77 void consume(size_t len) { offset_ += len; } | 77 void consume(size_t len) { offset_ += len; } |
78 | 78 |
79 DataBuffer buffer_; | 79 DataBuffer buffer_; |
80 size_t offset_; | 80 size_t offset_; |
81 }; | 81 }; |
82 | 82 |
83 #endif | 83 #endif |
OLD | NEW |