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

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

Issue 1076063002: Remove certificates from Channel ID (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
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/channel_id_chromium.h" 5 #include "net/quic/crypto/channel_id_chromium.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 int DoLoop(int last_io_result); 80 int DoLoop(int last_io_result);
81 void OnIOComplete(int result); 81 void OnIOComplete(int result);
82 int DoGetChannelIDKey(int result); 82 int DoGetChannelIDKey(int result);
83 int DoGetChannelIDKeyComplete(int result); 83 int DoGetChannelIDKeyComplete(int result);
84 84
85 // Channel ID source to notify when this jobs completes. 85 // Channel ID source to notify when this jobs completes.
86 ChannelIDSourceChromium* const channel_id_source_; 86 ChannelIDSourceChromium* const channel_id_source_;
87 87
88 ChannelIDService* const channel_id_service_; 88 ChannelIDService* const channel_id_service_;
89 89
90 std::string channel_id_private_key_; 90 scoped_ptr<crypto::ECPrivateKey> channel_id_crypto_key_;
91 std::string channel_id_cert_;
92 ChannelIDService::RequestHandle channel_id_request_handle_; 91 ChannelIDService::RequestHandle channel_id_request_handle_;
93 92
94 // |hostname| specifies the hostname for which we need a channel ID. 93 // |hostname| specifies the hostname for which we need a channel ID.
95 std::string hostname_; 94 std::string hostname_;
96 95
97 scoped_ptr<ChannelIDSourceCallback> callback_; 96 scoped_ptr<ChannelIDSourceCallback> callback_;
98 97
99 scoped_ptr<ChannelIDKey> channel_id_key_; 98 scoped_ptr<ChannelIDKey> channel_id_key_;
100 99
101 State next_state_; 100 State next_state_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 callback->Run(&channel_id_key_); 170 callback->Run(&channel_id_key_);
172 // Will delete |this|. 171 // Will delete |this|.
173 channel_id_source_->OnJobComplete(this); 172 channel_id_source_->OnJobComplete(this);
174 } 173 }
175 } 174 }
176 175
177 int ChannelIDSourceChromium::Job::DoGetChannelIDKey(int result) { 176 int ChannelIDSourceChromium::Job::DoGetChannelIDKey(int result) {
178 next_state_ = STATE_GET_CHANNEL_ID_KEY_COMPLETE; 177 next_state_ = STATE_GET_CHANNEL_ID_KEY_COMPLETE;
179 178
180 return channel_id_service_->GetOrCreateChannelID( 179 return channel_id_service_->GetOrCreateChannelID(
181 hostname_, 180 hostname_, &channel_id_crypto_key_,
182 &channel_id_private_key_,
183 &channel_id_cert_,
184 base::Bind(&ChannelIDSourceChromium::Job::OnIOComplete, 181 base::Bind(&ChannelIDSourceChromium::Job::OnIOComplete,
185 base::Unretained(this)), 182 base::Unretained(this)),
186 &channel_id_request_handle_); 183 &channel_id_request_handle_);
187 } 184 }
188 185
189 int ChannelIDSourceChromium::Job::DoGetChannelIDKeyComplete(int result) { 186 int ChannelIDSourceChromium::Job::DoGetChannelIDKeyComplete(int result) {
190 DCHECK_EQ(STATE_NONE, next_state_); 187 DCHECK_EQ(STATE_NONE, next_state_);
191 if (result != OK) { 188 if (result != OK) {
192 DLOG(WARNING) << "Failed to look up channel ID: " << ErrorToString(result); 189 DLOG(WARNING) << "Failed to look up channel ID: " << ErrorToString(result);
193 return result; 190 return result;
194 } 191 }
195 192
196 std::vector<uint8> encrypted_private_key_info( 193 crypto::ECPrivateKey* ec_private_key = channel_id_crypto_key_.get();
197 channel_id_private_key_.size());
198 memcpy(&encrypted_private_key_info[0], channel_id_private_key_.data(),
199 channel_id_private_key_.size());
200
201 base::StringPiece spki_piece;
202 if (!asn1::ExtractSPKIFromDERCert(channel_id_cert_, &spki_piece)) {
203 return ERR_UNEXPECTED;
204 }
205 std::vector<uint8> subject_public_key_info(spki_piece.size());
206 memcpy(&subject_public_key_info[0], spki_piece.data(), spki_piece.size());
207
208 crypto::ECPrivateKey* ec_private_key =
209 crypto::ECPrivateKey::CreateFromEncryptedPrivateKeyInfo(
210 ChannelIDService::kEPKIPassword, encrypted_private_key_info,
211 subject_public_key_info);
212 if (!ec_private_key) { 194 if (!ec_private_key) {
213 // TODO(wtc): use the new error code ERR_CHANNEL_ID_IMPORT_FAILED to be 195 // TODO(wtc): use the new error code ERR_CHANNEL_ID_IMPORT_FAILED to be
214 // added in https://codereview.chromium.org/338093012/. 196 // added in https://codereview.chromium.org/338093012/.
215 return ERR_UNEXPECTED; 197 return ERR_UNEXPECTED;
216 } 198 }
217 channel_id_key_.reset(new ChannelIDKeyChromium(ec_private_key)); 199 channel_id_key_.reset(new ChannelIDKeyChromium(ec_private_key));
mattm 2015/04/10 01:00:27 Doesn't this mean channel_id_crypto_key_ and chann
nharper 2015/04/25 02:59:18 I've fixed the ownership issues here so that chann
218 200
219 return result; 201 return result;
220 } 202 }
221 203
222 ChannelIDSourceChromium::ChannelIDSourceChromium( 204 ChannelIDSourceChromium::ChannelIDSourceChromium(
223 ChannelIDService* channel_id_service) 205 ChannelIDService* channel_id_service)
224 : channel_id_service_(channel_id_service) { 206 : channel_id_service_(channel_id_service) {
225 } 207 }
226 208
227 ChannelIDSourceChromium::~ChannelIDSourceChromium() { 209 ChannelIDSourceChromium::~ChannelIDSourceChromium() {
(...skipping 12 matching lines...) Expand all
240 } 222 }
241 return status; 223 return status;
242 } 224 }
243 225
244 void ChannelIDSourceChromium::OnJobComplete(Job* job) { 226 void ChannelIDSourceChromium::OnJobComplete(Job* job) {
245 active_jobs_.erase(job); 227 active_jobs_.erase(job);
246 delete job; 228 delete job;
247 } 229 }
248 230
249 } // namespace net 231 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698