blob: b77ae077bbe29666a3761daf568cd9cafa1bfe78 [file] [log] [blame]
zhihuange50658d2017-01-03 11:34:12 -08001/*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_P2P_BASE_DTLSTRANSPORTINTERNAL_H_
12#define WEBRTC_P2P_BASE_DTLSTRANSPORTINTERNAL_H_
13
14#include <memory>
15#include <string>
16#include <vector>
17
zhihuange50658d2017-01-03 11:34:12 -080018#include "webrtc/p2p/base/icetransportinternal.h"
19#include "webrtc/p2p/base/jseptransport.h"
deadbeef5bd5ca32017-02-10 11:31:50 -080020#include "webrtc/p2p/base/packettransportinternal.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020021#include "webrtc/rtc_base/sslstreamadapter.h"
22#include "webrtc/rtc_base/stringencode.h"
zhihuange50658d2017-01-03 11:34:12 -080023
24namespace cricket {
25
zhihuangb2cdd932017-01-19 16:54:25 -080026enum PacketFlags {
27 PF_NORMAL = 0x00, // A normal packet.
28 PF_SRTP_BYPASS = 0x01, // An encrypted SRTP packet; bypass any additional
29 // crypto provided by the transport (e.g. DTLS)
30};
31
deadbeef7914b8c2017-04-21 03:23:33 -070032// DtlsTransportInternal is an internal interface that does DTLS, also
33// negotiating SRTP crypto suites so that it may be used for DTLS-SRTP.
34//
zhihuange50658d2017-01-03 11:34:12 -080035// Once the public interface is supported,
36// (https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface)
37// the DtlsTransportInterface will be split from this class.
deadbeef5bd5ca32017-02-10 11:31:50 -080038class DtlsTransportInternal : public rtc::PacketTransportInternal {
zhihuange50658d2017-01-03 11:34:12 -080039 public:
40 virtual ~DtlsTransportInternal() {}
41
jbauch5869f502017-06-29 12:31:36 -070042 virtual const rtc::CryptoOptions& crypto_options() const = 0;
43
zhihuange50658d2017-01-03 11:34:12 -080044 virtual DtlsTransportState dtls_state() const = 0;
45
46 virtual const std::string& transport_name() const = 0;
47
48 virtual int component() const = 0;
49
50 virtual bool IsDtlsActive() const = 0;
51
52 virtual bool GetSslRole(rtc::SSLRole* role) const = 0;
53
54 virtual bool SetSslRole(rtc::SSLRole role) = 0;
55
zhihuange50658d2017-01-03 11:34:12 -080056 // Finds out which DTLS-SRTP cipher was negotiated.
57 // TODO(zhihuang): Remove this once all dependencies implement this.
58 virtual bool GetSrtpCryptoSuite(int* cipher) = 0;
59
60 // Finds out which DTLS cipher was negotiated.
61 // TODO(zhihuang): Remove this once all dependencies implement this.
62 virtual bool GetSslCipherSuite(int* cipher) = 0;
63
64 // Gets the local RTCCertificate used for DTLS.
65 virtual rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate()
66 const = 0;
67
68 virtual bool SetLocalCertificate(
69 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) = 0;
70
71 // Gets a copy of the remote side's SSL certificate.
72 virtual std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate()
73 const = 0;
74
75 // Allows key material to be extracted for external encryption.
76 virtual bool ExportKeyingMaterial(const std::string& label,
77 const uint8_t* context,
78 size_t context_len,
79 bool use_context,
80 uint8_t* result,
81 size_t result_len) = 0;
82
83 // Set DTLS remote fingerprint. Must be after local identity set.
84 virtual bool SetRemoteFingerprint(const std::string& digest_alg,
85 const uint8_t* digest,
86 size_t digest_len) = 0;
87
88 // Expose the underneath IceTransport.
89 virtual IceTransportInternal* ice_transport() = 0;
90
91 sigslot::signal2<DtlsTransportInternal*, DtlsTransportState> SignalDtlsState;
92
93 // Emitted whenever the Dtls handshake failed on some transport channel.
94 sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
95
96 // Debugging description of this transport.
97 std::string debug_name() const override {
deadbeefdbeeb702017-02-16 11:10:51 -080098 return transport_name() + " " + rtc::ToString(component());
zhihuange50658d2017-01-03 11:34:12 -080099 }
100
zhihuangb2cdd932017-01-19 16:54:25 -0800101 protected:
102 DtlsTransportInternal() {}
103
zhihuange50658d2017-01-03 11:34:12 -0800104 private:
105 RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportInternal);
106};
107
108} // namespace cricket
109
110#endif // WEBRTC_P2P_BASE_DTLSTRANSPORTINTERNAL_H_