|
OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/renderer_host/p2p/ssltcp_helper.h" | |
Mallinath (Gone from Chromium)
2013/06/17 22:13:22
I discovered this lately, there is already code wh
Sergey Ulanov
2013/06/18 20:05:49
That's a good point. Looks like you can just swap
| |
6 | |
7 namespace { | |
8 | |
9 // This is a SSL v2 CLIENT_HELLO message, got from libjingle code | |
10 // talk/base/socketadapters.cc. | |
11 const char kSslClientHello[] = { | |
Sergey Ulanov
2013/06/18 20:01:26
Are these standard? Can other implementation use s
| |
12 0x80, 0x46, // msg len | |
13 0x01, // CLIENT_HELLO | |
14 0x03, 0x01, // SSL 3.1 | |
15 0x00, 0x2d, // ciphersuite len | |
16 0x00, 0x00, // session id len | |
17 0x00, 0x10, // challenge len | |
18 0x01, 0x00, 0x80, 0x03, 0x00, 0x80, 0x07, 0x00, 0xc0, // ciphersuites | |
19 0x06, 0x00, 0x40, 0x02, 0x00, 0x80, 0x04, 0x00, 0x80, // | |
20 0x00, 0x00, 0x04, 0x00, 0xfe, 0xff, 0x00, 0x00, 0x0a, // | |
21 0x00, 0xfe, 0xfe, 0x00, 0x00, 0x09, 0x00, 0x00, 0x64, // | |
22 0x00, 0x00, 0x62, 0x00, 0x00, 0x03, 0x00, 0x00, 0x06, // | |
23 0x1f, 0x17, 0x0c, 0xa6, 0x2f, 0x00, 0x78, 0xfc, // challenge | |
24 0x46, 0x55, 0x2e, 0xb1, 0x83, 0x39, 0xf1, 0xea // | |
25 }; | |
26 | |
27 // This is a TLSv1 SERVER_HELLO message. | |
28 const char kSslServerHello[] = { | |
29 0x16, // handshake message | |
30 0x03, 0x01, // SSL 3.1 | |
31 0x00, 0x4a, // message len | |
32 0x02, // SERVER_HELLO | |
33 0x00, 0x00, 0x46, // handshake len | |
34 0x03, 0x01, // SSL 3.1 | |
35 0x42, 0x85, 0x45, 0xa7, 0x27, 0xa9, 0x5d, 0xa0, // server random | |
36 0xb3, 0xc5, 0xe7, 0x53, 0xda, 0x48, 0x2b, 0x3f, // | |
37 0xc6, 0x5a, 0xca, 0x89, 0xc1, 0x58, 0x52, 0xa1, // | |
38 0x78, 0x3c, 0x5b, 0x17, 0x46, 0x00, 0x85, 0x3f, // | |
39 0x20, // session id len | |
40 0x0e, 0xd3, 0x06, 0x72, 0x5b, 0x5b, 0x1b, 0x5f, // session id | |
41 0x15, 0xac, 0x13, 0xf9, 0x88, 0x53, 0x9d, 0x9b, // | |
42 0xe8, 0x3d, 0x7b, 0x0c, 0x30, 0x32, 0x6e, 0x38, // | |
43 0x4d, 0xa2, 0x75, 0x57, 0x41, 0x6c, 0x34, 0x5c, // | |
44 0x00, 0x04, // RSA/RC4-128/MD5 | |
45 0x00 // null compression | |
46 }; | |
47 } // namespace | |
48 | |
49 namespace content { | |
50 | |
51 size_t client_hello_message_size() { | |
52 return sizeof(kSslClientHello); | |
53 } | |
54 | |
55 size_t server_hello_message_size() { | |
56 return sizeof(kSslServerHello); | |
57 } | |
58 | |
59 SsltcpHelper::SsltcpHelper() | |
60 : client_(true), | |
61 hello_sent_(false), | |
62 hello_received_(false), | |
63 client_hello_message_(client_hello_message_size()), | |
Sergey Ulanov
2013/06/18 20:01:26
client_hello_message_(kSslClientHello, sizeof(kSsl
| |
64 server_hello_message_(server_hello_message_size()) { | |
65 memcpy(&client_hello_message_[0], kSslClientHello, | |
66 client_hello_message_size()); | |
67 memcpy(&server_hello_message_[0], kSslServerHello, | |
68 server_hello_message_size()); | |
69 } | |
70 | |
71 SsltcpHelper::~SsltcpHelper() { | |
72 } | |
73 | |
74 void SsltcpHelper::Init(bool client) { | |
75 client_ = client; | |
76 } | |
77 | |
78 bool SsltcpHelper::IsClient() const { | |
79 return client_; | |
80 } | |
81 | |
82 void SsltcpHelper::set_hello_sent(bool hello_sent) { | |
83 hello_sent_ = hello_sent; | |
84 } | |
85 | |
86 bool SsltcpHelper::hello_sent() const { | |
87 return hello_sent_; | |
88 } | |
89 | |
90 void SsltcpHelper::set_hello_received(bool hello_received) { | |
91 hello_received_ = hello_received; | |
92 } | |
93 | |
94 bool SsltcpHelper::hello_received() const { | |
95 return hello_received_; | |
96 } | |
97 | |
98 const std::vector<char>& SsltcpHelper::client_hello_message() const { | |
99 return client_hello_message_; | |
100 } | |
101 | |
102 const std::vector<char>& SsltcpHelper::server_hello_message() const { | |
103 return server_hello_message_; | |
104 } | |
105 | |
106 bool SsltcpHelper::IsHelloMessage(const char* message) { | |
Sergey Ulanov
2013/06/18 20:01:26
I think it would be better to pass size of the buf
| |
107 const char* expect = client_ ? kSslServerHello : kSslClientHello; | |
Sergey Ulanov
2013/06/18 20:01:26
const std::string& expected = client_ ? server_hel
| |
108 return (memcmp(expect, message, remote_hello_message_size()) == 0); | |
Sergey Ulanov
2013/06/18 20:01:26
nit: IMHO it's less readable with these parenthese
| |
109 } | |
110 | |
111 size_t SsltcpHelper::hello_message_size() { | |
112 return client_ ? client_hello_message_size() : server_hello_message_size(); | |
113 } | |
114 | |
115 size_t SsltcpHelper::remote_hello_message_size() { | |
116 return client_ ? server_hello_message_size() : client_hello_message_size(); | |
117 } | |
118 | |
119 } // namespace content | |
OLD | NEW |