| OLD | NEW |
| 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 |
| 11 #ifndef WEBRTC_API_DTLSIDENTITYSTORE_H_ | 11 #ifndef WEBRTC_API_DTLSIDENTITYSTORE_H_ |
| 12 #define WEBRTC_API_DTLSIDENTITYSTORE_H_ | 12 #define WEBRTC_API_DTLSIDENTITYSTORE_H_ |
| 13 | 13 |
| 14 #include <memory> |
| 14 #include <queue> | 15 #include <queue> |
| 15 #include <string> | 16 #include <string> |
| 16 #include <utility> | 17 #include <utility> |
| 17 | 18 |
| 18 #include "webrtc/base/messagehandler.h" | 19 #include "webrtc/base/messagehandler.h" |
| 19 #include "webrtc/base/messagequeue.h" | 20 #include "webrtc/base/messagequeue.h" |
| 20 #include "webrtc/base/optional.h" | 21 #include "webrtc/base/optional.h" |
| 21 #include "webrtc/base/refcount.h" | 22 #include "webrtc/base/refcount.h" |
| 22 #include "webrtc/base/scoped_ptr.h" | |
| 23 #include "webrtc/base/scoped_ref_ptr.h" | 23 #include "webrtc/base/scoped_ref_ptr.h" |
| 24 #include "webrtc/base/sslidentity.h" | 24 #include "webrtc/base/sslidentity.h" |
| 25 #include "webrtc/base/thread.h" | 25 #include "webrtc/base/thread.h" |
| 26 | 26 |
| 27 namespace webrtc { | 27 namespace webrtc { |
| 28 | 28 |
| 29 // Passed to SSLIdentity::Generate. | 29 // Passed to SSLIdentity::Generate. |
| 30 extern const char kIdentityName[]; | 30 extern const char kIdentityName[]; |
| 31 | 31 |
| 32 class SSLIdentity; | 32 class SSLIdentity; |
| 33 class Thread; | 33 class Thread; |
| 34 | 34 |
| 35 // Used to receive callbacks of DTLS identity requests. | 35 // Used to receive callbacks of DTLS identity requests. |
| 36 class DtlsIdentityRequestObserver : public rtc::RefCountInterface { | 36 class DtlsIdentityRequestObserver : public rtc::RefCountInterface { |
| 37 public: | 37 public: |
| 38 virtual void OnFailure(int error) = 0; | 38 virtual void OnFailure(int error) = 0; |
| 39 // TODO(hbos): Unify the OnSuccess method once Chrome code is updated. | 39 // TODO(hbos): Unify the OnSuccess method once Chrome code is updated. |
| 40 virtual void OnSuccess(const std::string& der_cert, | 40 virtual void OnSuccess(const std::string& der_cert, |
| 41 const std::string& der_private_key) = 0; | 41 const std::string& der_private_key) = 0; |
| 42 // |identity| is a scoped_ptr because rtc::SSLIdentity is not copyable and the | 42 // |identity| is a unique_ptr because rtc::SSLIdentity is not copyable and the |
| 43 // client has to get the ownership of the object to make use of it. | 43 // client has to get the ownership of the object to make use of it. |
| 44 virtual void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) = 0; | 44 virtual void OnSuccess(std::unique_ptr<rtc::SSLIdentity> identity) = 0; |
| 45 | 45 |
| 46 protected: | 46 protected: |
| 47 virtual ~DtlsIdentityRequestObserver() {} | 47 virtual ~DtlsIdentityRequestObserver() {} |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 // This interface defines an in-memory DTLS identity store, which generates DTLS | 50 // This interface defines an in-memory DTLS identity store, which generates DTLS |
| 51 // identities. | 51 // identities. |
| 52 // APIs calls must be made on the signaling thread and the callbacks are also | 52 // APIs calls must be made on the signaling thread and the callbacks are also |
| 53 // called on the signaling thread. | 53 // called on the signaling thread. |
| 54 class DtlsIdentityStoreInterface { | 54 class DtlsIdentityStoreInterface { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void OnMessage(rtc::Message* msg) override; | 99 void OnMessage(rtc::Message* msg) override; |
| 100 | 100 |
| 101 // Returns true if there is a free RSA identity, used for unit tests. | 101 // Returns true if there is a free RSA identity, used for unit tests. |
| 102 bool HasFreeIdentityForTesting(rtc::KeyType key_type) const; | 102 bool HasFreeIdentityForTesting(rtc::KeyType key_type) const; |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 void GenerateIdentity( | 105 void GenerateIdentity( |
| 106 rtc::KeyType key_type, | 106 rtc::KeyType key_type, |
| 107 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer); | 107 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer); |
| 108 void OnIdentityGenerated(rtc::KeyType key_type, | 108 void OnIdentityGenerated(rtc::KeyType key_type, |
| 109 rtc::scoped_ptr<rtc::SSLIdentity> identity); | 109 std::unique_ptr<rtc::SSLIdentity> identity); |
| 110 | 110 |
| 111 class WorkerTask; | 111 class WorkerTask; |
| 112 typedef rtc::ScopedMessageData<DtlsIdentityStoreImpl::WorkerTask> | 112 typedef rtc::ScopedMessageData<DtlsIdentityStoreImpl::WorkerTask> |
| 113 WorkerTaskMessageData; | 113 WorkerTaskMessageData; |
| 114 | 114 |
| 115 // A key type-identity pair. | 115 // A key type-identity pair. |
| 116 struct IdentityResult { | 116 struct IdentityResult { |
| 117 IdentityResult(rtc::KeyType key_type, | 117 IdentityResult(rtc::KeyType key_type, |
| 118 rtc::scoped_ptr<rtc::SSLIdentity> identity) | 118 std::unique_ptr<rtc::SSLIdentity> identity) |
| 119 : key_type_(key_type), identity_(std::move(identity)) {} | 119 : key_type_(key_type), identity_(std::move(identity)) {} |
| 120 | 120 |
| 121 rtc::KeyType key_type_; | 121 rtc::KeyType key_type_; |
| 122 rtc::scoped_ptr<rtc::SSLIdentity> identity_; | 122 std::unique_ptr<rtc::SSLIdentity> identity_; |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 typedef rtc::ScopedMessageData<IdentityResult> IdentityResultMessageData; | 125 typedef rtc::ScopedMessageData<IdentityResult> IdentityResultMessageData; |
| 126 | 126 |
| 127 sigslot::signal0<> SignalDestroyed; | 127 sigslot::signal0<> SignalDestroyed; |
| 128 | 128 |
| 129 rtc::Thread* const signaling_thread_; | 129 rtc::Thread* const signaling_thread_; |
| 130 // TODO(hbos): RSA generation is slow and would be VERY slow if we switch over | 130 // TODO(hbos): RSA generation is slow and would be VERY slow if we switch over |
| 131 // to 2048, DtlsIdentityStore should use a new thread and not the "general | 131 // to 2048, DtlsIdentityStore should use a new thread and not the "general |
| 132 // purpose" worker thread. | 132 // purpose" worker thread. |
| 133 rtc::Thread* const worker_thread_; | 133 rtc::Thread* const worker_thread_; |
| 134 | 134 |
| 135 struct RequestInfo { | 135 struct RequestInfo { |
| 136 RequestInfo() | 136 RequestInfo() |
| 137 : request_observers_(), gen_in_progress_counts_(0), free_identity_() {} | 137 : request_observers_(), gen_in_progress_counts_(0), free_identity_() {} |
| 138 | 138 |
| 139 std::queue<rtc::scoped_refptr<DtlsIdentityRequestObserver>> | 139 std::queue<rtc::scoped_refptr<DtlsIdentityRequestObserver>> |
| 140 request_observers_; | 140 request_observers_; |
| 141 size_t gen_in_progress_counts_; | 141 size_t gen_in_progress_counts_; |
| 142 rtc::scoped_ptr<rtc::SSLIdentity> free_identity_; | 142 std::unique_ptr<rtc::SSLIdentity> free_identity_; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 // One RequestInfo per KeyType. Only touch on the |signaling_thread_|. | 145 // One RequestInfo per KeyType. Only touch on the |signaling_thread_|. |
| 146 RequestInfo request_info_[rtc::KT_LAST]; | 146 RequestInfo request_info_[rtc::KT_LAST]; |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // namespace webrtc | 149 } // namespace webrtc |
| 150 | 150 |
| 151 #endif // WEBRTC_API_DTLSIDENTITYSTORE_H_ | 151 #endif // WEBRTC_API_DTLSIDENTITYSTORE_H_ |
| OLD | NEW |