OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/renderer/media/peer_connection_identity_store.h" | 5 #include "content/renderer/media/peer_connection_identity_store.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "content/renderer/media/webrtc_identity_service.h" | 11 #include "content/renderer/media/webrtc_identity_service.h" |
12 #include "content/renderer/render_thread_impl.h" | 12 #include "content/renderer/render_thread_impl.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 namespace { | 15 namespace { |
16 | 16 |
17 const char kIdentityName[] = "WebRTC"; | 17 const char kIdentityName[] = "WebRTC"; |
18 static unsigned int kRSAChromiumKeyLength = 1024; | 18 static unsigned int kRSAChromiumKeyLength = 1024; |
19 static unsigned int kRSAChromiumPubExp = 0x10001; | 19 static unsigned int kRSAChromiumPubExp = 0x10001; |
20 static uint64_t kYearInSeconds = 365 * 24 * 60 * 60; | |
20 | 21 |
21 // Bridges identity requests between the main render thread and libjingle's | 22 // Bridges identity requests between the main render thread and libjingle's |
22 // signaling thread. | 23 // signaling thread. |
23 class RequestHandler : public base::RefCountedThreadSafe<RequestHandler> { | 24 class RequestHandler : public base::RefCountedThreadSafe<RequestHandler> { |
24 public: | 25 public: |
25 explicit RequestHandler( | 26 explicit RequestHandler( |
26 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, | 27 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, |
27 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread, | 28 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread, |
28 webrtc::DtlsIdentityRequestObserver* observer) | 29 webrtc::DtlsIdentityRequestObserver* observer) |
29 : main_thread_(main_thread), | 30 : main_thread_(main_thread), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 DCHECK(main_thread_); | 110 DCHECK(main_thread_); |
110 DCHECK(signaling_thread_); | 111 DCHECK(signaling_thread_); |
111 } | 112 } |
112 | 113 |
113 PeerConnectionIdentityStore::~PeerConnectionIdentityStore() { | 114 PeerConnectionIdentityStore::~PeerConnectionIdentityStore() { |
114 // Typically destructed on libjingle's signaling thread. | 115 // Typically destructed on libjingle's signaling thread. |
115 } | 116 } |
116 | 117 |
117 void PeerConnectionIdentityStore::RequestIdentity( | 118 void PeerConnectionIdentityStore::RequestIdentity( |
118 rtc::KeyParams key_params, | 119 rtc::KeyParams key_params, |
120 rtc::Optional<uint64_t> expires_ms, | |
tommi (sloooow) - chröme
2016/03/04 09:55:40
Is there a reason why the arguments need to be pas
hbos_chromium
2016/03/04 12:24:11
No, will update webrtc interface to use const&, ro
| |
119 const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& observer) { | 121 const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& observer) { |
120 DCHECK(signaling_thread_->BelongsToCurrentThread()); | 122 DCHECK(signaling_thread_->BelongsToCurrentThread()); |
121 DCHECK(observer); | 123 DCHECK(observer); |
122 | 124 |
123 // TODO(torbjorng): crbug.com/544902. RequestIdentityOnUIThread uses Chromium | 125 // TODO(torbjorng): crbug.com/544902. RequestIdentityOnUIThread uses Chromium |
124 // key generation code with the assumption that it will generate with the | 126 // key generation code with the assumption that it will generate with the |
125 // following rsa_params(). This assumption should not be implicit! Either pass | 127 // following rsa_params(). This assumption should not be implicit! Either pass |
126 // the parameters along or check against constants exported from relevant | 128 // the parameters along or check against constants exported from relevant |
127 // header file(s). | 129 // header file(s). |
128 if (key_params.type() == rtc::KT_RSA && | 130 if (key_params.type() == rtc::KT_RSA && |
129 key_params.rsa_params().mod_size == kRSAChromiumKeyLength && | 131 key_params.rsa_params().mod_size == kRSAChromiumKeyLength && |
130 key_params.rsa_params().pub_exp == kRSAChromiumPubExp) { | 132 key_params.rsa_params().pub_exp == kRSAChromiumPubExp && |
133 !expires_ms) { | |
131 // Use Chromium identity generation code for its hardwired parameters (RSA, | 134 // Use Chromium identity generation code for its hardwired parameters (RSA, |
132 // 1024, 0x10001). This generation code is preferred over WebRTC generation | 135 // 1024, 0x10001). This generation code is preferred over WebRTC generation |
133 // code due to the performance benefits of caching. | 136 // code due to the performance benefits of caching. |
134 scoped_refptr<RequestHandler> handler( | 137 scoped_refptr<RequestHandler> handler( |
135 new RequestHandler(main_thread_, signaling_thread_, observer)); | 138 new RequestHandler(main_thread_, signaling_thread_, observer)); |
136 main_thread_->PostTask( | 139 main_thread_->PostTask( |
137 FROM_HERE, | 140 FROM_HERE, |
138 base::Bind(&RequestHandler::RequestIdentityOnMainThread, handler, url_, | 141 base::Bind(&RequestHandler::RequestIdentityOnMainThread, handler, url_, |
139 first_party_for_cookies_)); | 142 first_party_for_cookies_)); |
140 } else { | 143 } else { |
141 // Fall back on WebRTC identity generation code for everything else, e.g. | 144 // Fall back on WebRTC identity generation code for everything else, e.g. |
142 // RSA with any other parameters or ECDSA. These will not be cached. | 145 // RSA with any other parameters or ECDSA. These will not be cached. |
143 scoped_ptr<rtc::SSLIdentity> identity(rtc::SSLIdentity::Generate( | 146 scoped_ptr<rtc::SSLIdentity> identity; |
144 kIdentityName, key_params)); | 147 if (!expires_ms) { |
148 identity.reset(rtc::SSLIdentity::Generate(kIdentityName, key_params)); | |
149 } else { | |
150 uint64_t expires_s = *expires_ms / 1000; | |
151 // Limit the expiration time to something reasonable (a year). This also | |
152 // ensures that the value is not too large for time_t. | |
hbos_chromium
2016/03/04 09:26:31
Spec: "a user agent may choose to limit the period
tommi (sloooow) - chröme
2016/03/04 09:55:40
Was there a discussion on what is reasonable or is
hbos_chromium
2016/03/04 12:24:11
Rather arbitrarily, could have chosen something el
| |
153 if (expires_s > kYearInSeconds) | |
154 expires_s = kYearInSeconds; | |
155 identity.reset(rtc::SSLIdentity::Generate( | |
156 kIdentityName, key_params, static_cast<time_t>(expires_s))); | |
157 } | |
145 | 158 |
146 // Invoke |observer| callbacks asynchronously. The callbacks of | 159 // Invoke |observer| callbacks asynchronously. The callbacks of |
147 // DtlsIdentityStoreInterface implementations have to be async. | 160 // DtlsIdentityStoreInterface implementations have to be async. |
148 if (identity) { | 161 if (identity) { |
149 // Async call to |observer|->OnSuccess. | 162 // Async call to |observer|->OnSuccess. |
150 // Helper function necessary because OnSuccess takes an rtc::scoped_ptr | 163 // Helper function necessary because OnSuccess takes an rtc::scoped_ptr |
151 // argument which has to be Pass()-ed. base::Passed gets around this for | 164 // argument which has to be Pass()-ed. base::Passed gets around this for |
152 // scoped_ptr (without rtc namespace), but not for rtc::scoped_ptr. | 165 // scoped_ptr (without rtc namespace), but not for rtc::scoped_ptr. |
153 signaling_thread_->PostTask(FROM_HERE, | 166 signaling_thread_->PostTask(FROM_HERE, |
154 base::Bind(&ObserverOnSuccess, observer, base::Passed(&identity))); | 167 base::Bind(&ObserverOnSuccess, observer, base::Passed(&identity))); |
155 } else { | 168 } else { |
156 // Async call to |observer|->OnFailure. | 169 // Async call to |observer|->OnFailure. |
157 signaling_thread_->PostTask(FROM_HERE, | 170 signaling_thread_->PostTask(FROM_HERE, |
158 base::Bind(&webrtc::DtlsIdentityRequestObserver::OnFailure, | 171 base::Bind(&webrtc::DtlsIdentityRequestObserver::OnFailure, |
159 observer, 0)); | 172 observer, 0)); |
160 } | 173 } |
161 } | 174 } |
162 } | 175 } |
163 | 176 |
164 } // namespace content | 177 } // namespace content |
OLD | NEW |