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
|
|
|
#ifndef PC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
|
|
|
|
|
#define PC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
|
2013-08-10 07:18:04 +00:00
|
|
|
|
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
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "p2p/base/transportdescriptionfactory.h"
|
|
|
|
|
#include "pc/mediasession.h"
|
2018-01-23 16:38:46 -08:00
|
|
|
#include "pc/peerconnectioninternal.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/constructormagic.h"
|
|
|
|
|
#include "rtc_base/messagehandler.h"
|
|
|
|
|
#include "rtc_base/rtccertificate.h"
|
|
|
|
|
#include "rtc_base/rtccertificategenerator.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
|
|
|
// DTLS certificate request callback class.
|
|
|
|
|
class WebRtcCertificateGeneratorCallback
|
|
|
|
|
: public rtc::RTCCertificateGeneratorCallback,
|
|
|
|
|
public sigslot::has_slots<> {
|
2013-08-10 07:18:04 +00:00
|
|
|
public:
|
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::RTCCertificateGeneratorCallback| overrides.
|
|
|
|
|
void OnSuccess(
|
|
|
|
|
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override;
|
|
|
|
|
void OnFailure() override;
|
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
|
|
|
sigslot::signal0<> SignalRequestFailed;
|
2015-08-27 10:12:24 +02:00
|
|
|
sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&>
|
|
|
|
|
SignalCertificateReady;
|
2013-08-10 07:18:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct CreateSessionDescriptionRequest {
|
|
|
|
|
enum Type {
|
|
|
|
|
kOffer,
|
|
|
|
|
kAnswer,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CreateSessionDescriptionRequest(Type type,
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
|
|
|
|
const cricket::MediaSessionOptions& options)
|
|
|
|
|
: type(type), observer(observer), options(options) {}
|
|
|
|
|
|
|
|
|
|
Type type;
|
2014-07-29 17:36:52 +00:00
|
|
|
rtc::scoped_refptr<CreateSessionDescriptionObserver> observer;
|
2013-08-10 07:18:04 +00:00
|
|
|
cricket::MediaSessionOptions options;
|
|
|
|
|
};
|
|
|
|
|
|
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.
|
2014-07-29 17:36:52 +00:00
|
|
|
class WebRtcSessionDescriptionFactory : public rtc::MessageHandler,
|
2015-08-11 10:33:13 +02:00
|
|
|
public sigslot::has_slots<> {
|
2013-08-10 07:18:04 +00:00
|
|
|
public:
|
2017-10-23 14:49:26 -07:00
|
|
|
// Can specify either a |cert_generator| or |certificate| to enable DTLS. If
|
|
|
|
|
// 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(
|
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,
|
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,
|
2017-10-23 14:49:26 -07:00
|
|
|
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
|
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 rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
|
2013-08-10 07:18:04 +00:00
|
|
|
virtual ~WebRtcSessionDescriptionFactory();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-03-04 19:54:57 +00:00
|
|
|
void SetSdesPolicy(cricket::SecurePolicy secure_policy);
|
|
|
|
|
cricket::SecurePolicy SdesPolicy() const;
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-27 10:12:24 +02:00
|
|
|
sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&>
|
|
|
|
|
SignalCertificateReady;
|
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
|
|
|
}
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// MessageHandler implementation.
|
2014-07-29 17:36:52 +00:00
|
|
|
virtual void OnMessage(rtc::Message* msg);
|
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,
|
|
|
|
|
const std::string& error);
|
|
|
|
|
void PostCreateSessionDescriptionSucceeded(
|
|
|
|
|
CreateSessionDescriptionObserver* observer,
|
2017-12-07 10:27:41 -08:00
|
|
|
std::unique_ptr<SessionDescriptionInterface> description);
|
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();
|
2015-08-27 10:12:24 +02:00
|
|
|
void SetCertificate(
|
|
|
|
|
const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
|
2013-08-10 07:18:04 +00:00
|
|
|
|
|
|
|
|
std::queue<CreateSessionDescriptionRequest>
|
|
|
|
|
create_session_description_requests_;
|
2015-07-09 03:25:02 -07:00
|
|
|
rtc::Thread* 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_;
|
2017-10-23 14:49:26 -07:00
|
|
|
// TODO(jiayl): remove the dependency on peer connection once bug 2264 is
|
|
|
|
|
// fixed.
|
2018-01-23 16:38:46 -08:00
|
|
|
PeerConnectionInternal* const pc_;
|
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_;
|
2013-08-10 07:18:04 +00:00
|
|
|
|
2015-09-16 05:37:44 -07:00
|
|
|
RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory);
|
2013-08-10 07:18:04 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // PC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
|