DtlsIdentityStoreInterface::RequestIdentity gets optional expires param.

This is a preparation CL. The expires param will be used in
a follow-up CL. Initially it will only be used by the
chromium implementation. Then we will either update the
webrtc implementation (DtlsIdentityStoreImpl) to use it or
we will remove that store completely as part of clean-up
work.

There are currently two versions of RequestIdentity, one
that takes KeyType and one that takes KeyParams.

The KeyType version is removed in favor of the new
KeyParams + expires version. The KeyParams version without
expires is kept as to not break chromium which currently
implements that. This is the version that can be removed in
a follow-up CL.

BUG=webrtc:5092, chromium:544902

Review URL: https://codereview.webrtc.org/1749193002

Cr-Commit-Position: refs/heads/master@{#11846}
This commit is contained in:
hbos 2016-03-02 07:55:53 -08:00 committed by Commit bot
parent 0a9fc05583
commit 25359e0cc2
6 changed files with 56 additions and 31 deletions

View File

@ -122,12 +122,15 @@ DtlsIdentityStoreImpl::~DtlsIdentityStoreImpl() {
}
void DtlsIdentityStoreImpl::RequestIdentity(
rtc::KeyType key_type,
const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>& observer) {
rtc::KeyParams key_params,
rtc::Optional<uint64_t> expires,
const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) {
RTC_DCHECK(signaling_thread_->IsCurrent());
RTC_DCHECK(observer);
GenerateIdentity(key_type, observer);
// Dropping parameterization and |expires|.
// TODO(hbos,torbjorng): Use parameterizaton/expiration. webrtc:5092.
GenerateIdentity(key_params.type(), observer);
}
void DtlsIdentityStoreImpl::OnMessage(rtc::Message* msg) {

View File

@ -17,6 +17,7 @@
#include "webrtc/base/messagehandler.h"
#include "webrtc/base/messagequeue.h"
#include "webrtc/base/optional.h"
#include "webrtc/base/refcount.h"
#include "webrtc/base/scoped_ptr.h"
#include "webrtc/base/scoped_ref_ptr.h"
@ -56,23 +57,24 @@ class DtlsIdentityStoreInterface {
// The |observer| will be called when the requested identity is ready, or when
// identity generation fails.
// TODO(torbjorng,hbos): The following RequestIdentity is about to be removed,
// see below todo.
virtual void RequestIdentity(
rtc::KeyType key_type,
const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) {
// Add default parameterization.
RequestIdentity(rtc::KeyParams(key_type), observer);
}
// TODO(torbjorng,hbos): Parameterized key types! The following
// RequestIdentity should replace the old one that takes rtc::KeyType. When
// the new one is implemented by Chromium and WebRTC the old one should be
// removed. crbug.com/544902, webrtc:5092.
// TODO(torbjorng,hbos): There are currently two versions of RequestIdentity,
// with default implementation to call the other version of itself (so that a
// call can be made regardless of which version has been overridden). The 1st
// version exists because it is currently implemented in chromium. The 2nd
// version will become the one and only RequestIdentity as soon as chromium
// implements the correct version. crbug.com/544902, webrtc:5092.
virtual void RequestIdentity(
rtc::KeyParams key_params,
const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) {
// Drop parameterization.
RequestIdentity(key_params.type(), observer);
// Add default ("null") expiration.
RequestIdentity(key_params, rtc::Optional<uint64_t>(), observer);
}
virtual void RequestIdentity(
rtc::KeyParams key_params,
rtc::Optional<uint64_t> expires,
const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) {
// Drop |expires|.
RequestIdentity(key_params, observer);
}
};
@ -89,7 +91,8 @@ class DtlsIdentityStoreImpl : public DtlsIdentityStoreInterface,
// DtlsIdentityStoreInterface override;
void RequestIdentity(
rtc::KeyType key_type,
rtc::KeyParams key_params,
rtc::Optional<uint64_t> expires,
const rtc::scoped_refptr<DtlsIdentityRequestObserver>& observer) override;
// rtc::MessageHandler override;

View File

@ -85,7 +85,9 @@ class DtlsIdentityStoreTest : public testing::Test {
TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessRSA) {
EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(rtc::KT_RSA), kTimeoutMs);
store_->RequestIdentity(rtc::KT_RSA, observer_.get());
store_->RequestIdentity(rtc::KeyParams(rtc::KT_RSA),
rtc::Optional<uint64_t>(),
observer_.get());
EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs);
EXPECT_TRUE_WAIT(store_->HasFreeIdentityForTesting(rtc::KT_RSA), kTimeoutMs);
@ -93,7 +95,9 @@ TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessRSA) {
observer_->Reset();
// Verifies that the callback is async when a free identity is ready.
store_->RequestIdentity(rtc::KT_RSA, observer_.get());
store_->RequestIdentity(rtc::KeyParams(rtc::KT_RSA),
rtc::Optional<uint64_t>(),
observer_.get());
EXPECT_FALSE(observer_->call_back_called());
EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs);
}
@ -102,13 +106,17 @@ TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessECDSA) {
// Since store currently does not preemptively generate free ECDSA identities
// we do not invoke HasFreeIdentityForTesting between requests.
store_->RequestIdentity(rtc::KT_ECDSA, observer_.get());
store_->RequestIdentity(rtc::KeyParams(rtc::KT_ECDSA),
rtc::Optional<uint64_t>(),
observer_.get());
EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs);
observer_->Reset();
// Verifies that the callback is async when a free identity is ready.
store_->RequestIdentity(rtc::KT_ECDSA, observer_.get());
store_->RequestIdentity(rtc::KeyParams(rtc::KT_ECDSA),
rtc::Optional<uint64_t>(),
observer_.get());
EXPECT_FALSE(observer_->call_back_called());
EXPECT_TRUE_WAIT(observer_->LastRequestSucceeded(), kTimeoutMs);
}
@ -116,7 +124,9 @@ TEST_F(DtlsIdentityStoreTest, RequestIdentitySuccessECDSA) {
TEST_F(DtlsIdentityStoreTest, DeleteStoreEarlyNoCrashRSA) {
EXPECT_FALSE(store_->HasFreeIdentityForTesting(rtc::KT_RSA));
store_->RequestIdentity(rtc::KT_RSA, observer_.get());
store_->RequestIdentity(rtc::KeyParams(rtc::KT_RSA),
rtc::Optional<uint64_t>(),
observer_.get());
store_.reset();
worker_thread_->Stop();
@ -126,7 +136,9 @@ TEST_F(DtlsIdentityStoreTest, DeleteStoreEarlyNoCrashRSA) {
TEST_F(DtlsIdentityStoreTest, DeleteStoreEarlyNoCrashECDSA) {
EXPECT_FALSE(store_->HasFreeIdentityForTesting(rtc::KT_ECDSA));
store_->RequestIdentity(rtc::KT_ECDSA, observer_.get());
store_->RequestIdentity(rtc::KeyParams(rtc::KT_ECDSA),
rtc::Optional<uint64_t>(),
observer_.get());
store_.reset();
worker_thread_->Stop();

View File

@ -45,10 +45,11 @@ class DtlsIdentityStoreWrapper : public DtlsIdentityStoreInterface {
}
void RequestIdentity(
rtc::KeyType key_type,
rtc::KeyParams key_params,
rtc::Optional<uint64_t> expires,
const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>&
observer) override {
store_->RequestIdentity(key_type, observer);
store_->RequestIdentity(key_params, expires, observer);
}
private:

View File

@ -96,11 +96,15 @@ class FakeDtlsIdentityStore : public webrtc::DtlsIdentityStoreInterface,
void use_alternate_key() { key_index_ = 1; }
void RequestIdentity(
rtc::KeyType key_type,
rtc::KeyParams key_params,
rtc::Optional<uint64_t> expires,
const rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>&
observer) override {
// TODO(hbos): Should be able to generate KT_ECDSA too.
RTC_DCHECK(key_type == rtc::KT_RSA || should_fail_);
RTC_DCHECK((key_params.type() == rtc::KT_RSA &&
key_params.rsa_params().mod_size == 1024 &&
key_params.rsa_params().pub_exp == 0x10001) ||
should_fail_);
MessageData* msg = new MessageData(
rtc::scoped_refptr<webrtc::DtlsIdentityRequestObserver>(observer));
rtc::Thread::Current()->Post(

View File

@ -188,13 +188,15 @@ WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory(
identity_request_observer_->SignalCertificateReady.connect(
this, &WebRtcSessionDescriptionFactory::SetCertificate);
rtc::KeyType key_type = rtc::KT_DEFAULT;
rtc::KeyParams key_params = rtc::KeyParams();
LOG(LS_VERBOSE) << "DTLS-SRTP enabled; sending DTLS identity request (key "
<< "type: " << key_type << ").";
<< "type: " << key_params.type() << ").";
// Request identity. This happens asynchronously, so the caller will have a
// chance to connect to SignalIdentityReady.
dtls_identity_store_->RequestIdentity(key_type, identity_request_observer_);
dtls_identity_store_->RequestIdentity(key_params,
rtc::Optional<uint64_t>(),
identity_request_observer_);
}
WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory(