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

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: Udpate KeysEqual to fail if preconditions fail Created 5 years, 7 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
« no previous file with comments | « net/quic/crypto/channel_id_chromium.h ('k') | net/quic/test_tools/crypto_test_utils_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "crypto/ec_private_key.h" 11 #include "crypto/ec_private_key.h"
12 #include "crypto/ec_signature_creator.h" 12 #include "crypto/ec_signature_creator.h"
13 #include "net/base/net_errors.h" 13 #include "net/base/net_errors.h"
14 #include "net/cert/asn1_util.h" 14 #include "net/cert/asn1_util.h"
15 #include "net/ssl/channel_id_service.h" 15 #include "net/ssl/channel_id_service.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 ChannelIDKeyChromium::ChannelIDKeyChromium( 19 ChannelIDKeyChromium::ChannelIDKeyChromium(
20 crypto::ECPrivateKey* ec_private_key) 20 scoped_ptr<crypto::ECPrivateKey> ec_private_key)
21 : ec_private_key_(ec_private_key) {} 21 : ec_private_key_(ec_private_key.Pass()) {
22 }
22 23
23 ChannelIDKeyChromium::~ChannelIDKeyChromium() {} 24 ChannelIDKeyChromium::~ChannelIDKeyChromium() {}
24 25
25 bool ChannelIDKeyChromium::Sign(base::StringPiece signed_data, 26 bool ChannelIDKeyChromium::Sign(base::StringPiece signed_data,
26 std::string* out_signature) const { 27 std::string* out_signature) const {
27 scoped_ptr<crypto::ECSignatureCreator> sig_creator( 28 scoped_ptr<crypto::ECSignatureCreator> sig_creator(
28 crypto::ECSignatureCreator::Create(ec_private_key_.get())); 29 crypto::ECSignatureCreator::Create(ec_private_key_.get()));
29 if (!sig_creator) { 30 if (!sig_creator) {
30 return false; 31 return false;
31 } 32 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 int DoLoop(int last_io_result); 81 int DoLoop(int last_io_result);
81 void OnIOComplete(int result); 82 void OnIOComplete(int result);
82 int DoGetChannelIDKey(int result); 83 int DoGetChannelIDKey(int result);
83 int DoGetChannelIDKeyComplete(int result); 84 int DoGetChannelIDKeyComplete(int result);
84 85
85 // Channel ID source to notify when this jobs completes. 86 // Channel ID source to notify when this jobs completes.
86 ChannelIDSourceChromium* const channel_id_source_; 87 ChannelIDSourceChromium* const channel_id_source_;
87 88
88 ChannelIDService* const channel_id_service_; 89 ChannelIDService* const channel_id_service_;
89 90
90 std::string channel_id_private_key_; 91 scoped_ptr<crypto::ECPrivateKey> channel_id_crypto_key_;
91 std::string channel_id_cert_;
92 ChannelIDService::RequestHandle channel_id_request_handle_; 92 ChannelIDService::RequestHandle channel_id_request_handle_;
93 93
94 // |hostname| specifies the hostname for which we need a channel ID. 94 // |hostname| specifies the hostname for which we need a channel ID.
95 std::string hostname_; 95 std::string hostname_;
96 96
97 scoped_ptr<ChannelIDSourceCallback> callback_; 97 scoped_ptr<ChannelIDSourceCallback> callback_;
98 98
99 scoped_ptr<ChannelIDKey> channel_id_key_; 99 scoped_ptr<ChannelIDKey> channel_id_key_;
100 100
101 State next_state_; 101 State next_state_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 callback->Run(&channel_id_key_); 171 callback->Run(&channel_id_key_);
172 // Will delete |this|. 172 // Will delete |this|.
173 channel_id_source_->OnJobComplete(this); 173 channel_id_source_->OnJobComplete(this);
174 } 174 }
175 } 175 }
176 176
177 int ChannelIDSourceChromium::Job::DoGetChannelIDKey(int result) { 177 int ChannelIDSourceChromium::Job::DoGetChannelIDKey(int result) {
178 next_state_ = STATE_GET_CHANNEL_ID_KEY_COMPLETE; 178 next_state_ = STATE_GET_CHANNEL_ID_KEY_COMPLETE;
179 179
180 return channel_id_service_->GetOrCreateChannelID( 180 return channel_id_service_->GetOrCreateChannelID(
181 hostname_, 181 hostname_, &channel_id_crypto_key_,
182 &channel_id_private_key_,
183 &channel_id_cert_,
184 base::Bind(&ChannelIDSourceChromium::Job::OnIOComplete, 182 base::Bind(&ChannelIDSourceChromium::Job::OnIOComplete,
185 base::Unretained(this)), 183 base::Unretained(this)),
186 &channel_id_request_handle_); 184 &channel_id_request_handle_);
187 } 185 }
188 186
189 int ChannelIDSourceChromium::Job::DoGetChannelIDKeyComplete(int result) { 187 int ChannelIDSourceChromium::Job::DoGetChannelIDKeyComplete(int result) {
190 DCHECK_EQ(STATE_NONE, next_state_); 188 DCHECK_EQ(STATE_NONE, next_state_);
191 if (result != OK) { 189 if (result != OK) {
192 DLOG(WARNING) << "Failed to look up channel ID: " << ErrorToString(result); 190 DLOG(WARNING) << "Failed to look up channel ID: " << ErrorToString(result);
193 return result; 191 return result;
194 } 192 }
195 193
196 std::vector<uint8> encrypted_private_key_info( 194 if (!channel_id_crypto_key_) {
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) {
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(
200 new ChannelIDKeyChromium(channel_id_crypto_key_.Pass()));
218 201
219 return result; 202 return result;
220 } 203 }
221 204
222 ChannelIDSourceChromium::ChannelIDSourceChromium( 205 ChannelIDSourceChromium::ChannelIDSourceChromium(
223 ChannelIDService* channel_id_service) 206 ChannelIDService* channel_id_service)
224 : channel_id_service_(channel_id_service) { 207 : channel_id_service_(channel_id_service) {
225 } 208 }
226 209
227 ChannelIDSourceChromium::~ChannelIDSourceChromium() { 210 ChannelIDSourceChromium::~ChannelIDSourceChromium() {
(...skipping 12 matching lines...) Expand all
240 } 223 }
241 return status; 224 return status;
242 } 225 }
243 226
244 void ChannelIDSourceChromium::OnJobComplete(Job* job) { 227 void ChannelIDSourceChromium::OnJobComplete(Job* job) {
245 active_jobs_.erase(job); 228 active_jobs_.erase(job);
246 delete job; 229 delete job;
247 } 230 }
248 231
249 } // namespace net 232 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/channel_id_chromium.h ('k') | net/quic/test_tools/crypto_test_utils_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698