xref: /aosp_15_r20/external/webrtc/rtc_base/ssl_stream_adapter.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #ifndef RTC_BASE_SSL_STREAM_ADAPTER_H_
12*d9f75844SAndroid Build Coastguard Worker #define RTC_BASE_SSL_STREAM_ADAPTER_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <stddef.h>
15*d9f75844SAndroid Build Coastguard Worker #include <stdint.h>
16*d9f75844SAndroid Build Coastguard Worker 
17*d9f75844SAndroid Build Coastguard Worker #include <memory>
18*d9f75844SAndroid Build Coastguard Worker #include <string>
19*d9f75844SAndroid Build Coastguard Worker #include <vector>
20*d9f75844SAndroid Build Coastguard Worker 
21*d9f75844SAndroid Build Coastguard Worker #include "absl/memory/memory.h"
22*d9f75844SAndroid Build Coastguard Worker #include "absl/strings/string_view.h"
23*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/ssl_certificate.h"
24*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/ssl_identity.h"
25*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/stream.h"
26*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/third_party/sigslot/sigslot.h"
27*d9f75844SAndroid Build Coastguard Worker 
28*d9f75844SAndroid Build Coastguard Worker namespace rtc {
29*d9f75844SAndroid Build Coastguard Worker 
30*d9f75844SAndroid Build Coastguard Worker // Constants for SSL profile.
31*d9f75844SAndroid Build Coastguard Worker constexpr int kTlsNullWithNullNull = 0;
32*d9f75844SAndroid Build Coastguard Worker constexpr int kSslCipherSuiteMaxValue = 0xFFFF;
33*d9f75844SAndroid Build Coastguard Worker 
34*d9f75844SAndroid Build Coastguard Worker // Constants for SRTP profiles.
35*d9f75844SAndroid Build Coastguard Worker constexpr int kSrtpInvalidCryptoSuite = 0;
36*d9f75844SAndroid Build Coastguard Worker constexpr int kSrtpAes128CmSha1_80 = 0x0001;
37*d9f75844SAndroid Build Coastguard Worker constexpr int kSrtpAes128CmSha1_32 = 0x0002;
38*d9f75844SAndroid Build Coastguard Worker constexpr int kSrtpAeadAes128Gcm = 0x0007;
39*d9f75844SAndroid Build Coastguard Worker constexpr int kSrtpAeadAes256Gcm = 0x0008;
40*d9f75844SAndroid Build Coastguard Worker constexpr int kSrtpCryptoSuiteMaxValue = 0xFFFF;
41*d9f75844SAndroid Build Coastguard Worker 
42*d9f75844SAndroid Build Coastguard Worker // Names of SRTP profiles listed above.
43*d9f75844SAndroid Build Coastguard Worker // 128-bit AES with 80-bit SHA-1 HMAC.
44*d9f75844SAndroid Build Coastguard Worker extern const char kCsAesCm128HmacSha1_80[];
45*d9f75844SAndroid Build Coastguard Worker // 128-bit AES with 32-bit SHA-1 HMAC.
46*d9f75844SAndroid Build Coastguard Worker extern const char kCsAesCm128HmacSha1_32[];
47*d9f75844SAndroid Build Coastguard Worker // 128-bit AES GCM with 16 byte AEAD auth tag.
48*d9f75844SAndroid Build Coastguard Worker extern const char kCsAeadAes128Gcm[];
49*d9f75844SAndroid Build Coastguard Worker // 256-bit AES GCM with 16 byte AEAD auth tag.
50*d9f75844SAndroid Build Coastguard Worker extern const char kCsAeadAes256Gcm[];
51*d9f75844SAndroid Build Coastguard Worker 
52*d9f75844SAndroid Build Coastguard Worker // Given the DTLS-SRTP protection profile ID, as defined in
53*d9f75844SAndroid Build Coastguard Worker // https://tools.ietf.org/html/rfc4568#section-6.2 , return the SRTP profile
54*d9f75844SAndroid Build Coastguard Worker // name, as defined in https://tools.ietf.org/html/rfc5764#section-4.1.2.
55*d9f75844SAndroid Build Coastguard Worker std::string SrtpCryptoSuiteToName(int crypto_suite);
56*d9f75844SAndroid Build Coastguard Worker 
57*d9f75844SAndroid Build Coastguard Worker // The reverse of above conversion.
58*d9f75844SAndroid Build Coastguard Worker int SrtpCryptoSuiteFromName(absl::string_view crypto_suite);
59*d9f75844SAndroid Build Coastguard Worker 
60*d9f75844SAndroid Build Coastguard Worker // Get key length and salt length for given crypto suite. Returns true for
61*d9f75844SAndroid Build Coastguard Worker // valid suites, otherwise false.
62*d9f75844SAndroid Build Coastguard Worker bool GetSrtpKeyAndSaltLengths(int crypto_suite,
63*d9f75844SAndroid Build Coastguard Worker                               int* key_length,
64*d9f75844SAndroid Build Coastguard Worker                               int* salt_length);
65*d9f75844SAndroid Build Coastguard Worker 
66*d9f75844SAndroid Build Coastguard Worker // Returns true if the given crypto suite id uses a GCM cipher.
67*d9f75844SAndroid Build Coastguard Worker bool IsGcmCryptoSuite(int crypto_suite);
68*d9f75844SAndroid Build Coastguard Worker 
69*d9f75844SAndroid Build Coastguard Worker // Returns true if the given crypto suite name uses a GCM cipher.
70*d9f75844SAndroid Build Coastguard Worker bool IsGcmCryptoSuiteName(absl::string_view crypto_suite);
71*d9f75844SAndroid Build Coastguard Worker 
72*d9f75844SAndroid Build Coastguard Worker // SSLStreamAdapter : A StreamInterfaceAdapter that does SSL/TLS.
73*d9f75844SAndroid Build Coastguard Worker // After SSL has been started, the stream will only open on successful
74*d9f75844SAndroid Build Coastguard Worker // SSL verification of certificates, and the communication is
75*d9f75844SAndroid Build Coastguard Worker // encrypted of course.
76*d9f75844SAndroid Build Coastguard Worker //
77*d9f75844SAndroid Build Coastguard Worker // This class was written with SSLAdapter as a starting point. It
78*d9f75844SAndroid Build Coastguard Worker // offers a similar interface, with two differences: there is no
79*d9f75844SAndroid Build Coastguard Worker // support for a restartable SSL connection, and this class has a
80*d9f75844SAndroid Build Coastguard Worker // peer-to-peer mode.
81*d9f75844SAndroid Build Coastguard Worker //
82*d9f75844SAndroid Build Coastguard Worker // The SSL library requires initialization and cleanup. Static method
83*d9f75844SAndroid Build Coastguard Worker // for doing this are in SSLAdapter. They should possibly be moved out
84*d9f75844SAndroid Build Coastguard Worker // to a neutral class.
85*d9f75844SAndroid Build Coastguard Worker 
86*d9f75844SAndroid Build Coastguard Worker enum SSLRole { SSL_CLIENT, SSL_SERVER };
87*d9f75844SAndroid Build Coastguard Worker enum SSLMode { SSL_MODE_TLS, SSL_MODE_DTLS };
88*d9f75844SAndroid Build Coastguard Worker 
89*d9f75844SAndroid Build Coastguard Worker // Note: TLS_10, TLS_11, and DTLS_10 will all be ignored, and only DTLS1_2 will
90*d9f75844SAndroid Build Coastguard Worker // be accepted unless the trial flag WebRTC-LegacyTlsProtocols/Enabled/ is
91*d9f75844SAndroid Build Coastguard Worker // passed in or an explicit override is used. Support for the legacy protocol
92*d9f75844SAndroid Build Coastguard Worker // versions will be completely removed in the future.
93*d9f75844SAndroid Build Coastguard Worker // See https://bugs.webrtc.org/10261.
94*d9f75844SAndroid Build Coastguard Worker enum SSLProtocolVersion {
95*d9f75844SAndroid Build Coastguard Worker   SSL_PROTOCOL_NOT_GIVEN = -1,
96*d9f75844SAndroid Build Coastguard Worker   SSL_PROTOCOL_TLS_10 = 0,
97*d9f75844SAndroid Build Coastguard Worker   SSL_PROTOCOL_TLS_11,
98*d9f75844SAndroid Build Coastguard Worker   SSL_PROTOCOL_TLS_12,
99*d9f75844SAndroid Build Coastguard Worker   SSL_PROTOCOL_DTLS_10 = SSL_PROTOCOL_TLS_11,
100*d9f75844SAndroid Build Coastguard Worker   SSL_PROTOCOL_DTLS_12 = SSL_PROTOCOL_TLS_12,
101*d9f75844SAndroid Build Coastguard Worker };
102*d9f75844SAndroid Build Coastguard Worker enum class SSLPeerCertificateDigestError {
103*d9f75844SAndroid Build Coastguard Worker   NONE,
104*d9f75844SAndroid Build Coastguard Worker   UNKNOWN_ALGORITHM,
105*d9f75844SAndroid Build Coastguard Worker   INVALID_LENGTH,
106*d9f75844SAndroid Build Coastguard Worker   VERIFICATION_FAILED,
107*d9f75844SAndroid Build Coastguard Worker };
108*d9f75844SAndroid Build Coastguard Worker 
109*d9f75844SAndroid Build Coastguard Worker // Errors for Read -- in the high range so no conflict with OpenSSL.
110*d9f75844SAndroid Build Coastguard Worker enum { SSE_MSG_TRUNC = 0xff0001 };
111*d9f75844SAndroid Build Coastguard Worker 
112*d9f75844SAndroid Build Coastguard Worker // Used to send back UMA histogram value. Logged when Dtls handshake fails.
113*d9f75844SAndroid Build Coastguard Worker enum class SSLHandshakeError { UNKNOWN, INCOMPATIBLE_CIPHERSUITE, MAX_VALUE };
114*d9f75844SAndroid Build Coastguard Worker 
115*d9f75844SAndroid Build Coastguard Worker class SSLStreamAdapter : public StreamInterface, public sigslot::has_slots<> {
116*d9f75844SAndroid Build Coastguard Worker  public:
117*d9f75844SAndroid Build Coastguard Worker   // Instantiate an SSLStreamAdapter wrapping the given stream,
118*d9f75844SAndroid Build Coastguard Worker   // (using the selected implementation for the platform).
119*d9f75844SAndroid Build Coastguard Worker   // Caller is responsible for freeing the returned object.
120*d9f75844SAndroid Build Coastguard Worker   static std::unique_ptr<SSLStreamAdapter> Create(
121*d9f75844SAndroid Build Coastguard Worker       std::unique_ptr<StreamInterface> stream);
122*d9f75844SAndroid Build Coastguard Worker 
123*d9f75844SAndroid Build Coastguard Worker   SSLStreamAdapter() = default;
124*d9f75844SAndroid Build Coastguard Worker   ~SSLStreamAdapter() override = default;
125*d9f75844SAndroid Build Coastguard Worker 
126*d9f75844SAndroid Build Coastguard Worker   // Specify our SSL identity: key and certificate. SSLStream takes ownership
127*d9f75844SAndroid Build Coastguard Worker   // of the SSLIdentity object and will free it when appropriate. Should be
128*d9f75844SAndroid Build Coastguard Worker   // called no more than once on a given SSLStream instance.
129*d9f75844SAndroid Build Coastguard Worker   virtual void SetIdentity(std::unique_ptr<SSLIdentity> identity) = 0;
130*d9f75844SAndroid Build Coastguard Worker   virtual SSLIdentity* GetIdentityForTesting() const = 0;
131*d9f75844SAndroid Build Coastguard Worker 
132*d9f75844SAndroid Build Coastguard Worker   // Call this to indicate that we are to play the server role (or client role,
133*d9f75844SAndroid Build Coastguard Worker   // if the default argument is replaced by SSL_CLIENT).
134*d9f75844SAndroid Build Coastguard Worker   // The default argument is for backward compatibility.
135*d9f75844SAndroid Build Coastguard Worker   // TODO([email protected]): rename this SetRole to reflect its new function
136*d9f75844SAndroid Build Coastguard Worker   virtual void SetServerRole(SSLRole role = SSL_SERVER) = 0;
137*d9f75844SAndroid Build Coastguard Worker 
138*d9f75844SAndroid Build Coastguard Worker   // Do DTLS or TLS.
139*d9f75844SAndroid Build Coastguard Worker   virtual void SetMode(SSLMode mode) = 0;
140*d9f75844SAndroid Build Coastguard Worker 
141*d9f75844SAndroid Build Coastguard Worker   // Set maximum supported protocol version. The highest version supported by
142*d9f75844SAndroid Build Coastguard Worker   // both ends will be used for the connection, i.e. if one party supports
143*d9f75844SAndroid Build Coastguard Worker   // DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
144*d9f75844SAndroid Build Coastguard Worker   // If requested version is not supported by underlying crypto library, the
145*d9f75844SAndroid Build Coastguard Worker   // next lower will be used.
146*d9f75844SAndroid Build Coastguard Worker   virtual void SetMaxProtocolVersion(SSLProtocolVersion version) = 0;
147*d9f75844SAndroid Build Coastguard Worker 
148*d9f75844SAndroid Build Coastguard Worker   // Set the initial retransmission timeout for DTLS messages. When the timeout
149*d9f75844SAndroid Build Coastguard Worker   // expires, the message gets retransmitted and the timeout is exponentially
150*d9f75844SAndroid Build Coastguard Worker   // increased.
151*d9f75844SAndroid Build Coastguard Worker   // This should only be called before StartSSL().
152*d9f75844SAndroid Build Coastguard Worker   virtual void SetInitialRetransmissionTimeout(int timeout_ms) = 0;
153*d9f75844SAndroid Build Coastguard Worker 
154*d9f75844SAndroid Build Coastguard Worker   // StartSSL starts negotiation with a peer, whose certificate is verified
155*d9f75844SAndroid Build Coastguard Worker   // using the certificate digest. Generally, SetIdentity() and possibly
156*d9f75844SAndroid Build Coastguard Worker   // SetServerRole() should have been called before this.
157*d9f75844SAndroid Build Coastguard Worker   // SetPeerCertificateDigest() must also be called. It may be called after
158*d9f75844SAndroid Build Coastguard Worker   // StartSSLWithPeer() but must be called before the underlying stream opens.
159*d9f75844SAndroid Build Coastguard Worker   //
160*d9f75844SAndroid Build Coastguard Worker   // Use of the stream prior to calling StartSSL will pass data in clear text.
161*d9f75844SAndroid Build Coastguard Worker   // Calling StartSSL causes SSL negotiation to begin as soon as possible: right
162*d9f75844SAndroid Build Coastguard Worker   // away if the underlying wrapped stream is already opened, or else as soon as
163*d9f75844SAndroid Build Coastguard Worker   // it opens.
164*d9f75844SAndroid Build Coastguard Worker   //
165*d9f75844SAndroid Build Coastguard Worker   // StartSSL returns a negative error code on failure. Returning 0 means
166*d9f75844SAndroid Build Coastguard Worker   // success so far, but negotiation is probably not complete and will continue
167*d9f75844SAndroid Build Coastguard Worker   // asynchronously. In that case, the exposed stream will open after
168*d9f75844SAndroid Build Coastguard Worker   // successful negotiation and verification, or an SE_CLOSE event will be
169*d9f75844SAndroid Build Coastguard Worker   // raised if negotiation fails.
170*d9f75844SAndroid Build Coastguard Worker   virtual int StartSSL() = 0;
171*d9f75844SAndroid Build Coastguard Worker 
172*d9f75844SAndroid Build Coastguard Worker   // Specify the digest of the certificate that our peer is expected to use.
173*d9f75844SAndroid Build Coastguard Worker   // Only this certificate will be accepted during SSL verification. The
174*d9f75844SAndroid Build Coastguard Worker   // certificate is assumed to have been obtained through some other secure
175*d9f75844SAndroid Build Coastguard Worker   // channel (such as the signaling channel). This must specify the terminal
176*d9f75844SAndroid Build Coastguard Worker   // certificate, not just a CA. SSLStream makes a copy of the digest value.
177*d9f75844SAndroid Build Coastguard Worker   //
178*d9f75844SAndroid Build Coastguard Worker   // Returns true if successful.
179*d9f75844SAndroid Build Coastguard Worker   // `error` is optional and provides more information about the failure.
180*d9f75844SAndroid Build Coastguard Worker   virtual bool SetPeerCertificateDigest(
181*d9f75844SAndroid Build Coastguard Worker       absl::string_view digest_alg,
182*d9f75844SAndroid Build Coastguard Worker       const unsigned char* digest_val,
183*d9f75844SAndroid Build Coastguard Worker       size_t digest_len,
184*d9f75844SAndroid Build Coastguard Worker       SSLPeerCertificateDigestError* error = nullptr) = 0;
185*d9f75844SAndroid Build Coastguard Worker 
186*d9f75844SAndroid Build Coastguard Worker   // Retrieves the peer's certificate chain including leaf certificate, if a
187*d9f75844SAndroid Build Coastguard Worker   // connection has been established.
188*d9f75844SAndroid Build Coastguard Worker   virtual std::unique_ptr<SSLCertChain> GetPeerSSLCertChain() const = 0;
189*d9f75844SAndroid Build Coastguard Worker 
190*d9f75844SAndroid Build Coastguard Worker   // Retrieves the IANA registration id of the cipher suite used for the
191*d9f75844SAndroid Build Coastguard Worker   // connection (e.g. 0x2F for "TLS_RSA_WITH_AES_128_CBC_SHA").
192*d9f75844SAndroid Build Coastguard Worker   virtual bool GetSslCipherSuite(int* cipher_suite);
193*d9f75844SAndroid Build Coastguard Worker 
194*d9f75844SAndroid Build Coastguard Worker   // Retrieves the enum value for SSL version.
195*d9f75844SAndroid Build Coastguard Worker   // Will return -1 until the version has been negotiated.
196*d9f75844SAndroid Build Coastguard Worker   virtual SSLProtocolVersion GetSslVersion() const = 0;
197*d9f75844SAndroid Build Coastguard Worker   // Retrieves the 2-byte version from the TLS protocol.
198*d9f75844SAndroid Build Coastguard Worker   // Will return false until the version has been negotiated.
199*d9f75844SAndroid Build Coastguard Worker   virtual bool GetSslVersionBytes(int* version) const = 0;
200*d9f75844SAndroid Build Coastguard Worker 
201*d9f75844SAndroid Build Coastguard Worker   // Key Exporter interface from RFC 5705
202*d9f75844SAndroid Build Coastguard Worker   // Arguments are:
203*d9f75844SAndroid Build Coastguard Worker   // label               -- the exporter label.
204*d9f75844SAndroid Build Coastguard Worker   //                        part of the RFC defining each exporter
205*d9f75844SAndroid Build Coastguard Worker   //                        usage (IN)
206*d9f75844SAndroid Build Coastguard Worker   // context/context_len -- a context to bind to for this connection;
207*d9f75844SAndroid Build Coastguard Worker   //                        optional, can be null, 0 (IN)
208*d9f75844SAndroid Build Coastguard Worker   // use_context         -- whether to use the context value
209*d9f75844SAndroid Build Coastguard Worker   //                        (needed to distinguish no context from
210*d9f75844SAndroid Build Coastguard Worker   //                        zero-length ones).
211*d9f75844SAndroid Build Coastguard Worker   // result              -- where to put the computed value
212*d9f75844SAndroid Build Coastguard Worker   // result_len          -- the length of the computed value
213*d9f75844SAndroid Build Coastguard Worker   virtual bool ExportKeyingMaterial(absl::string_view label,
214*d9f75844SAndroid Build Coastguard Worker                                     const uint8_t* context,
215*d9f75844SAndroid Build Coastguard Worker                                     size_t context_len,
216*d9f75844SAndroid Build Coastguard Worker                                     bool use_context,
217*d9f75844SAndroid Build Coastguard Worker                                     uint8_t* result,
218*d9f75844SAndroid Build Coastguard Worker                                     size_t result_len);
219*d9f75844SAndroid Build Coastguard Worker 
220*d9f75844SAndroid Build Coastguard Worker   // DTLS-SRTP interface
221*d9f75844SAndroid Build Coastguard Worker   virtual bool SetDtlsSrtpCryptoSuites(const std::vector<int>& crypto_suites);
222*d9f75844SAndroid Build Coastguard Worker   virtual bool GetDtlsSrtpCryptoSuite(int* crypto_suite);
223*d9f75844SAndroid Build Coastguard Worker 
224*d9f75844SAndroid Build Coastguard Worker   // Returns true if a TLS connection has been established.
225*d9f75844SAndroid Build Coastguard Worker   // The only difference between this and "GetState() == SE_OPEN" is that if
226*d9f75844SAndroid Build Coastguard Worker   // the peer certificate digest hasn't been verified, the state will still be
227*d9f75844SAndroid Build Coastguard Worker   // SS_OPENING but IsTlsConnected should return true.
228*d9f75844SAndroid Build Coastguard Worker   virtual bool IsTlsConnected() = 0;
229*d9f75844SAndroid Build Coastguard Worker 
230*d9f75844SAndroid Build Coastguard Worker   // Capabilities testing.
231*d9f75844SAndroid Build Coastguard Worker   // Used to have "DTLS supported", "DTLS-SRTP supported" etc. methods, but now
232*d9f75844SAndroid Build Coastguard Worker   // that's assumed.
233*d9f75844SAndroid Build Coastguard Worker   static bool IsBoringSsl();
234*d9f75844SAndroid Build Coastguard Worker 
235*d9f75844SAndroid Build Coastguard Worker   // Returns true iff the supplied cipher is deemed to be strong.
236*d9f75844SAndroid Build Coastguard Worker   // TODO(torbjorng): Consider removing the KeyType argument.
237*d9f75844SAndroid Build Coastguard Worker   static bool IsAcceptableCipher(int cipher, KeyType key_type);
238*d9f75844SAndroid Build Coastguard Worker   static bool IsAcceptableCipher(absl::string_view cipher, KeyType key_type);
239*d9f75844SAndroid Build Coastguard Worker 
240*d9f75844SAndroid Build Coastguard Worker   // TODO(guoweis): Move this away from a static class method. Currently this is
241*d9f75844SAndroid Build Coastguard Worker   // introduced such that any caller could depend on sslstreamadapter.h without
242*d9f75844SAndroid Build Coastguard Worker   // depending on specific SSL implementation.
243*d9f75844SAndroid Build Coastguard Worker   static std::string SslCipherSuiteToName(int cipher_suite);
244*d9f75844SAndroid Build Coastguard Worker 
245*d9f75844SAndroid Build Coastguard Worker   ////////////////////////////////////////////////////////////////////////////
246*d9f75844SAndroid Build Coastguard Worker   // Testing only member functions
247*d9f75844SAndroid Build Coastguard Worker   ////////////////////////////////////////////////////////////////////////////
248*d9f75844SAndroid Build Coastguard Worker 
249*d9f75844SAndroid Build Coastguard Worker   // Use our timeutils.h source of timing in BoringSSL, allowing us to test
250*d9f75844SAndroid Build Coastguard Worker   // using a fake clock.
251*d9f75844SAndroid Build Coastguard Worker   static void EnableTimeCallbackForTesting();
252*d9f75844SAndroid Build Coastguard Worker 
253*d9f75844SAndroid Build Coastguard Worker   // Deprecated. Do not use this API outside of testing.
254*d9f75844SAndroid Build Coastguard Worker   // Do not set this to false outside of testing.
SetClientAuthEnabledForTesting(bool enabled)255*d9f75844SAndroid Build Coastguard Worker   void SetClientAuthEnabledForTesting(bool enabled) {
256*d9f75844SAndroid Build Coastguard Worker     client_auth_enabled_ = enabled;
257*d9f75844SAndroid Build Coastguard Worker   }
258*d9f75844SAndroid Build Coastguard Worker 
259*d9f75844SAndroid Build Coastguard Worker   // Deprecated. Do not use this API outside of testing.
260*d9f75844SAndroid Build Coastguard Worker   // Returns true by default, else false if explicitly set to disable client
261*d9f75844SAndroid Build Coastguard Worker   // authentication.
GetClientAuthEnabled()262*d9f75844SAndroid Build Coastguard Worker   bool GetClientAuthEnabled() const { return client_auth_enabled_; }
263*d9f75844SAndroid Build Coastguard Worker 
264*d9f75844SAndroid Build Coastguard Worker   sigslot::signal1<SSLHandshakeError> SignalSSLHandshakeError;
265*d9f75844SAndroid Build Coastguard Worker 
266*d9f75844SAndroid Build Coastguard Worker  private:
267*d9f75844SAndroid Build Coastguard Worker   // If true (default), the client is required to provide a certificate during
268*d9f75844SAndroid Build Coastguard Worker   // handshake. If no certificate is given, handshake fails. This applies to
269*d9f75844SAndroid Build Coastguard Worker   // server mode only.
270*d9f75844SAndroid Build Coastguard Worker   bool client_auth_enabled_ = true;
271*d9f75844SAndroid Build Coastguard Worker };
272*d9f75844SAndroid Build Coastguard Worker 
273*d9f75844SAndroid Build Coastguard Worker }  // namespace rtc
274*d9f75844SAndroid Build Coastguard Worker 
275*d9f75844SAndroid Build Coastguard Worker #endif  // RTC_BASE_SSL_STREAM_ADAPTER_H_
276