dtls_transport_internal.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifndef P2P_BASE_DTLS_TRANSPORT_INTERNAL_H_
  11. #define P2P_BASE_DTLS_TRANSPORT_INTERNAL_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <memory>
  15. #include <string>
  16. #include "api/crypto/crypto_options.h"
  17. #include "api/dtls_transport_interface.h"
  18. #include "api/scoped_refptr.h"
  19. #include "p2p/base/ice_transport_internal.h"
  20. #include "p2p/base/packet_transport_internal.h"
  21. #include "rtc_base/constructor_magic.h"
  22. #include "rtc_base/ssl_certificate.h"
  23. #include "rtc_base/ssl_fingerprint.h"
  24. #include "rtc_base/ssl_stream_adapter.h"
  25. #include "rtc_base/third_party/sigslot/sigslot.h"
  26. namespace cricket {
  27. enum DtlsTransportState {
  28. // Haven't started negotiating.
  29. DTLS_TRANSPORT_NEW = 0,
  30. // Have started negotiating.
  31. DTLS_TRANSPORT_CONNECTING,
  32. // Negotiated, and has a secure connection.
  33. DTLS_TRANSPORT_CONNECTED,
  34. // Transport is closed.
  35. DTLS_TRANSPORT_CLOSED,
  36. // Failed due to some error in the handshake process.
  37. DTLS_TRANSPORT_FAILED,
  38. };
  39. webrtc::DtlsTransportState ConvertDtlsTransportState(
  40. cricket::DtlsTransportState cricket_state);
  41. enum PacketFlags {
  42. PF_NORMAL = 0x00, // A normal packet.
  43. PF_SRTP_BYPASS = 0x01, // An encrypted SRTP packet; bypass any additional
  44. // crypto provided by the transport (e.g. DTLS)
  45. };
  46. // DtlsTransportInternal is an internal interface that does DTLS, also
  47. // negotiating SRTP crypto suites so that it may be used for DTLS-SRTP.
  48. //
  49. // Once the public interface is supported,
  50. // (https://www.w3.org/TR/webrtc/#rtcdtlstransport-interface)
  51. // the DtlsTransportInterface will be split from this class.
  52. class DtlsTransportInternal : public rtc::PacketTransportInternal {
  53. public:
  54. ~DtlsTransportInternal() override;
  55. virtual const webrtc::CryptoOptions& crypto_options() const = 0;
  56. virtual DtlsTransportState dtls_state() const = 0;
  57. virtual int component() const = 0;
  58. virtual bool IsDtlsActive() const = 0;
  59. virtual bool GetDtlsRole(rtc::SSLRole* role) const = 0;
  60. virtual bool SetDtlsRole(rtc::SSLRole role) = 0;
  61. // Finds out which TLS/DTLS version is running.
  62. virtual bool GetSslVersionBytes(int* version) const = 0;
  63. // Finds out which DTLS-SRTP cipher was negotiated.
  64. // TODO(zhihuang): Remove this once all dependencies implement this.
  65. virtual bool GetSrtpCryptoSuite(int* cipher) = 0;
  66. // Finds out which DTLS cipher was negotiated.
  67. // TODO(zhihuang): Remove this once all dependencies implement this.
  68. virtual bool GetSslCipherSuite(int* cipher) = 0;
  69. // Gets the local RTCCertificate used for DTLS.
  70. virtual rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate()
  71. const = 0;
  72. virtual bool SetLocalCertificate(
  73. const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) = 0;
  74. // Gets a copy of the remote side's SSL certificate chain.
  75. virtual std::unique_ptr<rtc::SSLCertChain> GetRemoteSSLCertChain() const = 0;
  76. // Allows key material to be extracted for external encryption.
  77. virtual bool ExportKeyingMaterial(const std::string& label,
  78. const uint8_t* context,
  79. size_t context_len,
  80. bool use_context,
  81. uint8_t* result,
  82. size_t result_len) = 0;
  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. virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) = 0;
  88. // Expose the underneath IceTransport.
  89. virtual IceTransportInternal* ice_transport() = 0;
  90. sigslot::signal2<DtlsTransportInternal*, DtlsTransportState> SignalDtlsState;
  91. // Emitted whenever the Dtls handshake failed on some transport channel.
  92. sigslot::signal1<rtc::SSLHandshakeError> SignalDtlsHandshakeError;
  93. protected:
  94. DtlsTransportInternal();
  95. private:
  96. RTC_DISALLOW_COPY_AND_ASSIGN(DtlsTransportInternal);
  97. };
  98. } // namespace cricket
  99. #endif // P2P_BASE_DTLS_TRANSPORT_INTERNAL_H_