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