This is a new way of generating RTCCertificate objects that is meant to replace DtlsIdentityStoreInterface and all of its implementations (clean up work). It is similar to the identity store in that it generates on the worker thread and does callback on the signaling thread, but: - It does not generate identities in the background that you did not ask for (preemptive generation made more sense before certificates were parameterized, not so much anymore, and ECDSA which will be most common takes like <=2 ms to generate). - As such this code is less complicated than the store's code. - The API is different, it takes Optional<uint64_t> expires and it returns RTCCertificates, not SSLIdentities. - It supports a blocking version of GenerateCertificate that can be called from any thread, necessary for Chrome which can generate certificates before the signaling/worker threads have been initialized as WebRTC-threads (Chrome can invoke this version on the worker thread outside of WebRTC). This CL does not remove the identity store, only adds the alternative. Follow-up CLs will start using it, the store will be removed once it is no longer used anywhere. BUG=webrtc:5707, webrtc:5708 R=hta@webrtc.org, torbjorng@webrtc.org Review URL: https://codereview.webrtc.org/1883813002 . Cr-Commit-Position: refs/heads/master@{#12381}
70 lines
2.6 KiB
C++
70 lines
2.6 KiB
C++
/*
|
|
* Copyright 2016 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#ifndef WEBRTC_BASE_RTCCERTIFICATEGENERATOR_H_
|
|
#define WEBRTC_BASE_RTCCERTIFICATEGENERATOR_H_
|
|
|
|
#include "webrtc/base/optional.h"
|
|
#include "webrtc/base/refcount.h"
|
|
#include "webrtc/base/rtccertificate.h"
|
|
#include "webrtc/base/scoped_ref_ptr.h"
|
|
#include "webrtc/base/sslidentity.h"
|
|
#include "webrtc/base/thread.h"
|
|
|
|
namespace rtc {
|
|
|
|
class RTCCertificateGeneratorCallback : public RefCountInterface {
|
|
public:
|
|
virtual void OnSuccess(
|
|
const scoped_refptr<RTCCertificate>& certificate) = 0;
|
|
virtual void OnFailure() = 0;
|
|
|
|
protected:
|
|
~RTCCertificateGeneratorCallback() override {}
|
|
};
|
|
|
|
// Generates |RTCCertificate|s.
|
|
// The static function |GenerateCertificate| generates a certificate on the
|
|
// current thread. The |RTCCertificateGenerator| instance generates certificates
|
|
// asynchronously on the worker thread with |GenerateCertificateAsync|.
|
|
class RTCCertificateGenerator {
|
|
public:
|
|
// Generates a certificate on the current thread. Returns null on failure.
|
|
// If |expires_ms| is specified, the certificate will expire in approximately
|
|
// that many milliseconds from now. |expires_ms| is limited to a year, a
|
|
// larger value than that is clamped down to a year. If |expires_ms| is not
|
|
// specified, a default expiration time is used.
|
|
static scoped_refptr<RTCCertificate> GenerateCertificate(
|
|
const KeyParams& key_params,
|
|
const Optional<uint64_t>& expires_ms);
|
|
|
|
RTCCertificateGenerator(Thread* signaling_thread, Thread* worker_thread);
|
|
|
|
// Generates a certificate asynchronously on the worker thread.
|
|
// Must be called on the signaling thread. The |callback| is invoked with the
|
|
// result on the signaling thread. If |expires_ms| is specified, the
|
|
// certificate will expire in approximately that many milliseconds from now.
|
|
// |expires_ms| is limited to a year, a larger value than that is clamped down
|
|
// to a year. If |expires_ms| is not specified, a default expiration time is
|
|
// used.
|
|
void GenerateCertificateAsync(
|
|
const KeyParams& key_params,
|
|
const Optional<uint64_t>& expires_ms,
|
|
const scoped_refptr<RTCCertificateGeneratorCallback>& callback);
|
|
|
|
private:
|
|
Thread* const signaling_thread_;
|
|
Thread* const worker_thread_;
|
|
};
|
|
|
|
} // namespace rtc
|
|
|
|
#endif // WEBRTC_BASE_RTCCERTIFICATEGENERATOR_H_
|