zhihuang | e50658d | 2017-01-03 11:34:12 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
zhihuang | e50658d | 2017-01-03 11:34:12 -0800 | [diff] [blame] | 18 | #include "webrtc/p2p/base/icetransportinternal.h" |
| 19 | #include "webrtc/p2p/base/jseptransport.h" |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 20 | #include "webrtc/p2p/base/packettransportinternal.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 21 | #include "webrtc/rtc_base/sslstreamadapter.h" |
| 22 | #include "webrtc/rtc_base/stringencode.h" |
zhihuang | e50658d | 2017-01-03 11:34:12 -0800 | [diff] [blame] | 23 | |
| 24 | namespace cricket { |
| 25 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 26 | enum 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 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 32 | // DtlsTransportInternal is an internal interface that does DTLS, also |
| 33 | // negotiating SRTP crypto suites so that it may be used for DTLS-SRTP. |
| 34 | // |
zhihuang | e50658d | 2017-01-03 11:34:12 -0800 | [diff] [blame] | 35 | // Once the public interface is supported, |
| 36 | // (https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface) |
| 37 | // the DtlsTransportInterface will be split from this class. |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 38 | class DtlsTransportInternal : public rtc::PacketTransportInternal { |
zhihuang | e50658d | 2017-01-03 11:34:12 -0800 | [diff] [blame] | 39 | public: |
| 40 | virtual ~DtlsTransportInternal() {} |
| 41 | |
jbauch | 5869f50 | 2017-06-29 12:31:36 -0700 | [diff] [blame] | 42 | virtual const rtc::CryptoOptions& crypto_options() const = 0; |
| 43 | |
zhihuang | e50658d | 2017-01-03 11:34:12 -0800 | [diff] [blame] | 44 | 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 | |
zhihuang | e50658d | 2017-01-03 11:34:12 -0800 | [diff] [blame] | 56 | // 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 { |
deadbeef | dbeeb70 | 2017-02-16 11:10:51 -0800 | [diff] [blame] | 98 | return transport_name() + " " + rtc::ToString(component()); |
zhihuang | e50658d | 2017-01-03 11:34:12 -0800 | [diff] [blame] | 99 | } |
| 100 | |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 101 | protected: |
| 102 | DtlsTransportInternal() {} |
| 103 | |
zhihuang | e50658d | 2017-01-03 11:34:12 -0800 | [diff] [blame] | 104 | private: |
| 105 | RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportInternal); |
| 106 | }; |
| 107 | |
| 108 | } // namespace cricket |
| 109 | |
| 110 | #endif // WEBRTC_P2P_BASE_DTLSTRANSPORTINTERNAL_H_ |