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
|
|
|
*/
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "pc/webrtc_session_description_factory.h"
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stddef.h>
|
2020-10-21 08:59:22 +00:00
|
|
|
#include <algorithm>
|
2019-09-17 17:06:18 +02:00
|
|
|
#include <memory>
|
2017-10-30 09:57:42 -07:00
|
|
|
#include <string>
|
2020-10-23 13:30:46 +00:00
|
|
|
#include <type_traits>
|
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
|
|
|
|
2019-01-28 17:25:26 -08:00
|
|
|
#include "absl/algorithm/container.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "absl/types/optional.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/jsep.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "api/jsep_session_description.h"
|
|
|
|
|
#include "api/rtc_error.h"
|
2020-10-23 13:30:46 +00:00
|
|
|
#include "pc/sdp_state_provider.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "pc/session_description.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/location.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/ref_counted_object.h"
|
|
|
|
|
#include "rtc_base/ssl_identity.h"
|
|
|
|
|
#include "rtc_base/ssl_stream_adapter.h"
|
|
|
|
|
#include "rtc_base/string_encode.h"
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2013-11-20 21:49:41 +00:00
|
|
|
using cricket::MediaSessionOptions;
|
2019-01-25 17:13:56 -08:00
|
|
|
using rtc::UniqueRandomIdGenerator;
|
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
|
|
|
// 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());
|
|
|
|
|
}
|
2019-01-28 17:25:26 -08:00
|
|
|
absl::c_sort(sorted_senders, [](const cricket::SenderOptions& sender1,
|
|
|
|
|
const cricket::SenderOptions& sender2) {
|
|
|
|
|
return sender1.track_id < sender2.track_id;
|
|
|
|
|
});
|
|
|
|
|
return absl::c_adjacent_find(sorted_senders,
|
|
|
|
|
[](const cricket::SenderOptions& sender1,
|
|
|
|
|
const cricket::SenderOptions& sender2) {
|
|
|
|
|
return sender1.track_id == sender2.track_id;
|
|
|
|
|
}) == 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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
2020-10-23 13:30:46 +00:00
|
|
|
const SdpStateProvider* sdp_info,
|
2013-08-10 07:18:04 +00:00
|
|
|
const std::string& session_id,
|
2020-10-21 08:59:22 +00:00
|
|
|
bool dtls_enabled,
|
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,
|
2019-01-25 17:13:56 -08:00
|
|
|
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate,
|
2020-11-09 14:15:00 +00:00
|
|
|
UniqueRandomIdGenerator* ssrc_generator,
|
|
|
|
|
std::function<void(const rtc::scoped_refptr<rtc::RTCCertificate>&)>
|
|
|
|
|
on_certificate_ready)
|
2020-09-24 22:39:21 +02:00
|
|
|
: signaling_thread_(signaling_thread),
|
2019-01-25 17:13:56 -08:00
|
|
|
session_desc_factory_(channel_manager,
|
|
|
|
|
&transport_desc_factory_,
|
|
|
|
|
ssrc_generator),
|
2013-08-10 07:18:04 +00:00
|
|
|
// 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
|
2021-07-27 22:09:55 +00:00
|
|
|
// |kInitSessionVersion|.
|
2013-08-10 07:18:04 +00:00
|
|
|
session_version_(kInitSessionVersion),
|
2020-10-21 08:59:22 +00:00
|
|
|
cert_generator_(dtls_enabled ? std::move(cert_generator) : nullptr),
|
2020-10-23 13:30:46 +00:00
|
|
|
sdp_info_(sdp_info),
|
2013-08-10 07:18:04 +00:00
|
|
|
session_id_(session_id),
|
2020-11-09 14:15:00 +00:00
|
|
|
certificate_request_state_(CERTIFICATE_NOT_NEEDED),
|
|
|
|
|
on_certificate_ready_(on_certificate_ready) {
|
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_);
|
2020-10-21 08:59:22 +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 (!dtls_enabled) {
|
2020-10-21 08:59:22 +00:00
|
|
|
SetSdesPolicy(cricket::SEC_REQUIRED);
|
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
|
|
|
|
2020-10-21 08:59:22 +00:00
|
|
|
// SRTP-SDES is disabled if DTLS is on.
|
|
|
|
|
SetSdesPolicy(cricket::SEC_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
|
|
|
if (certificate) {
|
2021-07-27 22:09:55 +00:00
|
|
|
// Use |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
|
|
|
certificate_request_state_ = CERTIFICATE_WAITING;
|
|
|
|
|
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_VERBOSE) << "DTLS-SRTP enabled; has certificate parameter.";
|
2021-07-27 22:09:55 +00:00
|
|
|
// We already have a certificate but we wait to do |SetIdentity|; if we do
|
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
|
|
|
// it in the constructor then the caller has not had a chance to connect to
|
2021-07-27 22:09:55 +00:00
|
|
|
// |SignalCertificateReady|.
|
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
|
|
|
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;
|
|
|
|
|
|
2021-04-27 14:43:08 +02:00
|
|
|
auto callback = rtc::make_ref_counted<WebRtcCertificateGeneratorCallback>();
|
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
|
|
|
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
|
2021-07-27 22:09:55 +00:00
|
|
|
// 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() {
|
2021-02-04 10:22:50 +01:00
|
|
|
RTC_DCHECK_RUN_ON(signaling_thread_);
|
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) {
|
2021-02-04 10:22:50 +01:00
|
|
|
RTC_DCHECK_RUN_ON(signaling_thread_);
|
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;
|
|
|
|
|
}
|
2020-10-23 13:30:46 +00:00
|
|
|
if (!sdp_info_->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;
|
|
|
|
|
}
|
2020-10-23 13:30:46 +00:00
|
|
|
if (sdp_info_->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) {
|
2020-10-23 13:30:46 +00:00
|
|
|
if (sdp_info_->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) {
|
2020-10-23 13:30:46 +00:00
|
|
|
if (sdp_info_->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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-11 10:15:23 -08:00
|
|
|
std::unique_ptr<cricket::SessionDescription> desc =
|
|
|
|
|
session_desc_factory_.CreateOffer(
|
2020-10-23 13:30:46 +00:00
|
|
|
request.options, sdp_info_->local_description()
|
|
|
|
|
? sdp_info_->local_description()->description()
|
|
|
|
|
: nullptr);
|
2018-12-11 10:15:23 -08:00
|
|
|
if (!desc) {
|
|
|
|
|
PostCreateSessionDescriptionFailed(request.observer,
|
|
|
|
|
"Failed to initialize the offer.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
2021-07-27 22:09:55 +00: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_);
|
2019-09-17 17:06:18 +02:00
|
|
|
auto offer = std::make_unique<JsepSessionDescription>(
|
2018-12-11 10:15:23 -08:00
|
|
|
SdpType::kOffer, std::move(desc), session_id_,
|
|
|
|
|
rtc::ToString(session_version_++));
|
2020-10-23 13:30:46 +00:00
|
|
|
if (sdp_info_->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) {
|
2020-10-23 13:30:46 +00:00
|
|
|
CopyCandidatesFromSessionDescription(sdp_info_->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) {
|
2020-10-23 13:30:46 +00:00
|
|
|
if (sdp_info_->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 =
|
2020-10-23 13:30:46 +00:00
|
|
|
sdp_info_->IceRestartPending(options.mid);
|
2020-10-21 08:59:22 +00:00
|
|
|
// We should pass the current DTLS role to the transport description
|
2016-02-23 17:24:52 -08:00
|
|
|
// factory, if there is already an existing ongoing session.
|
2020-10-21 08:59:22 +00:00
|
|
|
absl::optional<rtc::SSLRole> dtls_role =
|
2020-10-23 13:30:46 +00:00
|
|
|
sdp_info_->GetDtlsRole(options.mid);
|
2020-10-21 08:59:22 +00:00
|
|
|
if (dtls_role) {
|
2017-08-17 14:10:50 -07:00
|
|
|
options.transport_options.prefer_passive_role =
|
2020-10-21 08:59:22 +00:00
|
|
|
(rtc::SSL_SERVER == *dtls_role);
|
2016-02-23 17:24:52 -08:00
|
|
|
}
|
|
|
|
|
}
|
2013-08-23 23:21:25 +00:00
|
|
|
}
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2018-12-11 10:15:23 -08:00
|
|
|
std::unique_ptr<cricket::SessionDescription> desc =
|
|
|
|
|
session_desc_factory_.CreateAnswer(
|
2020-10-23 13:30:46 +00:00
|
|
|
sdp_info_->remote_description()
|
|
|
|
|
? sdp_info_->remote_description()->description()
|
2020-10-21 08:59:22 +00:00
|
|
|
: nullptr,
|
2018-12-11 10:15:23 -08:00
|
|
|
request.options,
|
2020-10-23 13:30:46 +00:00
|
|
|
sdp_info_->local_description()
|
|
|
|
|
? sdp_info_->local_description()->description()
|
2020-10-21 08:59:22 +00:00
|
|
|
: nullptr);
|
2018-12-11 10:15:23 -08:00
|
|
|
if (!desc) {
|
|
|
|
|
PostCreateSessionDescriptionFailed(request.observer,
|
|
|
|
|
"Failed to initialize the answer.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
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.
|
2021-07-27 22:09:55 +00:00
|
|
|
// Get a new version number by increasing the |session_version_answer_|.
|
|
|
|
|
// 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_);
|
2019-09-17 17:06:18 +02:00
|
|
|
auto answer = std::make_unique<JsepSessionDescription>(
|
2018-12-11 10:15:23 -08:00
|
|
|
SdpType::kAnswer, std::move(desc), session_id_,
|
|
|
|
|
rtc::ToString(session_version_++));
|
2020-10-23 13:30:46 +00:00
|
|
|
if (sdp_info_->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) {
|
2020-10-23 13:30:46 +00:00
|
|
|
CopyCandidatesFromSessionDescription(sdp_info_->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) {
|
2021-02-04 10:22:50 +01:00
|
|
|
RTC_DCHECK_RUN_ON(signaling_thread_);
|
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() {
|
2021-02-04 10:22:50 +01:00
|
|
|
RTC_DCHECK_RUN_ON(signaling_thread_);
|
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;
|
2020-11-09 14:15:00 +00:00
|
|
|
|
|
|
|
|
on_certificate_ready_(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
|