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