| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/media/webrtc_identity_store.h" | 5 #include "content/browser/media/webrtc_identity_store.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Generates a new identity using |common_name| which expires after | 34 // Generates a new identity using |common_name| which expires after |
| 35 // |validity_period| and returns the result in |result|. | 35 // |validity_period| and returns the result in |result|. |
| 36 static void GenerateIdentityWorker(const std::string& common_name, | 36 static void GenerateIdentityWorker(const std::string& common_name, |
| 37 base::TimeDelta validity_period, | 37 base::TimeDelta validity_period, |
| 38 WebRTCIdentityRequestResult* result) { | 38 WebRTCIdentityRequestResult* result) { |
| 39 result->error = net::OK; | 39 result->error = net::OK; |
| 40 int serial_number = base::RandInt(0, std::numeric_limits<int>::max()); | 40 int serial_number = base::RandInt(0, std::numeric_limits<int>::max()); |
| 41 | 41 |
| 42 scoped_ptr<crypto::RSAPrivateKey> key(crypto::RSAPrivateKey::Create(1024)); | 42 crypto::RSAPrivateKey* raw_key; |
| 43 if (!key.get()) { | 43 base::Time now = base::Time::Now(); |
| 44 DLOG(ERROR) << "Unable to create key pair for client"; | 44 bool success = net::x509_util::CreateKeyAndSelfSignedCert( |
| 45 result->error = net::ERR_KEY_GENERATION_FAILED; | 45 "CN=" + common_name, |
| 46 return; | 46 serial_number, |
| 47 } | 47 now, |
| 48 now + validity_period, |
| 49 &raw_key, |
| 50 &result->certificate); |
| 48 | 51 |
| 49 base::Time now = base::Time::Now(); | |
| 50 bool success = net::x509_util::CreateSelfSignedCert(key.get(), | |
| 51 "CN=" + common_name, | |
| 52 serial_number, | |
| 53 now, | |
| 54 now + validity_period, | |
| 55 &result->certificate); | |
| 56 if (!success) { | 52 if (!success) { |
| 57 DLOG(ERROR) << "Unable to create x509 cert for client"; | 53 DLOG(ERROR) << "Unable to create x509 cert for client"; |
| 58 result->error = net::ERR_SELF_SIGNED_CERT_GENERATION_FAILED; | 54 result->error = net::ERR_SELF_SIGNED_CERT_GENERATION_FAILED; |
| 59 return; | 55 return; |
| 60 } | 56 } |
| 61 | 57 |
| 58 scoped_ptr<crypto::RSAPrivateKey> key(raw_key); |
| 62 std::vector<uint8> private_key_info; | 59 std::vector<uint8> private_key_info; |
| 63 if (!key->ExportPrivateKey(&private_key_info)) { | 60 if (!key->ExportPrivateKey(&private_key_info)) { |
| 64 DLOG(ERROR) << "Unable to export private key"; | 61 DLOG(ERROR) << "Unable to export private key"; |
| 65 result->error = net::ERR_PRIVATE_KEY_EXPORT_FAILED; | 62 result->error = net::ERR_PRIVATE_KEY_EXPORT_FAILED; |
| 66 return; | 63 return; |
| 67 } | 64 } |
| 68 | 65 |
| 69 result->private_key = | 66 result->private_key = |
| 70 std::string(private_key_info.begin(), private_key_info.end()); | 67 std::string(private_key_info.begin(), private_key_info.end()); |
| 71 } | 68 } |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 if (in_flight_requests_[i]->origin_ == origin && | 307 if (in_flight_requests_[i]->origin_ == origin && |
| 311 in_flight_requests_[i]->identity_name_ == identity_name && | 308 in_flight_requests_[i]->identity_name_ == identity_name && |
| 312 in_flight_requests_[i]->common_name_ == common_name) { | 309 in_flight_requests_[i]->common_name_ == common_name) { |
| 313 return in_flight_requests_[i]; | 310 return in_flight_requests_[i]; |
| 314 } | 311 } |
| 315 } | 312 } |
| 316 return NULL; | 313 return NULL; |
| 317 } | 314 } |
| 318 | 315 |
| 319 } // namespace content | 316 } // namespace content |
| OLD | NEW |