Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: webrtc/api/dtlsidentitystore.cc

Issue 2001103002: RTCCertificateGeneratorInterface and RTCCertificateGeneratorStoreWrapper added. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed nits Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/dtlsidentitystore.h ('k') | webrtc/base/rtccertificategenerator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 13 matching lines...) Expand all
24 const char kIdentityName[] = "WebRTC"; 24 const char kIdentityName[] = "WebRTC";
25 25
26 namespace { 26 namespace {
27 27
28 enum { 28 enum {
29 MSG_DESTROY, 29 MSG_DESTROY,
30 MSG_GENERATE_IDENTITY, 30 MSG_GENERATE_IDENTITY,
31 MSG_GENERATE_IDENTITY_RESULT 31 MSG_GENERATE_IDENTITY_RESULT
32 }; 32 };
33 33
34 // A |DtlsIdentityRequestObserver| that informs an
35 // |RTCCertificateGeneratorCallback| of the result of an identity request. On
36 // success, a certificate is created using the identity before passing it to
37 // the callback.
38 class RTCCertificateStoreCallbackObserver
39 : public webrtc::DtlsIdentityRequestObserver {
40 public:
41 RTCCertificateStoreCallbackObserver(
42 const rtc::scoped_refptr<rtc::RTCCertificateGeneratorCallback>& callback)
43 : callback_(callback) {}
44
45 private:
46 void OnFailure(int error) override {
47 LOG(LS_WARNING) << "DtlsIdentityRequestObserver failure code: " << error;
48 Callback(nullptr);
49 }
50 void OnSuccess(const std::string& der_cert,
51 const std::string& der_private_key) override {
52 std::string pem_cert = rtc::SSLIdentity::DerToPem(
53 rtc::kPemTypeCertificate,
54 reinterpret_cast<const unsigned char*>(der_cert.data()),
55 der_cert.length());
56 std::string pem_key = rtc::SSLIdentity::DerToPem(
57 rtc::kPemTypeRsaPrivateKey,
58 reinterpret_cast<const unsigned char*>(der_private_key.data()),
59 der_private_key.length());
60 std::unique_ptr<rtc::SSLIdentity> identity(
61 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert));
62 OnSuccess(std::move(identity));
63 }
64 void OnSuccess(std::unique_ptr<rtc::SSLIdentity> identity) override {
65 Callback(rtc::RTCCertificate::Create(std::move(identity)));
66 }
67
68 void Callback(rtc::scoped_refptr<rtc::RTCCertificate> certificate) {
69 if (certificate)
70 callback_->OnSuccess(certificate);
71 else
72 callback_->OnFailure();
73 }
74
75 rtc::scoped_refptr<rtc::RTCCertificateGeneratorCallback> callback_;
76 };
77
34 } // namespace 78 } // namespace
35 79
36 // This class runs on the worker thread to generate the identity. It's necessary 80 // This class runs on the worker thread to generate the identity. It's necessary
37 // to separate this class from DtlsIdentityStore so that it can live on the 81 // to separate this class from DtlsIdentityStore so that it can live on the
38 // worker thread after DtlsIdentityStore is destroyed. 82 // worker thread after DtlsIdentityStore is destroyed.
39 class DtlsIdentityStoreImpl::WorkerTask : public sigslot::has_slots<>, 83 class DtlsIdentityStoreImpl::WorkerTask : public sigslot::has_slots<>,
40 public rtc::MessageHandler { 84 public rtc::MessageHandler {
41 public: 85 public:
42 WorkerTask(DtlsIdentityStoreImpl* store, rtc::KeyType key_type) 86 WorkerTask(DtlsIdentityStoreImpl* store, rtc::KeyType key_type)
43 : signaling_thread_(rtc::Thread::Current()), 87 : signaling_thread_(rtc::Thread::Current()),
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 185 }
142 186
143 bool DtlsIdentityStoreImpl::HasFreeIdentityForTesting( 187 bool DtlsIdentityStoreImpl::HasFreeIdentityForTesting(
144 rtc::KeyType key_type) const { 188 rtc::KeyType key_type) const {
145 RTC_DCHECK(signaling_thread_->IsCurrent()); 189 RTC_DCHECK(signaling_thread_->IsCurrent());
146 return request_info_[key_type].free_identity_.get() != nullptr; 190 return request_info_[key_type].free_identity_.get() != nullptr;
147 } 191 }
148 192
149 void DtlsIdentityStoreImpl::GenerateIdentity( 193 void DtlsIdentityStoreImpl::GenerateIdentity(
150 rtc::KeyType key_type, 194 rtc::KeyType key_type,
151 const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& observer) { 195 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) {
152 RTC_DCHECK(signaling_thread_->IsCurrent()); 196 RTC_DCHECK(signaling_thread_->IsCurrent());
153 197
154 // Enqueue observer to be informed when generation of |key_type| is completed. 198 // Enqueue observer to be informed when generation of |key_type| is completed.
155 if (observer.get()) { 199 if (observer.get()) {
156 request_info_[key_type].request_observers_.push(observer); 200 request_info_[key_type].request_observers_.push(observer);
157 201
158 // Already have a free identity generated? 202 // Already have a free identity generated?
159 if (request_info_[key_type].free_identity_.get()) { 203 if (request_info_[key_type].free_identity_.get()) {
160 // Return identity async - post even though we are on |signaling_thread_|. 204 // Return identity async - post even though we are on |signaling_thread_|.
161 LOG(LS_VERBOSE) << "Using a free DTLS identity."; 205 LOG(LS_VERBOSE) << "Using a free DTLS identity.";
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 if (worker_thread_ != signaling_thread_ && // Only do in background thread. 265 if (worker_thread_ != signaling_thread_ && // Only do in background thread.
222 key_type == rtc::KT_RSA && // Only necessary for RSA. 266 key_type == rtc::KT_RSA && // Only necessary for RSA.
223 !request_info_[key_type].free_identity_.get() && 267 !request_info_[key_type].free_identity_.get() &&
224 request_info_[key_type].request_observers_.size() == 268 request_info_[key_type].request_observers_.size() ==
225 request_info_[key_type].gen_in_progress_counts_) { 269 request_info_[key_type].gen_in_progress_counts_) {
226 GenerateIdentity(key_type, nullptr); 270 GenerateIdentity(key_type, nullptr);
227 } 271 }
228 } 272 }
229 } 273 }
230 274
275 RTCCertificateGeneratorStoreWrapper::RTCCertificateGeneratorStoreWrapper(
276 std::unique_ptr<DtlsIdentityStoreInterface> store)
277 : store_(std::move(store)) {
278 RTC_DCHECK(store_);
279 }
280
281 void RTCCertificateGeneratorStoreWrapper::GenerateCertificateAsync(
282 const rtc::KeyParams& key_params,
283 const rtc::Optional<uint64_t>& expires_ms,
284 const rtc::scoped_refptr<rtc::RTCCertificateGeneratorCallback>& callback) {
285 store_->RequestIdentity(
286 key_params,
287 expires_ms,
288 new rtc::RefCountedObject<RTCCertificateStoreCallbackObserver>(callback));
289 }
290
231 } // namespace webrtc 291 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/dtlsidentitystore.h ('k') | webrtc/base/rtccertificategenerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698