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

Side by Side Diff: net/base/origin_bound_cert_service.cc

Issue 8296014: Use NSS to generate Origin-Bound Certs on Win and Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address other points of original review too Created 9 years, 2 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/base/origin_bound_cert_service.h" 5 #include "net/base/origin_bound_cert_service.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/rand_util.h" 15 #include "base/rand_util.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/threading/worker_pool.h" 17 #include "base/threading/worker_pool.h"
18 #include "crypto/rsa_private_key.h" 18 #include "crypto/rsa_private_key.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 #include "net/base/origin_bound_cert_store.h" 20 #include "net/base/origin_bound_cert_store.h"
21 #include "net/base/x509_certificate.h" 21 #include "net/base/x509_certificate.h"
22 #include "net/base/x509_util.h"
22 23
23 #if defined(USE_NSS) 24 #if defined(USE_NSS)
24 #include <private/pprthred.h> // PR_DetachThread 25 #include <private/pprthred.h> // PR_DetachThread
25 #endif 26 #endif
26 27
27 namespace net { 28 namespace net {
28 29
29 namespace { 30 namespace {
30 31
31 const int kKeySizeInBits = 1024; 32 const int kKeySizeInBits = 1024;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 int OriginBoundCertService::GenerateCert(const std::string& origin, 318 int OriginBoundCertService::GenerateCert(const std::string& origin,
318 uint32 serial_number, 319 uint32 serial_number,
319 std::string* private_key, 320 std::string* private_key,
320 std::string* cert) { 321 std::string* cert) {
321 scoped_ptr<crypto::RSAPrivateKey> key( 322 scoped_ptr<crypto::RSAPrivateKey> key(
322 crypto::RSAPrivateKey::Create(kKeySizeInBits)); 323 crypto::RSAPrivateKey::Create(kKeySizeInBits));
323 if (!key.get()) { 324 if (!key.get()) {
324 LOG(WARNING) << "Unable to create key pair for client"; 325 LOG(WARNING) << "Unable to create key pair for client";
325 return ERR_KEY_GENERATION_FAILED; 326 return ERR_KEY_GENERATION_FAILED;
326 } 327 }
327 #if defined(USE_NSS) 328 std::string der_cert;
328 scoped_refptr<X509Certificate> x509_cert = X509Certificate::CreateOriginBound( 329 if (!x509_util::CreateOriginBoundCert(
329 key.get(), 330 key.get(),
330 origin, 331 origin,
331 serial_number, 332 serial_number,
332 base::TimeDelta::FromDays(kValidityPeriodInDays)); 333 base::TimeDelta::FromDays(kValidityPeriodInDays),
333 #else 334 &der_cert)) {
334 scoped_refptr<X509Certificate> x509_cert = X509Certificate::CreateSelfSigned(
335 key.get(),
336 "CN=anonymous.invalid",
337 serial_number,
338 base::TimeDelta::FromDays(kValidityPeriodInDays));
339 #endif
340 if (!x509_cert) {
341 LOG(WARNING) << "Unable to create x509 cert for client"; 335 LOG(WARNING) << "Unable to create x509 cert for client";
342 return ERR_ORIGIN_BOUND_CERT_GENERATION_FAILED; 336 return ERR_ORIGIN_BOUND_CERT_GENERATION_FAILED;
343 } 337 }
344 338
345 std::vector<uint8> private_key_info; 339 std::vector<uint8> private_key_info;
346 if (!key->ExportPrivateKey(&private_key_info)) { 340 if (!key->ExportPrivateKey(&private_key_info)) {
347 LOG(WARNING) << "Unable to export private key"; 341 LOG(WARNING) << "Unable to export private key";
348 return ERR_PRIVATE_KEY_EXPORT_FAILED; 342 return ERR_PRIVATE_KEY_EXPORT_FAILED;
349 } 343 }
350 // TODO(rkn): Perhaps ExportPrivateKey should be changed to output a 344 // TODO(rkn): Perhaps ExportPrivateKey should be changed to output a
351 // std::string* to prevent this copying. 345 // std::string* to prevent this copying.
352 std::string key_out(private_key_info.begin(), private_key_info.end()); 346 std::string key_out(private_key_info.begin(), private_key_info.end());
353 347
354 std::string der_cert;
355 if (!x509_cert->GetDEREncoded(&der_cert)) {
356 LOG(WARNING) << "Unable to get DER-encoded cert";
357 return ERR_GET_CERT_BYTES_FAILED;
wtc 2011/10/17 19:09:27 I believe this is the only place where ERR_GET_CER
mattm 2011/10/17 22:54:19 Done.
358 }
359
360 private_key->swap(key_out); 348 private_key->swap(key_out);
361 cert->swap(der_cert); 349 cert->swap(der_cert);
362 return OK; 350 return OK;
363 } 351 }
364 352
365 void OriginBoundCertService::CancelRequest(RequestHandle req) { 353 void OriginBoundCertService::CancelRequest(RequestHandle req) {
366 DCHECK(CalledOnValidThread()); 354 DCHECK(CalledOnValidThread());
367 OriginBoundCertServiceRequest* request = 355 OriginBoundCertServiceRequest* request =
368 reinterpret_cast<OriginBoundCertServiceRequest*>(req); 356 reinterpret_cast<OriginBoundCertServiceRequest*>(req);
369 request->Cancel(); 357 request->Cancel();
(...skipping 22 matching lines...) Expand all
392 delete job; 380 delete job;
393 } 381 }
394 382
395 int OriginBoundCertService::cert_count() { 383 int OriginBoundCertService::cert_count() {
396 return origin_bound_cert_store_->GetCertCount(); 384 return origin_bound_cert_store_->GetCertCount();
397 } 385 }
398 386
399 } // namespace net 387 } // namespace net
400 388
401 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::OriginBoundCertServiceWorker); 389 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::OriginBoundCertServiceWorker);
OLDNEW
« no previous file with comments | « crypto/scoped_nss_types.h ('k') | net/base/x509_certificate.h » ('j') | net/base/x509_util.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698