henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 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_BASE_SSLADAPTER_H_ |
| 12 | #define WEBRTC_BASE_SSLADAPTER_H_ |
| 13 | |
| 14 | #include "webrtc/base/asyncsocket.h" |
pthatcher@webrtc.org | dede187 | 2014-12-29 23:00:14 | [diff] [blame] | 15 | #include "webrtc/base/sslstreamadapter.h" |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 16 | |
| 17 | namespace rtc { |
| 18 | |
| 19 | /////////////////////////////////////////////////////////////////////////////// |
| 20 | |
| 21 | class SSLAdapter : public AsyncSocketAdapter { |
| 22 | public: |
| 23 | explicit SSLAdapter(AsyncSocket* socket) |
| 24 | : AsyncSocketAdapter(socket), ignore_bad_cert_(false) { } |
| 25 | |
| 26 | bool ignore_bad_cert() const { return ignore_bad_cert_; } |
| 27 | void set_ignore_bad_cert(bool ignore) { ignore_bad_cert_ = ignore; } |
| 28 | |
pthatcher@webrtc.org | dede187 | 2014-12-29 23:00:14 | [diff] [blame] | 29 | // Do DTLS or TLS (default is TLS, if unspecified) |
| 30 | virtual void SetMode(SSLMode mode) = 0; |
| 31 | |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 32 | // StartSSL returns 0 if successful. |
| 33 | // If StartSSL is called while the socket is closed or connecting, the SSL |
| 34 | // negotiation will begin as soon as the socket connects. |
| 35 | virtual int StartSSL(const char* hostname, bool restartable) = 0; |
| 36 | |
| 37 | // Create the default SSL adapter for this platform. On failure, returns NULL |
| 38 | // and deletes |socket|. Otherwise, the returned SSLAdapter takes ownership |
| 39 | // of |socket|. |
| 40 | static SSLAdapter* Create(AsyncSocket* socket); |
| 41 | |
| 42 | private: |
| 43 | // If true, the server certificate need not match the configured hostname. |
| 44 | bool ignore_bad_cert_; |
| 45 | }; |
| 46 | |
| 47 | /////////////////////////////////////////////////////////////////////////////// |
| 48 | |
| 49 | typedef bool (*VerificationCallback)(void* cert); |
| 50 | |
| 51 | // Call this on the main thread, before using SSL. |
| 52 | // Call CleanupSSLThread when finished with SSL. |
| 53 | bool InitializeSSL(VerificationCallback callback = NULL); |
| 54 | |
| 55 | // Call to initialize additional threads. |
| 56 | bool InitializeSSLThread(); |
| 57 | |
| 58 | // Call to cleanup additional threads, and also the main thread. |
| 59 | bool CleanupSSL(); |
| 60 | |
| 61 | /////////////////////////////////////////////////////////////////////////////// |
| 62 | |
| 63 | } // namespace rtc |
| 64 | |
| 65 | #endif // WEBRTC_BASE_SSLADAPTER_H_ |