• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2019 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 API_PACKET_SOCKET_FACTORY_H_
12 #define API_PACKET_SOCKET_FACTORY_H_
13 
14 #include <string>
15 #include <vector>
16 
17 #include "rtc_base/async_packet_socket.h"
18 #include "rtc_base/proxy_info.h"
19 #include "rtc_base/system/rtc_export.h"
20 
21 namespace rtc {
22 
23 class SSLCertificateVerifier;
24 class AsyncResolverInterface;
25 
26 struct PacketSocketTcpOptions {
27   PacketSocketTcpOptions() = default;
28   ~PacketSocketTcpOptions() = default;
29 
30   int opts = 0;
31   std::vector<std::string> tls_alpn_protocols;
32   std::vector<std::string> tls_elliptic_curves;
33   // An optional custom SSL certificate verifier that an API user can provide to
34   // inject their own certificate verification logic (not available to users
35   // outside of the WebRTC repo).
36   SSLCertificateVerifier* tls_cert_verifier = nullptr;
37 };
38 
39 class RTC_EXPORT PacketSocketFactory {
40  public:
41   enum Options {
42     OPT_STUN = 0x04,
43 
44     // The TLS options below are mutually exclusive.
45     OPT_TLS = 0x02,           // Real and secure TLS.
46     OPT_TLS_FAKE = 0x01,      // Fake TLS with a dummy SSL handshake.
47     OPT_TLS_INSECURE = 0x08,  // Insecure TLS without certificate validation.
48 
49     // Deprecated, use OPT_TLS_FAKE.
50     OPT_SSLTCP = OPT_TLS_FAKE,
51   };
52 
53   PacketSocketFactory() = default;
54   virtual ~PacketSocketFactory() = default;
55 
56   virtual AsyncPacketSocket* CreateUdpSocket(const SocketAddress& address,
57                                              uint16_t min_port,
58                                              uint16_t max_port) = 0;
59   virtual AsyncPacketSocket* CreateServerTcpSocket(
60       const SocketAddress& local_address,
61       uint16_t min_port,
62       uint16_t max_port,
63       int opts) = 0;
64 
65   virtual AsyncPacketSocket* CreateClientTcpSocket(
66       const SocketAddress& local_address,
67       const SocketAddress& remote_address,
68       const ProxyInfo& proxy_info,
69       const std::string& user_agent,
70       const PacketSocketTcpOptions& tcp_options) = 0;
71 
72   virtual AsyncResolverInterface* CreateAsyncResolver() = 0;
73 
74  private:
75   PacketSocketFactory(const PacketSocketFactory&) = delete;
76   PacketSocketFactory& operator=(const PacketSocketFactory&) = delete;
77 };
78 
79 }  // namespace rtc
80 
81 #endif  // API_PACKET_SOCKET_FACTORY_H_
82