Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: net/quic/crypto/quic_server_info.cc

Issue 154933003: Persist server's crypto config data to disk cache for 0-RTT (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with trunk Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/crypto/quic_server_info.h" 5 #include "net/quic/crypto/quic_server_info.h"
6 6
7 #include "base/bind.h" 7 #include <limits>
8
8 #include "base/pickle.h" 9 #include "base/pickle.h"
9 #include "base/strings/string_piece.h" 10
11 using std::string;
12
13 namespace {
14
15 const int kQuicCryptoConfigVersion = 1;
16
17 } // namespace
10 18
11 namespace net { 19 namespace net {
12 20
13 QuicServerInfo::State::State() {} 21 QuicServerInfo::State::State() {}
14 22
15 QuicServerInfo::State::~State() {} 23 QuicServerInfo::State::~State() {}
16 24
17 void QuicServerInfo::State::Clear() { 25 void QuicServerInfo::State::Clear() {
18 data.clear(); 26 server_config->clear();
27 source_address_token->clear();
28 server_config_sig->clear();
29 certs->clear();
19 } 30 }
20 31
21 // TODO(rtenneti): Flesh out the details. 32 void QuicServerInfo::State::SetConfigData(std::string* server_config_arg,
22 QuicServerInfo::QuicServerInfo( 33 std::string* source_address_token_arg,
23 const std::string& hostname) 34 std::vector<std::string>* certs_arg,
24 : hostname_(hostname), 35 std::string* server_config_sig_arg) {
25 weak_factory_(this) { 36 server_config = server_config_arg;
37 source_address_token = source_address_token_arg;
38 certs = certs_arg;
39 server_config_sig = server_config_sig_arg;
40 }
41
42 QuicServerInfo::QuicServerInfo(const string& hostname) : hostname_(hostname) {
26 } 43 }
27 44
28 QuicServerInfo::~QuicServerInfo() { 45 QuicServerInfo::~QuicServerInfo() {
29 } 46 }
30 47
31 const QuicServerInfo::State& QuicServerInfo::state() const { 48 const QuicServerInfo::State& QuicServerInfo::state() const {
32 return state_; 49 return state_;
33 } 50 }
34 51
35 QuicServerInfo::State* QuicServerInfo::mutable_state() { 52 QuicServerInfo::State* QuicServerInfo::mutable_state() {
36 return &state_; 53 return &state_;
37 } 54 }
38 55
39 bool QuicServerInfo::Parse(const std::string& data) { 56 bool QuicServerInfo::Parse(const string& data) {
40 State* state = mutable_state(); 57 State* state = mutable_state();
41 58
59 if (!state->server_config->empty()) {
60 return false;
61 }
62
42 state->Clear(); 63 state->Clear();
43 64
44 bool r = ParseInner(data); 65 bool r = ParseInner(data);
45 if (!r) 66 if (!r) {
46 state->Clear(); 67 state->Clear();
68 }
47 return r; 69 return r;
48 } 70 }
49 71
50 bool QuicServerInfo::ParseInner(const std::string& data) { 72 bool QuicServerInfo::ParseInner(const string& data) {
51 // TODO(rtenneti): restore QuicCryptoClientConfig::CachedState. 73 State* state = mutable_state();
52 // State* state = mutable_state();
53 74
54 // Pickle p(data.data(), data.size()); 75 // No data was read from the disk cache.
55 // PickleIterator iter(p); 76 if (data.empty()) {
77 return false;
78 }
79
80 Pickle p(data.data(), data.size());
81 PickleIterator iter(p);
82
83 int version = -1;
84 if (!p.ReadInt(&iter, &version)) {
85 DVLOG(1) << "Missing version";
86 return false;
87 }
88
89 if (version != kQuicCryptoConfigVersion) {
90 DVLOG(1) << "Unsupported version";
91 return false;
92 }
93
94 if (!p.ReadString(&iter, state->server_config)) {
95 DVLOG(1) << "Malformed server_config";
96 return false;
97 }
98 if (!p.ReadString(&iter, state->source_address_token)) {
99 DVLOG(1) << "Malformed source_address_token";
100 return false;
101 }
102 if (!p.ReadString(&iter, state->server_config_sig)) {
103 DVLOG(1) << "Malformed server_config_sig";
104 return false;
105 }
106
107 // Read certs.
108 uint32 num_certs;
109 if (!p.ReadUInt32(&iter, &num_certs)) {
110 DVLOG(1) << "Malformed num_certs";
111 return false;
112 }
113
114 for (uint32 i = 0; i < num_certs; i++) {
115 string cert;
116 if (!p.ReadString(&iter, &cert)) {
117 DVLOG(1) << "Malformed cert";
118 return false;
119 }
120 state->certs->push_back(cert);
121 }
56 122
57 return true; 123 return true;
58 } 124 }
59 125
60 std::string QuicServerInfo::Serialize() const { 126 string QuicServerInfo::Serialize() const {
61 Pickle p(sizeof(Pickle::Header)); 127 Pickle p(sizeof(Pickle::Header));
62 128
63 // TODO(rtenneti): serialize QuicCryptoClientConfig::CachedState. 129 if (!p.WriteInt(kQuicCryptoConfigVersion) ||
64 return std::string(reinterpret_cast<const char *>(p.data()), p.size()); 130 !p.WriteString(*state_.server_config) ||
131 !p.WriteString(*state_.source_address_token) ||
132 !p.WriteString(*state_.server_config_sig) ||
133 state_.certs->size() > std::numeric_limits<uint32>::max() ||
134 !p.WriteUInt32(state_.certs->size())) {
135 return string();
136 }
137
138 for (size_t i = 0; i < state_.certs->size(); i++) {
139 if (!p.WriteString((*state_.certs)[i])) {
140 return string();
141 }
142 }
143
144 return string(reinterpret_cast<const char *>(p.data()), p.size());
65 } 145 }
66 146
67 QuicServerInfoFactory::~QuicServerInfoFactory() {} 147 QuicServerInfoFactory::~QuicServerInfoFactory() {}
68 148
69 } // namespace net 149 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698