OLD | NEW |
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/logging.h" | 10 #include "base/logging.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 job->AddRequest(request); | 309 job->AddRequest(request); |
310 *out_req = request; | 310 *out_req = request; |
311 return ERR_IO_PENDING; | 311 return ERR_IO_PENDING; |
312 } | 312 } |
313 | 313 |
314 // static | 314 // static |
315 int OriginBoundCertService::GenerateCert(const std::string& origin, | 315 int OriginBoundCertService::GenerateCert(const std::string& origin, |
316 uint32 serial_number, | 316 uint32 serial_number, |
317 std::string* private_key, | 317 std::string* private_key, |
318 std::string* cert) { | 318 std::string* cert) { |
| 319 std::string subject = "CN=OBC"; |
319 scoped_ptr<crypto::RSAPrivateKey> key( | 320 scoped_ptr<crypto::RSAPrivateKey> key( |
320 crypto::RSAPrivateKey::Create(kKeySizeInBits)); | 321 crypto::RSAPrivateKey::Create(kKeySizeInBits)); |
321 if (!key.get()) { | 322 if (!key.get()) { |
322 LOG(WARNING) << "Unable to create key pair for client"; | 323 LOG(WARNING) << "Unable to create key pair for client"; |
323 return ERR_KEY_GENERATION_FAILED; | 324 return ERR_KEY_GENERATION_FAILED; |
324 } | 325 } |
325 #if defined(USE_NSS) | 326 |
326 scoped_refptr<X509Certificate> x509_cert = X509Certificate::CreateOriginBound( | 327 scoped_refptr<X509Certificate> x509_cert = X509Certificate::CreateSelfSigned( |
327 key.get(), | 328 key.get(), |
328 origin, | 329 subject, |
329 serial_number, | 330 serial_number, |
330 base::TimeDelta::FromDays(kValidityPeriodInDays)); | 331 base::TimeDelta::FromDays(kValidityPeriodInDays)); |
331 #else | |
332 scoped_refptr<X509Certificate> x509_cert = X509Certificate::CreateSelfSigned( | |
333 key.get(), | |
334 "CN=anonymous.invalid", | |
335 serial_number, | |
336 base::TimeDelta::FromDays(kValidityPeriodInDays)); | |
337 #endif | |
338 if (!x509_cert) { | 332 if (!x509_cert) { |
339 LOG(WARNING) << "Unable to create x509 cert for client"; | 333 LOG(WARNING) << "Unable to create x509 cert for client"; |
340 return ERR_ORIGIN_BOUND_CERT_GENERATION_FAILED; | 334 return ERR_ORIGIN_BOUND_CERT_GENERATION_FAILED; |
341 } | 335 } |
342 | 336 |
343 std::vector<uint8> private_key_info; | 337 std::vector<uint8> private_key_info; |
344 if (!key->ExportPrivateKey(&private_key_info)) { | 338 if (!key->ExportPrivateKey(&private_key_info)) { |
345 LOG(WARNING) << "Unable to export private key"; | 339 LOG(WARNING) << "Unable to export private key"; |
346 return ERR_PRIVATE_KEY_EXPORT_FAILED; | 340 return ERR_PRIVATE_KEY_EXPORT_FAILED; |
347 } | 341 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 delete job; | 384 delete job; |
391 } | 385 } |
392 | 386 |
393 int OriginBoundCertService::cert_count() { | 387 int OriginBoundCertService::cert_count() { |
394 return origin_bound_cert_store_->GetCertCount(); | 388 return origin_bound_cert_store_->GetCertCount(); |
395 } | 389 } |
396 | 390 |
397 } // namespace net | 391 } // namespace net |
398 | 392 |
399 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::OriginBoundCertServiceWorker); | 393 DISABLE_RUNNABLE_METHOD_REFCOUNT(net::OriginBoundCertServiceWorker); |
OLD | NEW |