Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/media/rtc_certificate_generator.h" | |
| 6 | |
| 7 #include "content/renderer/media/peer_connection_identity_store.h" | |
| 8 #include "content/renderer/media/rtc_certificate.h" | |
| 9 #include "third_party/webrtc/base/rtccertificate.h" | |
| 10 #include "third_party/webrtc/base/scoped_ref_ptr.h" | |
| 11 #include "url/gurl.h" | |
| 12 | |
| 13 namespace content { | |
| 14 namespace { | |
| 15 | |
| 16 class RTCCertificateIdentityObserver | |
| 17 : public webrtc::DtlsIdentityRequestObserver { | |
| 18 public: | |
| 19 RTCCertificateIdentityObserver( | |
| 20 const blink::WebRTCKeyParams& key_params, | |
| 21 webrtc::DtlsIdentityStoreInterface* store, | |
| 22 blink::WebCallbacks<blink::WebRTCCertificate*, void>* observer) | |
| 23 : key_params_(key_params), store_(store), observer_(observer) { | |
| 24 } | |
| 25 | |
| 26 ~RTCCertificateIdentityObserver() override { | |
| 27 } | |
| 28 | |
| 29 void Init(const rtc::scoped_refptr<RTCCertificateIdentityObserver>& self) { | |
| 30 this_ = self; | |
|
Guido Urdaneta
2015/10/08 11:13:03
Would it be much more complex to handle ownership
hbos_chromium
2015/10/14 13:00:49
I have to protect it with reference counting becau
| |
| 31 } | |
| 32 | |
| 33 private: | |
| 34 void OnFailure(int error) override { | |
| 35 DCHECK(this_) << "Not initialized."; | |
| 36 observer_->onError(); | |
| 37 // Stop protecting against destruction. This could result in "delete this". | |
| 38 this_ = nullptr; | |
| 39 } | |
| 40 | |
| 41 void OnSuccess(const std::string& der_cert, | |
| 42 const std::string& der_private_key) override { | |
| 43 DCHECK(this_) << "Not initialized."; | |
| 44 std::string pem_cert = rtc::SSLIdentity::DerToPem( | |
| 45 rtc::kPemTypeCertificate, | |
| 46 reinterpret_cast<const unsigned char*>(der_cert.data()), | |
| 47 der_cert.length()); | |
| 48 std::string pem_key = rtc::SSLIdentity::DerToPem( | |
| 49 rtc::kPemTypeRsaPrivateKey, | |
| 50 reinterpret_cast<const unsigned char*>(der_private_key.data()), | |
| 51 der_private_key.length()); | |
|
Ryan Sleevi
2015/10/10 04:04:48
This seems quite inefficient to be converting; why
torbjorng
2015/10/14 13:02:48
We don't currently provide any DER format conversi
| |
| 52 rtc::scoped_ptr<rtc::SSLIdentity> identity( | |
| 53 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert)); | |
| 54 OnSuccess(identity.Pass()); | |
| 55 } | |
| 56 | |
| 57 void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override { | |
| 58 DCHECK(this_) << "Not initialized."; | |
| 59 rtc::scoped_refptr<rtc::RTCCertificate> certificate = | |
| 60 rtc::RTCCertificate::Create(identity.Pass()); | |
| 61 observer_->onSuccess(new RTCCertificate(key_params_, certificate)); | |
| 62 // Stop protecting against destruction. This could result in "delete this". | |
| 63 this_ = nullptr; | |
| 64 } | |
| 65 | |
| 66 rtc::scoped_refptr<RTCCertificateIdentityObserver> this_; | |
| 67 blink::WebRTCKeyParams key_params_; | |
| 68 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> store_; | |
| 69 blink::WebCallbacks<blink::WebRTCCertificate*, void>* observer_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(RTCCertificateIdentityObserver); | |
| 72 }; | |
| 73 | |
| 74 } // namespace | |
| 75 | |
| 76 void RTCCertificateGenerator::generateCertificate( | |
| 77 const blink::WebRTCKeyParams& key_params, | |
| 78 const blink::WebURL& url, | |
| 79 const blink::WebURL& first_party_for_cookies, | |
| 80 blink::WebCallbacks<blink::WebRTCCertificate*, void>* observer) { | |
| 81 // TODO(hbos): Convert blink::WebRTCKeyParams -> rtc::KeyParams and use that | |
| 82 // in RequestIdentity when rtc::KeyParams CL has landed. | |
|
Guido Urdaneta
2015/10/08 11:13:03
Reference a crbug
hbos_chromium
2015/10/14 13:00:49
Bug resolved.
| |
| 83 rtc::KeyType rtc_key_type = rtc::IntKeyTypeFamilyToKeyType( | |
| 84 static_cast<int>(key_params.keyType())); | |
| 85 | |
| 86 PeerConnectionIdentityStore* store = | |
| 87 new PeerConnectionIdentityStore(url, first_party_for_cookies); | |
|
Ryan Sleevi
2015/10/10 04:04:48
BUG? How does this not leak store?
hbos_chromium
2015/10/14 13:00:49
The ownership of |store| was passed to |identity_o
| |
| 88 | |
| 89 rtc::scoped_refptr<RTCCertificateIdentityObserver> identity_observer( | |
| 90 new rtc::RefCountedObject<RTCCertificateIdentityObserver>( | |
| 91 key_params, store, observer)); | |
| 92 identity_observer->Init(identity_observer); | |
| 93 store->RequestIdentity(rtc_key_type, identity_observer); | |
| 94 } | |
| 95 | |
| 96 bool RTCCertificateGenerator::isValidKeyParams( | |
| 97 const blink::WebRTCKeyParams& key_params) { | |
| 98 // TODO(hbos): Convert to rtc::KeyParams and check KeyParams::IsValid instead | |
| 99 // of having parameter validation code in multiple places. | |
|
Guido Urdaneta
2015/10/08 11:13:03
Reference a crbug
hbos_chromium
2015/10/14 13:00:49
Bug resolved.
| |
| 100 if (key_params.keyType() == blink::WebRTCKeyTypeRSA) { | |
| 101 // Smaller |modLength| insecure, greater |modLength| slow and redundant. | |
| 102 // 65537 is the only supported |pubExp|. | |
| 103 return key_params.rsaParams().modLength >= 1024 && | |
| 104 key_params.rsaParams().modLength <= 8192 && | |
| 105 key_params.rsaParams().pubExp == 65537; | |
| 106 } | |
| 107 if (key_params.keyType() == blink::WebRTCKeyTypeECDSA) { | |
| 108 return key_params.ecCurve() == blink::WebRTCECCurveNistP256; | |
| 109 } | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 113 } // namespace content | |
| OLD | NEW |