| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 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_BASE_RTCCERTIFICATEGENERATOR_H_ | 11 #ifndef WEBRTC_BASE_RTCCERTIFICATEGENERATOR_H_ |
| 12 #define WEBRTC_BASE_RTCCERTIFICATEGENERATOR_H_ | 12 #define WEBRTC_BASE_RTCCERTIFICATEGENERATOR_H_ |
| 13 | 13 |
| 14 #include "webrtc/base/optional.h" | 14 #include "webrtc/base/optional.h" |
| 15 #include "webrtc/base/refcount.h" | 15 #include "webrtc/base/refcount.h" |
| 16 #include "webrtc/base/rtccertificate.h" | 16 #include "webrtc/base/rtccertificate.h" |
| 17 #include "webrtc/base/scoped_ref_ptr.h" | 17 #include "webrtc/base/scoped_ref_ptr.h" |
| 18 #include "webrtc/base/sslidentity.h" | 18 #include "webrtc/base/sslidentity.h" |
| 19 #include "webrtc/base/thread.h" | 19 #include "webrtc/base/thread.h" |
| 20 | 20 |
| 21 namespace rtc { | 21 namespace rtc { |
| 22 | 22 |
| 23 // See |RTCCertificateGeneratorInterface::GenerateCertificateAsync|. |
| 23 class RTCCertificateGeneratorCallback : public RefCountInterface { | 24 class RTCCertificateGeneratorCallback : public RefCountInterface { |
| 24 public: | 25 public: |
| 25 virtual void OnSuccess( | 26 virtual void OnSuccess( |
| 26 const scoped_refptr<RTCCertificate>& certificate) = 0; | 27 const scoped_refptr<RTCCertificate>& certificate) = 0; |
| 27 virtual void OnFailure() = 0; | 28 virtual void OnFailure() = 0; |
| 28 | 29 |
| 29 protected: | 30 protected: |
| 30 ~RTCCertificateGeneratorCallback() override {} | 31 ~RTCCertificateGeneratorCallback() override {} |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 // Generates |RTCCertificate|s. | 34 // Generates |RTCCertificate|s. |
| 35 // See |RTCCertificateGenerator| for the WebRTC repo's implementation. |
| 36 class RTCCertificateGeneratorInterface { |
| 37 public: |
| 38 virtual ~RTCCertificateGeneratorInterface() {} |
| 39 |
| 40 // Generates a certificate asynchronously on the worker thread. |
| 41 // Must be called on the signaling thread. The |callback| is invoked with the |
| 42 // result on the signaling thread. |exipres_ms| optionally specifies for how |
| 43 // long we want the certificate to be valid, but the implementation may choose |
| 44 // its own restrictions on the expiration time. |
| 45 virtual void GenerateCertificateAsync( |
| 46 const KeyParams& key_params, |
| 47 const Optional<uint64_t>& expires_ms, |
| 48 const scoped_refptr<RTCCertificateGeneratorCallback>& callback) = 0; |
| 49 }; |
| 50 |
| 51 // Standard implementation of |RTCCertificateGeneratorInterface|. |
| 34 // The static function |GenerateCertificate| generates a certificate on the | 52 // The static function |GenerateCertificate| generates a certificate on the |
| 35 // current thread. The |RTCCertificateGenerator| instance generates certificates | 53 // current thread. The |RTCCertificateGenerator| instance generates certificates |
| 36 // asynchronously on the worker thread with |GenerateCertificateAsync|. | 54 // asynchronously on the worker thread with |GenerateCertificateAsync|. |
| 37 class RTCCertificateGenerator { | 55 class RTCCertificateGenerator : public RTCCertificateGeneratorInterface { |
| 38 public: | 56 public: |
| 39 // Generates a certificate on the current thread. Returns null on failure. | 57 // Generates a certificate on the current thread. Returns null on failure. |
| 40 // If |expires_ms| is specified, the certificate will expire in approximately | 58 // If |expires_ms| is specified, the certificate will expire in approximately |
| 41 // that many milliseconds from now. |expires_ms| is limited to a year, a | 59 // that many milliseconds from now. |expires_ms| is limited to a year, a |
| 42 // larger value than that is clamped down to a year. If |expires_ms| is not | 60 // larger value than that is clamped down to a year. If |expires_ms| is not |
| 43 // specified, a default expiration time is used. | 61 // specified, a default expiration time is used. |
| 44 static scoped_refptr<RTCCertificate> GenerateCertificate( | 62 static scoped_refptr<RTCCertificate> GenerateCertificate( |
| 45 const KeyParams& key_params, | 63 const KeyParams& key_params, |
| 46 const Optional<uint64_t>& expires_ms); | 64 const Optional<uint64_t>& expires_ms); |
| 47 | 65 |
| 48 RTCCertificateGenerator(Thread* signaling_thread, Thread* worker_thread); | 66 RTCCertificateGenerator(Thread* signaling_thread, Thread* worker_thread); |
| 67 ~RTCCertificateGenerator() override {} |
| 49 | 68 |
| 50 // Generates a certificate asynchronously on the worker thread. | 69 // |RTCCertificateGeneratorInterface| overrides. |
| 51 // Must be called on the signaling thread. The |callback| is invoked with the | 70 // If |expires_ms| is specified, the certificate will expire in approximately |
| 52 // result on the signaling thread. If |expires_ms| is specified, the | 71 // that many milliseconds from now. |expires_ms| is limited to a year, a |
| 53 // certificate will expire in approximately that many milliseconds from now. | 72 // larger value than that is clamped down to a year. If |expires_ms| is not |
| 54 // |expires_ms| is limited to a year, a larger value than that is clamped down | 73 // specified, a default expiration time is used. |
| 55 // to a year. If |expires_ms| is not specified, a default expiration time is | |
| 56 // used. | |
| 57 void GenerateCertificateAsync( | 74 void GenerateCertificateAsync( |
| 58 const KeyParams& key_params, | 75 const KeyParams& key_params, |
| 59 const Optional<uint64_t>& expires_ms, | 76 const Optional<uint64_t>& expires_ms, |
| 60 const scoped_refptr<RTCCertificateGeneratorCallback>& callback); | 77 const scoped_refptr<RTCCertificateGeneratorCallback>& callback) override; |
| 61 | 78 |
| 62 private: | 79 private: |
| 63 Thread* const signaling_thread_; | 80 Thread* const signaling_thread_; |
| 64 Thread* const worker_thread_; | 81 Thread* const worker_thread_; |
| 65 }; | 82 }; |
| 66 | 83 |
| 67 } // namespace rtc | 84 } // namespace rtc |
| 68 | 85 |
| 69 #endif // WEBRTC_BASE_RTCCERTIFICATEGENERATOR_H_ | 86 #endif // WEBRTC_BASE_RTCCERTIFICATEGENERATOR_H_ |
| OLD | NEW |