2013-08-10 07:18:04 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2013 The WebRTC project authors. All Rights Reserved.
|
2013-08-10 07:18:04 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* 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.
|
2013-08-10 07:18:04 +00:00
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "pc/webrtcsessiondescriptionfactory.h"
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2017-10-30 09:57:42 -07:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <string>
|
2015-12-17 03:04:15 -08:00
|
|
|
#include <utility>
|
2017-10-30 09:57:42 -07:00
|
|
|
#include <vector>
|
2015-12-17 03:04:15 -08:00
|
|
|
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
#include "absl/memory/memory.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/jsep.h"
|
|
|
|
|
#include "api/jsepsessiondescription.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/sslidentity.h"
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2013-11-20 21:49:41 +00:00
|
|
|
using cricket::MediaSessionOptions;
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2013-11-20 21:49:41 +00:00
|
|
|
namespace webrtc {
|
2013-08-10 07:18:04 +00:00
|
|
|
namespace {
|
|
|
|
|
static const char kFailedDueToIdentityFailed[] =
|
|
|
|
|
" failed because DTLS identity request failed";
|
2015-07-09 03:25:02 -07:00
|
|
|
static const char kFailedDueToSessionShutdown[] =
|
|
|
|
|
" failed because the session was shut down";
|
2013-08-10 07:18:04 +00:00
|
|
|
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
static const uint64_t kInitSessionVersion = 2;
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2017-08-17 14:10:50 -07:00
|
|
|
static bool CompareSenderOptions(const cricket::SenderOptions& sender1,
|
|
|
|
|
const cricket::SenderOptions& sender2) {
|
|
|
|
|
return sender1.track_id < sender2.track_id;
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-17 14:10:50 -07:00
|
|
|
static bool SameId(const cricket::SenderOptions& sender1,
|
|
|
|
|
const cricket::SenderOptions& sender2) {
|
|
|
|
|
return sender1.track_id == sender2.track_id;
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-17 14:10:50 -07:00
|
|
|
// Check that each sender has a unique ID.
|
|
|
|
|
static bool ValidMediaSessionOptions(
|
|
|
|
|
const cricket::MediaSessionOptions& session_options) {
|
|
|
|
|
std::vector<cricket::SenderOptions> sorted_senders;
|
|
|
|
|
for (const cricket::MediaDescriptionOptions& media_description_options :
|
|
|
|
|
session_options.media_description_options) {
|
|
|
|
|
sorted_senders.insert(sorted_senders.end(),
|
|
|
|
|
media_description_options.sender_options.begin(),
|
|
|
|
|
media_description_options.sender_options.end());
|
|
|
|
|
}
|
|
|
|
|
std::sort(sorted_senders.begin(), sorted_senders.end(), CompareSenderOptions);
|
|
|
|
|
std::vector<cricket::SenderOptions>::iterator it =
|
|
|
|
|
std::adjacent_find(sorted_senders.begin(), sorted_senders.end(), SameId);
|
|
|
|
|
return it == sorted_senders.end();
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
MSG_CREATE_SESSIONDESCRIPTION_SUCCESS,
|
2015-08-25 09:53:21 +02:00
|
|
|
MSG_CREATE_SESSIONDESCRIPTION_FAILED,
|
|
|
|
|
MSG_USE_CONSTRUCTOR_CERTIFICATE
|
2013-08-10 07:18:04 +00:00
|
|
|
};
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
struct CreateSessionDescriptionMsg : public rtc::MessageData {
|
2013-08-10 07:18:04 +00:00
|
|
|
explicit CreateSessionDescriptionMsg(
|
2018-05-24 10:53:49 +02:00
|
|
|
webrtc::CreateSessionDescriptionObserver* observer,
|
|
|
|
|
RTCError error_in)
|
|
|
|
|
: observer(observer), error(std::move(error_in)) {}
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer;
|
2018-05-24 10:53:49 +02:00
|
|
|
RTCError error;
|
2016-04-27 06:47:29 -07:00
|
|
|
std::unique_ptr<webrtc::SessionDescriptionInterface> description;
|
2013-08-10 07:18:04 +00:00
|
|
|
};
|
|
|
|
|
} // namespace
|
|
|
|
|
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
void WebRtcCertificateGeneratorCallback::OnFailure() {
|
|
|
|
|
SignalRequestFailed();
|
2015-03-04 22:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
void WebRtcCertificateGeneratorCallback::OnSuccess(
|
|
|
|
|
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
|
|
|
|
|
SignalCertificateReady(certificate);
|
2015-03-04 22:17:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-10 07:18:04 +00:00
|
|
|
// static
|
|
|
|
|
void WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription(
|
|
|
|
|
const SessionDescriptionInterface* source_desc,
|
2016-02-23 17:24:52 -08:00
|
|
|
const std::string& content_name,
|
2013-08-10 07:18:04 +00:00
|
|
|
SessionDescriptionInterface* dest_desc) {
|
2016-02-23 17:24:52 -08:00
|
|
|
if (!source_desc) {
|
2013-08-10 07:18:04 +00:00
|
|
|
return;
|
2016-02-23 17:24:52 -08:00
|
|
|
}
|
|
|
|
|
const cricket::ContentInfos& contents =
|
|
|
|
|
source_desc->description()->contents();
|
|
|
|
|
const cricket::ContentInfo* cinfo =
|
|
|
|
|
source_desc->description()->GetContentByName(content_name);
|
|
|
|
|
if (!cinfo) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
size_t mediasection_index = static_cast<int>(cinfo - &contents[0]);
|
|
|
|
|
const IceCandidateCollection* source_candidates =
|
|
|
|
|
source_desc->candidates(mediasection_index);
|
|
|
|
|
const IceCandidateCollection* dest_candidates =
|
|
|
|
|
dest_desc->candidates(mediasection_index);
|
2016-03-01 16:21:07 -08:00
|
|
|
if (!source_candidates || !dest_candidates) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-23 17:24:52 -08:00
|
|
|
for (size_t n = 0; n < source_candidates->count(); ++n) {
|
|
|
|
|
const IceCandidateInterface* new_candidate = source_candidates->at(n);
|
|
|
|
|
if (!dest_candidates->HasCandidate(new_candidate)) {
|
|
|
|
|
dest_desc->AddCandidate(source_candidates->at(n));
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-25 09:53:21 +02:00
|
|
|
// Private constructor called by other constructors.
|
2013-08-10 07:18:04 +00:00
|
|
|
WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory(
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::Thread* signaling_thread,
|
2013-08-10 07:18:04 +00:00
|
|
|
cricket::ChannelManager* channel_manager,
|
2018-01-23 16:38:46 -08:00
|
|
|
PeerConnectionInternal* pc,
|
2013-08-10 07:18:04 +00:00
|
|
|
const std::string& session_id,
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
|
|
|
|
|
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate)
|
2013-08-10 07:18:04 +00:00
|
|
|
: signaling_thread_(signaling_thread),
|
|
|
|
|
session_desc_factory_(channel_manager, &transport_desc_factory_),
|
|
|
|
|
// RFC 4566 suggested a Network Time Protocol (NTP) format timestamp
|
|
|
|
|
// as the session id and session version. To simplify, it should be fine
|
|
|
|
|
// to just use a random number as session id and start version from
|
|
|
|
|
// |kInitSessionVersion|.
|
|
|
|
|
session_version_(kInitSessionVersion),
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
cert_generator_(std::move(cert_generator)),
|
2017-10-23 14:49:26 -07:00
|
|
|
pc_(pc),
|
2013-08-10 07:18:04 +00:00
|
|
|
session_id_(session_id),
|
2015-08-25 09:53:21 +02:00
|
|
|
certificate_request_state_(CERTIFICATE_NOT_NEEDED) {
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
RTC_DCHECK(signaling_thread_);
|
2017-10-23 14:49:26 -07:00
|
|
|
RTC_DCHECK(!(cert_generator_ && certificate));
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
bool dtls_enabled = cert_generator_ || certificate;
|
2014-03-04 19:54:57 +00:00
|
|
|
// SRTP-SDES is disabled if DTLS is on.
|
|
|
|
|
SetSdesPolicy(dtls_enabled ? cricket::SEC_DISABLED : cricket::SEC_REQUIRED);
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
if (!dtls_enabled) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_VERBOSE) << "DTLS-SRTP disabled.";
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2013-11-20 21:49:41 +00:00
|
|
|
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
if (certificate) {
|
|
|
|
|
// Use |certificate|.
|
|
|
|
|
certificate_request_state_ = CERTIFICATE_WAITING;
|
|
|
|
|
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_VERBOSE) << "DTLS-SRTP enabled; has certificate parameter.";
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
// We already have a certificate but we wait to do |SetIdentity|; if we do
|
|
|
|
|
// it in the constructor then the caller has not had a chance to connect to
|
|
|
|
|
// |SignalCertificateReady|.
|
|
|
|
|
signaling_thread_->Post(
|
2016-06-10 14:17:27 -07:00
|
|
|
RTC_FROM_HERE, this, MSG_USE_CONSTRUCTOR_CERTIFICATE,
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
new rtc::ScopedRefMessageData<rtc::RTCCertificate>(certificate));
|
|
|
|
|
} else {
|
|
|
|
|
// Generate certificate.
|
|
|
|
|
certificate_request_state_ = CERTIFICATE_WAITING;
|
|
|
|
|
|
|
|
|
|
rtc::scoped_refptr<WebRtcCertificateGeneratorCallback> callback(
|
|
|
|
|
new rtc::RefCountedObject<WebRtcCertificateGeneratorCallback>());
|
|
|
|
|
callback->SignalRequestFailed.connect(
|
|
|
|
|
this, &WebRtcSessionDescriptionFactory::OnCertificateRequestFailed);
|
|
|
|
|
callback->SignalCertificateReady.connect(
|
|
|
|
|
this, &WebRtcSessionDescriptionFactory::SetCertificate);
|
|
|
|
|
|
|
|
|
|
rtc::KeyParams key_params = rtc::KeyParams();
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_VERBOSE)
|
2018-02-13 10:37:07 +01:00
|
|
|
<< "DTLS-SRTP enabled; sending DTLS identity request (key type: "
|
|
|
|
|
<< key_params.type() << ").";
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
|
|
|
|
|
// Request certificate. This happens asynchronously, so that the caller gets
|
|
|
|
|
// a chance to connect to |SignalCertificateReady|.
|
2018-06-19 16:47:43 +02:00
|
|
|
cert_generator_->GenerateCertificateAsync(key_params, absl::nullopt,
|
2017-11-16 10:54:27 +01:00
|
|
|
callback);
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
}
|
2015-08-25 09:53:21 +02:00
|
|
|
}
|
2013-11-20 21:49:41 +00:00
|
|
|
|
2013-08-10 07:18:04 +00:00
|
|
|
WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(signaling_thread_->IsCurrent());
|
2015-07-09 03:25:02 -07:00
|
|
|
|
|
|
|
|
// Fail any requests that were asked for before identity generation completed.
|
|
|
|
|
FailPendingRequests(kFailedDueToSessionShutdown);
|
|
|
|
|
|
|
|
|
|
// Process all pending notifications in the message queue. If we don't do
|
|
|
|
|
// this, requests will linger and not know they succeeded or failed.
|
|
|
|
|
rtc::MessageList list;
|
|
|
|
|
signaling_thread_->Clear(this, rtc::MQID_ANY, &list);
|
2015-08-25 09:53:21 +02:00
|
|
|
for (auto& msg : list) {
|
|
|
|
|
if (msg.message_id != MSG_USE_CONSTRUCTOR_CERTIFICATE) {
|
|
|
|
|
OnMessage(&msg);
|
|
|
|
|
} else {
|
|
|
|
|
// Skip MSG_USE_CONSTRUCTOR_CERTIFICATE because we don't want to trigger
|
|
|
|
|
// SetIdentity-related callbacks in the destructor. This can be a problem
|
|
|
|
|
// when WebRtcSession listens to the callback but it was the WebRtcSession
|
|
|
|
|
// destructor that caused WebRtcSessionDescriptionFactory's destruction.
|
|
|
|
|
// The callback is then ignored, leaking memory allocated by OnMessage for
|
|
|
|
|
// MSG_USE_CONSTRUCTOR_CERTIFICATE.
|
|
|
|
|
delete msg.pdata;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebRtcSessionDescriptionFactory::CreateOffer(
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
2015-10-14 11:33:11 -07:00
|
|
|
const PeerConnectionInterface::RTCOfferAnswerOptions& options,
|
|
|
|
|
const cricket::MediaSessionOptions& session_options) {
|
2013-08-10 07:18:04 +00:00
|
|
|
std::string error = "CreateOffer";
|
2015-08-25 09:53:21 +02:00
|
|
|
if (certificate_request_state_ == CERTIFICATE_FAILED) {
|
2013-08-10 07:18:04 +00:00
|
|
|
error += kFailedDueToIdentityFailed;
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << error;
|
2013-08-10 07:18:04 +00:00
|
|
|
PostCreateSessionDescriptionFailed(observer, error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-17 14:10:50 -07:00
|
|
|
if (!ValidMediaSessionOptions(session_options)) {
|
|
|
|
|
error += " called with invalid session options";
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << error;
|
2013-08-10 07:18:04 +00:00
|
|
|
PostCreateSessionDescriptionFailed(observer, error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CreateSessionDescriptionRequest request(
|
2014-08-04 18:34:16 +00:00
|
|
|
CreateSessionDescriptionRequest::kOffer, observer, session_options);
|
2015-08-25 09:53:21 +02:00
|
|
|
if (certificate_request_state_ == CERTIFICATE_WAITING) {
|
2013-08-10 07:18:04 +00:00
|
|
|
create_session_description_requests_.push(request);
|
|
|
|
|
} else {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(certificate_request_state_ == CERTIFICATE_SUCCEEDED ||
|
|
|
|
|
certificate_request_state_ == CERTIFICATE_NOT_NEEDED);
|
2013-08-10 07:18:04 +00:00
|
|
|
InternalCreateOffer(request);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebRtcSessionDescriptionFactory::CreateAnswer(
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
2015-10-14 11:33:11 -07:00
|
|
|
const cricket::MediaSessionOptions& session_options) {
|
2013-08-10 07:18:04 +00:00
|
|
|
std::string error = "CreateAnswer";
|
2015-08-25 09:53:21 +02:00
|
|
|
if (certificate_request_state_ == CERTIFICATE_FAILED) {
|
2013-08-10 07:18:04 +00:00
|
|
|
error += kFailedDueToIdentityFailed;
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << error;
|
2013-08-10 07:18:04 +00:00
|
|
|
PostCreateSessionDescriptionFailed(observer, error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-10-23 14:49:26 -07:00
|
|
|
if (!pc_->remote_description()) {
|
2013-08-10 07:18:04 +00:00
|
|
|
error += " can't be called before SetRemoteDescription.";
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << error;
|
2013-08-10 07:18:04 +00:00
|
|
|
PostCreateSessionDescriptionFailed(observer, error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-12-07 10:27:41 -08:00
|
|
|
if (pc_->remote_description()->GetType() != SdpType::kOffer) {
|
2013-08-10 07:18:04 +00:00
|
|
|
error += " failed because remote_description is not an offer.";
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << error;
|
2013-08-10 07:18:04 +00:00
|
|
|
PostCreateSessionDescriptionFailed(observer, error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-17 14:10:50 -07:00
|
|
|
if (!ValidMediaSessionOptions(session_options)) {
|
|
|
|
|
error += " called with invalid session options.";
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << error;
|
2013-08-10 07:18:04 +00:00
|
|
|
PostCreateSessionDescriptionFailed(observer, error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CreateSessionDescriptionRequest request(
|
2015-10-14 11:33:11 -07:00
|
|
|
CreateSessionDescriptionRequest::kAnswer, observer, session_options);
|
2015-08-25 09:53:21 +02:00
|
|
|
if (certificate_request_state_ == CERTIFICATE_WAITING) {
|
2013-08-10 07:18:04 +00:00
|
|
|
create_session_description_requests_.push(request);
|
|
|
|
|
} else {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(certificate_request_state_ == CERTIFICATE_SUCCEEDED ||
|
|
|
|
|
certificate_request_state_ == CERTIFICATE_NOT_NEEDED);
|
2013-08-10 07:18:04 +00:00
|
|
|
InternalCreateAnswer(request);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 19:54:57 +00:00
|
|
|
void WebRtcSessionDescriptionFactory::SetSdesPolicy(
|
|
|
|
|
cricket::SecurePolicy secure_policy) {
|
2013-08-10 07:18:04 +00:00
|
|
|
session_desc_factory_.set_secure(secure_policy);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-04 19:54:57 +00:00
|
|
|
cricket::SecurePolicy WebRtcSessionDescriptionFactory::SdesPolicy() const {
|
2013-08-10 07:18:04 +00:00
|
|
|
return session_desc_factory_.secure();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
void WebRtcSessionDescriptionFactory::OnMessage(rtc::Message* msg) {
|
2013-08-10 07:18:04 +00:00
|
|
|
switch (msg->message_id) {
|
|
|
|
|
case MSG_CREATE_SESSIONDESCRIPTION_SUCCESS: {
|
|
|
|
|
CreateSessionDescriptionMsg* param =
|
|
|
|
|
static_cast<CreateSessionDescriptionMsg*>(msg->pdata);
|
|
|
|
|
param->observer->OnSuccess(param->description.release());
|
|
|
|
|
delete param;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case MSG_CREATE_SESSIONDESCRIPTION_FAILED: {
|
|
|
|
|
CreateSessionDescriptionMsg* param =
|
|
|
|
|
static_cast<CreateSessionDescriptionMsg*>(msg->pdata);
|
2018-05-24 10:53:49 +02:00
|
|
|
param->observer->OnFailure(std::move(param->error));
|
2013-08-10 07:18:04 +00:00
|
|
|
delete param;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-08-25 09:53:21 +02:00
|
|
|
case MSG_USE_CONSTRUCTOR_CERTIFICATE: {
|
|
|
|
|
rtc::ScopedRefMessageData<rtc::RTCCertificate>* param =
|
|
|
|
|
static_cast<rtc::ScopedRefMessageData<rtc::RTCCertificate>*>(
|
|
|
|
|
msg->pdata);
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "Using certificate supplied to the constructor.";
|
2015-08-27 10:12:24 +02:00
|
|
|
SetCertificate(param->data());
|
2015-08-25 09:53:21 +02:00
|
|
|
delete param;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-08-10 07:18:04 +00:00
|
|
|
default:
|
2017-01-11 05:56:46 -08:00
|
|
|
RTC_NOTREACHED();
|
2013-08-10 07:18:04 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebRtcSessionDescriptionFactory::InternalCreateOffer(
|
|
|
|
|
CreateSessionDescriptionRequest request) {
|
2017-10-23 14:49:26 -07:00
|
|
|
if (pc_->local_description()) {
|
2017-08-17 14:10:50 -07:00
|
|
|
// If the needs-ice-restart flag is set as described by JSEP, we should
|
|
|
|
|
// generate an offer with a new ufrag/password to trigger an ICE restart.
|
|
|
|
|
for (cricket::MediaDescriptionOptions& options :
|
|
|
|
|
request.options.media_description_options) {
|
2017-10-23 14:49:26 -07:00
|
|
|
if (pc_->NeedsIceRestart(options.mid)) {
|
2017-08-17 14:10:50 -07:00
|
|
|
options.transport_options.ice_restart = true;
|
2016-12-10 13:15:33 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 15:02:44 -07:00
|
|
|
cricket::SessionDescription* desc(session_desc_factory_.CreateOffer(
|
2017-10-23 14:49:26 -07:00
|
|
|
request.options, pc_->local_description()
|
|
|
|
|
? pc_->local_description()->description()
|
2015-10-14 15:02:44 -07:00
|
|
|
: nullptr));
|
2013-08-10 07:18:04 +00:00
|
|
|
// RFC 3264
|
|
|
|
|
// When issuing an offer that modifies the session,
|
|
|
|
|
// the "o=" line of the new SDP MUST be identical to that in the
|
|
|
|
|
// previous SDP, except that the version in the origin field MUST
|
|
|
|
|
// increment by one from the previous SDP.
|
|
|
|
|
|
|
|
|
|
// Just increase the version number by one each time when a new offer
|
|
|
|
|
// is created regardless if it's identical to the previous one or not.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
// The |session_version_| is a uint64_t, the wrap around should not happen.
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(session_version_ + 1 > session_version_);
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
auto offer = absl::make_unique<JsepSessionDescription>(SdpType::kOffer);
|
2013-08-10 07:18:04 +00:00
|
|
|
if (!offer->Initialize(desc, session_id_,
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::ToString(session_version_++))) {
|
2014-03-04 19:54:57 +00:00
|
|
|
PostCreateSessionDescriptionFailed(request.observer,
|
|
|
|
|
"Failed to initialize the offer.");
|
2013-08-10 07:18:04 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2017-10-23 14:49:26 -07:00
|
|
|
if (pc_->local_description()) {
|
2017-08-17 14:10:50 -07:00
|
|
|
for (const cricket::MediaDescriptionOptions& options :
|
|
|
|
|
request.options.media_description_options) {
|
|
|
|
|
if (!options.transport_options.ice_restart) {
|
2017-10-23 14:49:26 -07:00
|
|
|
CopyCandidatesFromSessionDescription(pc_->local_description(),
|
2017-12-07 10:27:41 -08:00
|
|
|
options.mid, offer.get());
|
2016-02-23 17:24:52 -08:00
|
|
|
}
|
|
|
|
|
}
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
2017-12-07 10:27:41 -08:00
|
|
|
PostCreateSessionDescriptionSucceeded(request.observer, std::move(offer));
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebRtcSessionDescriptionFactory::InternalCreateAnswer(
|
|
|
|
|
CreateSessionDescriptionRequest request) {
|
2017-10-23 14:49:26 -07:00
|
|
|
if (pc_->remote_description()) {
|
2017-08-17 14:10:50 -07:00
|
|
|
for (cricket::MediaDescriptionOptions& options :
|
|
|
|
|
request.options.media_description_options) {
|
2016-02-23 17:24:52 -08:00
|
|
|
// According to http://tools.ietf.org/html/rfc5245#section-9.2.1.1
|
|
|
|
|
// an answer should also contain new ICE ufrag and password if an offer
|
|
|
|
|
// has been received with new ufrag and password.
|
2017-08-17 14:10:50 -07:00
|
|
|
options.transport_options.ice_restart =
|
2017-10-23 14:49:26 -07:00
|
|
|
pc_->IceRestartPending(options.mid);
|
2016-02-23 17:24:52 -08:00
|
|
|
// We should pass the current SSL role to the transport description
|
|
|
|
|
// factory, if there is already an existing ongoing session.
|
|
|
|
|
rtc::SSLRole ssl_role;
|
2017-10-23 14:49:26 -07:00
|
|
|
if (pc_->GetSslRole(options.mid, &ssl_role)) {
|
2017-08-17 14:10:50 -07:00
|
|
|
options.transport_options.prefer_passive_role =
|
2016-02-23 17:24:52 -08:00
|
|
|
(rtc::SSL_SERVER == ssl_role);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-23 23:21:25 +00:00
|
|
|
}
|
2013-08-10 07:18:04 +00:00
|
|
|
|
|
|
|
|
cricket::SessionDescription* desc(session_desc_factory_.CreateAnswer(
|
2017-10-23 14:49:26 -07:00
|
|
|
pc_->remote_description() ? pc_->remote_description()->description()
|
|
|
|
|
: nullptr,
|
|
|
|
|
request.options,
|
|
|
|
|
pc_->local_description() ? pc_->local_description()->description()
|
|
|
|
|
: nullptr));
|
2013-08-10 07:18:04 +00:00
|
|
|
// RFC 3264
|
|
|
|
|
// If the answer is different from the offer in any way (different IP
|
|
|
|
|
// addresses, ports, etc.), the origin line MUST be different in the answer.
|
|
|
|
|
// In that case, the version number in the "o=" line of the answer is
|
|
|
|
|
// unrelated to the version number in the o line of the offer.
|
|
|
|
|
// Get a new version number by increasing the |session_version_answer_|.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
// The |session_version_| is a uint64_t, the wrap around should not happen.
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(session_version_ + 1 > session_version_);
|
Use absl::make_unique and absl::WrapUnique directly
Instead of going through our wrappers in ptr_util.h.
This CL was generated by the following script:
git grep -l ptr_util | xargs perl -pi -e 's,#include "rtc_base/ptr_util.h",#include "absl/memory/memory.h",'
git grep -l MakeUnique | xargs perl -pi -e 's,\b(rtc::)?MakeUnique\b,absl::make_unique,g'
git grep -l WrapUnique | xargs perl -pi -e 's,\b(rtc::)?WrapUnique\b,absl::WrapUnique,g'
git checkout -- rtc_base/ptr_util{.h,_unittest.cc}
git cl format
Followed by manually adding dependencies on
//third_party/abseil-cpp/absl/memory until `gn check` stopped
complaining.
Bug: webrtc:9473
Change-Id: I89ccd363f070479b8c431eb2c3d404a46eaacc1c
Reviewed-on: https://webrtc-review.googlesource.com/86600
Commit-Queue: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23850}
2018-07-05 11:40:33 +02:00
|
|
|
auto answer = absl::make_unique<JsepSessionDescription>(SdpType::kAnswer);
|
2013-08-10 07:18:04 +00:00
|
|
|
if (!answer->Initialize(desc, session_id_,
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::ToString(session_version_++))) {
|
2013-08-10 07:18:04 +00:00
|
|
|
PostCreateSessionDescriptionFailed(request.observer,
|
2014-03-04 19:54:57 +00:00
|
|
|
"Failed to initialize the answer.");
|
2013-08-10 07:18:04 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2017-10-23 14:49:26 -07:00
|
|
|
if (pc_->local_description()) {
|
2017-08-17 14:10:50 -07:00
|
|
|
// Include all local ICE candidates in the SessionDescription unless
|
|
|
|
|
// the remote peer has requested an ICE restart.
|
|
|
|
|
for (const cricket::MediaDescriptionOptions& options :
|
|
|
|
|
request.options.media_description_options) {
|
|
|
|
|
if (!options.transport_options.ice_restart) {
|
2017-10-23 14:49:26 -07:00
|
|
|
CopyCandidatesFromSessionDescription(pc_->local_description(),
|
2017-12-07 10:27:41 -08:00
|
|
|
options.mid, answer.get());
|
2016-02-23 17:24:52 -08:00
|
|
|
}
|
|
|
|
|
}
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
2017-12-07 10:27:41 -08:00
|
|
|
PostCreateSessionDescriptionSucceeded(request.observer, std::move(answer));
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-09 03:25:02 -07:00
|
|
|
void WebRtcSessionDescriptionFactory::FailPendingRequests(
|
|
|
|
|
const std::string& reason) {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(signaling_thread_->IsCurrent());
|
2015-07-09 03:25:02 -07:00
|
|
|
while (!create_session_description_requests_.empty()) {
|
|
|
|
|
const CreateSessionDescriptionRequest& request =
|
|
|
|
|
create_session_description_requests_.front();
|
|
|
|
|
PostCreateSessionDescriptionFailed(
|
|
|
|
|
request.observer,
|
|
|
|
|
((request.type == CreateSessionDescriptionRequest::kOffer)
|
|
|
|
|
? "CreateOffer"
|
|
|
|
|
: "CreateAnswer") +
|
|
|
|
|
reason);
|
|
|
|
|
create_session_description_requests_.pop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 07:18:04 +00:00
|
|
|
void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed(
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
|
|
|
|
const std::string& error) {
|
2018-05-24 10:53:49 +02:00
|
|
|
CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(
|
|
|
|
|
observer, RTCError(RTCErrorType::INTERNAL_ERROR, std::string(error)));
|
2016-06-10 14:17:27 -07:00
|
|
|
signaling_thread_->Post(RTC_FROM_HERE, this,
|
|
|
|
|
MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg);
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << "Create SDP failed: " << error;
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded(
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
2017-12-07 10:27:41 -08:00
|
|
|
std::unique_ptr<SessionDescriptionInterface> description) {
|
2018-05-24 10:53:49 +02:00
|
|
|
CreateSessionDescriptionMsg* msg =
|
|
|
|
|
new CreateSessionDescriptionMsg(observer, RTCError::OK());
|
2017-12-07 10:27:41 -08:00
|
|
|
msg->description = std::move(description);
|
2016-06-10 14:17:27 -07:00
|
|
|
signaling_thread_->Post(RTC_FROM_HERE, this,
|
|
|
|
|
MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg);
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
Replacing DtlsIdentityStoreInterface with RTCCertificateGeneratorInterface.
The store was used in WebRtcSessionDescriptionFactory to generate certificates,
now a generator is used instead (new API). PeerConnection[Factory][Interface],
and WebRtcSession are updated to pass generators all the way down to the
WebRtcSessionDescriptionFactory instead of stores.
The webrtc implementation of a generator, RTCCertificateGenerator, is used as
the default generator (peerconnectionfactory.cc:189) instead of the webrtc
implementation of a store, DtlsIdentityStoreImpl.
The generator is fully parameterized and does not generate RSA-1024 unless you
ask for it (which makes sense not to do beforehand since ECDSA is now default).
The store was not fully parameterized (known filed bug).
The "top" layer, PeerConnectionFactoryInterface::CreatePeerConneciton, is
updated to take a generator instead of a store.
Many unittests still use a store, to allow them to continue to do so the
factory gets CreatePeerConnectionWithStore which uses the old function
signature (and invokes the new signature by wrapping the store in an
RTCCertificateGeneratorStoreWrapper). As soon as the FakeDtlsIdentityStore is
turned into a certificate generator instead of a store, the unittests will be
updated and we can remove CreatePeerConnectionWithStore.
This is a reupload of https://codereview.webrtc.org/2013523002/ with minor
changes.
BUG=webrtc:5707, webrtc:5708
R=tommi@webrtc.org
Review URL: https://codereview.webrtc.org/2017943002 .
Cr-Commit-Position: refs/heads/master@{#12984}
2016-06-01 11:44:18 +02:00
|
|
|
void WebRtcSessionDescriptionFactory::OnCertificateRequestFailed() {
|
2017-01-12 05:15:36 -08:00
|
|
|
RTC_DCHECK(signaling_thread_->IsCurrent());
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << "Asynchronous certificate generation request failed.";
|
2015-08-25 09:53:21 +02:00
|
|
|
certificate_request_state_ = CERTIFICATE_FAILED;
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2015-07-09 03:25:02 -07:00
|
|
|
FailPendingRequests(kFailedDueToIdentityFailed);
|
2013-08-10 07:18:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-08-27 10:12:24 +02:00
|
|
|
void WebRtcSessionDescriptionFactory::SetCertificate(
|
|
|
|
|
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(certificate);
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_VERBOSE) << "Setting new certificate.";
|
2015-03-04 22:17:38 +00:00
|
|
|
|
2015-08-25 09:53:21 +02:00
|
|
|
certificate_request_state_ = CERTIFICATE_SUCCEEDED;
|
2015-08-27 10:12:24 +02:00
|
|
|
SignalCertificateReady(certificate);
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2015-08-31 09:27:58 +02:00
|
|
|
transport_desc_factory_.set_certificate(certificate);
|
2013-08-10 07:18:04 +00:00
|
|
|
transport_desc_factory_.set_secure(cricket::SEC_ENABLED);
|
|
|
|
|
|
|
|
|
|
while (!create_session_description_requests_.empty()) {
|
|
|
|
|
if (create_session_description_requests_.front().type ==
|
|
|
|
|
CreateSessionDescriptionRequest::kOffer) {
|
|
|
|
|
InternalCreateOffer(create_session_description_requests_.front());
|
|
|
|
|
} else {
|
|
|
|
|
InternalCreateAnswer(create_session_description_requests_.front());
|
|
|
|
|
}
|
|
|
|
|
create_session_description_requests_.pop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // namespace webrtc
|