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
|
|
|
#ifndef PC_WEBRTC_SESSION_DESCRIPTION_FACTORY_H_
|
|
|
|
|
#define PC_WEBRTC_SESSION_DESCRIPTION_FACTORY_H_
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stdint.h>
|
2021-01-29 14:45:08 +00:00
|
|
|
|
|
|
|
|
#include <functional>
|
2016-04-26 03:13:22 -07:00
|
|
|
#include <memory>
|
2017-10-30 09:57:42 -07:00
|
|
|
#include <queue>
|
|
|
|
|
#include <string>
|
2016-04-26 03:13:22 -07:00
|
|
|
|
2022-08-22 19:45:43 +02:00
|
|
|
#include "absl/functional/any_invocable.h"
|
2024-09-16 20:28:14 +00:00
|
|
|
#include "api/field_trials_view.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/jsep.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "api/peer_connection_interface.h"
|
2024-09-16 20:28:14 +00:00
|
|
|
#include "api/rtc_error.h"
|
2019-01-25 20:26:48 +01:00
|
|
|
#include "api/scoped_refptr.h"
|
2022-08-22 19:45:43 +02:00
|
|
|
#include "api/task_queue/task_queue_base.h"
|
2024-09-16 20:28:14 +00:00
|
|
|
#include "call/payload_type.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "p2p/base/transport_description_factory.h"
|
|
|
|
|
#include "pc/media_session.h"
|
2020-10-23 13:30:46 +00:00
|
|
|
#include "pc/sdp_state_provider.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/rtc_certificate.h"
|
|
|
|
|
#include "rtc_base/rtc_certificate_generator.h"
|
2022-08-19 14:03:54 +02:00
|
|
|
#include "rtc_base/weak_ptr.h"
|
2013-08-10 07:18:04 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
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
|
|
|
// This class is used to create offer/answer session description. Certificates
|
|
|
|
|
// for WebRtcSession/DTLS are either supplied at construction or generated
|
|
|
|
|
// asynchronously. It queues the create offer/answer request until the
|
|
|
|
|
// certificate generation has completed, i.e. when OnCertificateRequestFailed or
|
|
|
|
|
// OnCertificateReady is called.
|
2022-08-22 19:45:43 +02:00
|
|
|
class WebRtcSessionDescriptionFactory {
|
2013-08-10 07:18:04 +00:00
|
|
|
public:
|
2021-07-30 22:30:23 +02:00
|
|
|
// Can specify either a `cert_generator` or `certificate` to enable DTLS. If
|
2017-10-23 14:49:26 -07:00
|
|
|
// a certificate generator is given, starts generating the certificate
|
|
|
|
|
// asynchronously. If a certificate is given, will use that for identifying
|
|
|
|
|
// over DTLS. If neither is specified, DTLS is disabled.
|
2013-08-10 07:18:04 +00:00
|
|
|
WebRtcSessionDescriptionFactory(
|
2022-03-09 09:28:10 +01:00
|
|
|
ConnectionContext* context,
|
2020-10-23 13:30:46 +00:00
|
|
|
const SdpStateProvider* sdp_info,
|
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
|
|
|
const std::string& session_id,
|
2020-10-21 08:59:22 +00:00
|
|
|
bool dtls_enabled,
|
2017-10-23 14:49:26 -07:00
|
|
|
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
|
2022-08-22 16:39:34 +02:00
|
|
|
rtc::scoped_refptr<rtc::RTCCertificate> certificate,
|
2020-11-09 14:15:00 +00:00
|
|
|
std::function<void(const rtc::scoped_refptr<rtc::RTCCertificate>&)>
|
2022-04-19 17:24:10 +02:00
|
|
|
on_certificate_ready,
|
2024-09-16 20:28:14 +00:00
|
|
|
PayloadTypeSuggester* pt_suggester,
|
2022-04-19 17:24:10 +02:00
|
|
|
const FieldTrialsView& field_trials);
|
2022-08-22 19:45:43 +02:00
|
|
|
~WebRtcSessionDescriptionFactory();
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2022-01-18 09:35:48 +09:00
|
|
|
WebRtcSessionDescriptionFactory(const WebRtcSessionDescriptionFactory&) =
|
|
|
|
|
delete;
|
|
|
|
|
WebRtcSessionDescriptionFactory& operator=(
|
|
|
|
|
const WebRtcSessionDescriptionFactory&) = delete;
|
|
|
|
|
|
2013-08-10 07:18:04 +00:00
|
|
|
static void CopyCandidatesFromSessionDescription(
|
2016-02-23 17:24:52 -08:00
|
|
|
const SessionDescriptionInterface* source_desc,
|
|
|
|
|
const std::string& content_name,
|
|
|
|
|
SessionDescriptionInterface* dest_desc);
|
2013-08-10 07:18:04 +00:00
|
|
|
|
|
|
|
|
void CreateOffer(
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
2015-10-14 11:33:11 -07:00
|
|
|
const PeerConnectionInterface::RTCOfferAnswerOptions& options,
|
|
|
|
|
const cricket::MediaSessionOptions& session_options);
|
|
|
|
|
void CreateAnswer(CreateSessionDescriptionObserver* observer,
|
|
|
|
|
const cricket::MediaSessionOptions& session_options);
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2017-06-29 12:31:36 -07:00
|
|
|
void set_enable_encrypted_rtp_header_extensions(bool enable) {
|
|
|
|
|
session_desc_factory_.set_enable_encrypted_rtp_header_extensions(enable);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-10 16:08:05 -08:00
|
|
|
void set_is_unified_plan(bool is_unified_plan) {
|
|
|
|
|
session_desc_factory_.set_is_unified_plan(is_unified_plan);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 07:18:04 +00:00
|
|
|
// For testing.
|
2015-08-25 09:53:21 +02:00
|
|
|
bool waiting_for_certificate_for_testing() const {
|
|
|
|
|
return certificate_request_state_ == CERTIFICATE_WAITING;
|
2013-11-20 21:49:41 +00:00
|
|
|
}
|
2024-02-08 13:15:51 +00:00
|
|
|
void SetInsecureForTesting() {
|
|
|
|
|
transport_desc_factory_.SetInsecureForTesting();
|
|
|
|
|
}
|
2013-08-10 07:18:04 +00:00
|
|
|
|
|
|
|
|
private:
|
2015-08-25 09:53:21 +02:00
|
|
|
enum CertificateRequestState {
|
|
|
|
|
CERTIFICATE_NOT_NEEDED,
|
|
|
|
|
CERTIFICATE_WAITING,
|
|
|
|
|
CERTIFICATE_SUCCEEDED,
|
|
|
|
|
CERTIFICATE_FAILED,
|
2013-08-10 07:18:04 +00:00
|
|
|
};
|
|
|
|
|
|
2022-08-19 14:03:54 +02:00
|
|
|
struct CreateSessionDescriptionRequest {
|
|
|
|
|
enum Type {
|
|
|
|
|
kOffer,
|
|
|
|
|
kAnswer,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CreateSessionDescriptionRequest(Type type,
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
|
|
|
|
const cricket::MediaSessionOptions& options)
|
|
|
|
|
: type(type), observer(observer), options(options) {}
|
|
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
|
rtc::scoped_refptr<CreateSessionDescriptionObserver> observer;
|
|
|
|
|
cricket::MediaSessionOptions options;
|
|
|
|
|
};
|
|
|
|
|
|
2013-08-10 07:18:04 +00:00
|
|
|
void InternalCreateOffer(CreateSessionDescriptionRequest request);
|
|
|
|
|
void InternalCreateAnswer(CreateSessionDescriptionRequest request);
|
2015-07-09 03:25:02 -07:00
|
|
|
// Posts failure notifications for all pending session description requests.
|
|
|
|
|
void FailPendingRequests(const std::string& reason);
|
2013-08-10 07:18:04 +00:00
|
|
|
void PostCreateSessionDescriptionFailed(
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
2023-09-18 13:06:24 +02:00
|
|
|
RTCError error);
|
2013-08-10 07:18:04 +00:00
|
|
|
void PostCreateSessionDescriptionSucceeded(
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
2017-12-07 10:27:41 -08:00
|
|
|
std::unique_ptr<SessionDescriptionInterface> description);
|
2022-08-22 19:45:43 +02:00
|
|
|
// Posts `callback` to `signaling_thread_`, and ensures it will be called no
|
|
|
|
|
// later than in the destructor.
|
|
|
|
|
void Post(absl::AnyInvocable<void() &&> callback);
|
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 OnCertificateRequestFailed();
|
2022-08-22 16:39:34 +02:00
|
|
|
void SetCertificate(rtc::scoped_refptr<rtc::RTCCertificate> certificate);
|
2013-08-10 07:18:04 +00:00
|
|
|
|
|
|
|
|
std::queue<CreateSessionDescriptionRequest>
|
|
|
|
|
create_session_description_requests_;
|
2022-08-22 19:45:43 +02:00
|
|
|
TaskQueueBase* const signaling_thread_;
|
2013-08-10 07:18:04 +00:00
|
|
|
cricket::TransportDescriptionFactory transport_desc_factory_;
|
|
|
|
|
cricket::MediaSessionDescriptionFactory session_desc_factory_;
|
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
|
|
|
uint64_t session_version_;
|
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
|
|
|
const std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator_;
|
2020-10-23 13:30:46 +00:00
|
|
|
const SdpStateProvider* sdp_info_;
|
2015-07-09 03:25:02 -07:00
|
|
|
const std::string session_id_;
|
2015-08-25 09:53:21 +02:00
|
|
|
CertificateRequestState certificate_request_state_;
|
2022-08-22 19:45:43 +02:00
|
|
|
std::queue<absl::AnyInvocable<void() &&>> callbacks_;
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2020-11-09 14:15:00 +00:00
|
|
|
std::function<void(const rtc::scoped_refptr<rtc::RTCCertificate>&)>
|
|
|
|
|
on_certificate_ready_;
|
2024-02-08 13:15:51 +00:00
|
|
|
|
2022-08-19 14:03:54 +02:00
|
|
|
rtc::WeakPtrFactory<WebRtcSessionDescriptionFactory> weak_factory_{this};
|
2013-08-10 07:18:04 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2019-01-11 09:11:00 -08:00
|
|
|
#endif // PC_WEBRTC_SESSION_DESCRIPTION_FACTORY_H_
|