| 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 <queue> | 14 #include <queue> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <utility> | 16 #include <utility> |
| 17 | 17 |
| 18 #include "webrtc/base/messagehandler.h" | 18 #include "webrtc/base/messagehandler.h" |
| 19 #include "webrtc/base/messagequeue.h" | 19 #include "webrtc/base/messagequeue.h" |
| 20 #include "webrtc/base/optional.h" |
| 20 #include "webrtc/base/refcount.h" | 21 #include "webrtc/base/refcount.h" |
| 21 #include "webrtc/base/scoped_ptr.h" | 22 #include "webrtc/base/scoped_ptr.h" |
| 22 #include "webrtc/base/scoped_ref_ptr.h" | 23 #include "webrtc/base/scoped_ref_ptr.h" |
| 23 #include "webrtc/base/sslidentity.h" | 24 #include "webrtc/base/sslidentity.h" |
| 24 #include "webrtc/base/thread.h" | 25 #include "webrtc/base/thread.h" |
| 25 | 26 |
| 26 namespace webrtc { | 27 namespace webrtc { |
| 27 | 28 |
| 28 // Passed to SSLIdentity::Generate. | 29 // Passed to SSLIdentity::Generate. |
| 29 extern const char kIdentityName[]; | 30 extern const char kIdentityName[]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 // 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 |
| 50 // identities. | 51 // identities. |
| 51 // 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 |
| 52 // called on the signaling thread. | 53 // called on the signaling thread. |
| 53 class DtlsIdentityStoreInterface { | 54 class DtlsIdentityStoreInterface { |
| 54 public: | 55 public: |
| 55 virtual ~DtlsIdentityStoreInterface() { } | 56 virtual ~DtlsIdentityStoreInterface() { } |
| 56 | 57 |
| 57 // The |observer| will be called when the requested identity is ready, or when | 58 // The |observer| will be called when the requested identity is ready, or when |
| 58 // identity generation fails. | 59 // identity generation fails. |
| 59 // TODO(torbjorng,hbos): The following RequestIdentity is about to be removed, | 60 // TODO(torbjorng,hbos): There are currently two versions of RequestIdentity, |
| 60 // see below todo. | 61 // with default implementation to call the other version of itself (so that a |
| 61 virtual void RequestIdentity( | 62 // call can be made regardless of which version has been overridden). The 1st |
| 62 rtc::KeyType key_type, | 63 // version exists because it is currently implemented in chromium. The 2nd |
| 63 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) { | 64 // version will become the one and only RequestIdentity as soon as chromium |
| 64 // Add default parameterization. | 65 // implements the correct version. crbug.com/544902, webrtc:5092. |
| 65 RequestIdentity(rtc::KeyParams(key_type), observer); | |
| 66 } | |
| 67 // TODO(torbjorng,hbos): Parameterized key types! The following | |
| 68 // RequestIdentity should replace the old one that takes rtc::KeyType. When | |
| 69 // the new one is implemented by Chromium and WebRTC the old one should be | |
| 70 // removed. crbug.com/544902, webrtc:5092. | |
| 71 virtual void RequestIdentity( | 66 virtual void RequestIdentity( |
| 72 rtc::KeyParams key_params, | 67 rtc::KeyParams key_params, |
| 73 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) { | 68 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) { |
| 74 // Drop parameterization. | 69 // Add default ("null") expiration. |
| 75 RequestIdentity(key_params.type(), observer); | 70 RequestIdentity(key_params, rtc::Optional<uint64_t>(), observer); |
| 71 } |
| 72 virtual void RequestIdentity( |
| 73 rtc::KeyParams key_params, |
| 74 rtc::Optional<uint64_t> expires, |
| 75 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) { |
| 76 // Drop |expires|. |
| 77 RequestIdentity(key_params, observer); |
| 76 } | 78 } |
| 77 }; | 79 }; |
| 78 | 80 |
| 79 // The WebRTC default implementation of DtlsIdentityStoreInterface. | 81 // The WebRTC default implementation of DtlsIdentityStoreInterface. |
| 80 // Identity generation is performed on the worker thread. | 82 // Identity generation is performed on the worker thread. |
| 81 class DtlsIdentityStoreImpl : public DtlsIdentityStoreInterface, | 83 class DtlsIdentityStoreImpl : public DtlsIdentityStoreInterface, |
| 82 public rtc::MessageHandler { | 84 public rtc::MessageHandler { |
| 83 public: | 85 public: |
| 84 // This will start to preemptively generating an RSA identity in the | 86 // This will start to preemptively generating an RSA identity in the |
| 85 // background if the worker thread is not the same as the signaling thread. | 87 // background if the worker thread is not the same as the signaling thread. |
| 86 DtlsIdentityStoreImpl(rtc::Thread* signaling_thread, | 88 DtlsIdentityStoreImpl(rtc::Thread* signaling_thread, |
| 87 rtc::Thread* worker_thread); | 89 rtc::Thread* worker_thread); |
| 88 ~DtlsIdentityStoreImpl() override; | 90 ~DtlsIdentityStoreImpl() override; |
| 89 | 91 |
| 90 // DtlsIdentityStoreInterface override; | 92 // DtlsIdentityStoreInterface override; |
| 91 void RequestIdentity( | 93 void RequestIdentity( |
| 92 rtc::KeyType key_type, | 94 rtc::KeyParams key_params, |
| 95 rtc::Optional<uint64_t> expires, |
| 93 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) override; | 96 const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) override; |
| 94 | 97 |
| 95 // rtc::MessageHandler override; | 98 // rtc::MessageHandler override; |
| 96 void OnMessage(rtc::Message* msg) override; | 99 void OnMessage(rtc::Message* msg) override; |
| 97 | 100 |
| 98 // 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. |
| 99 bool HasFreeIdentityForTesting(rtc::KeyType key_type) const; | 102 bool HasFreeIdentityForTesting(rtc::KeyType key_type) const; |
| 100 | 103 |
| 101 private: | 104 private: |
| 102 void GenerateIdentity( | 105 void GenerateIdentity( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 rtc::scoped_ptr<rtc::SSLIdentity> free_identity_; | 142 rtc::scoped_ptr<rtc::SSLIdentity> free_identity_; |
| 140 }; | 143 }; |
| 141 | 144 |
| 142 // One RequestInfo per KeyType. Only touch on the |signaling_thread_|. | 145 // One RequestInfo per KeyType. Only touch on the |signaling_thread_|. |
| 143 RequestInfo request_info_[rtc::KT_LAST]; | 146 RequestInfo request_info_[rtc::KT_LAST]; |
| 144 }; | 147 }; |
| 145 | 148 |
| 146 } // namespace webrtc | 149 } // namespace webrtc |
| 147 | 150 |
| 148 #endif // WEBRTC_API_DTLSIDENTITYSTORE_H_ | 151 #endif // WEBRTC_API_DTLSIDENTITYSTORE_H_ |
| OLD | NEW |