henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 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 | |
kjellander | e96c45b | 2017-06-30 10:45:21 -0700 | [diff] [blame] | 11 | #include "webrtc/rtc_base/openssladapter.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 12 | |
| 13 | #if defined(WEBRTC_POSIX) |
| 14 | #include <unistd.h> |
| 15 | #endif |
| 16 | |
| 17 | // Must be included first before openssl headers. |
kjellander | e96c45b | 2017-06-30 10:45:21 -0700 | [diff] [blame] | 18 | #include "webrtc/rtc_base/win32.h" // NOLINT |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 19 | |
| 20 | #include <openssl/bio.h> |
| 21 | #include <openssl/crypto.h> |
| 22 | #include <openssl/err.h> |
| 23 | #include <openssl/opensslv.h> |
| 24 | #include <openssl/rand.h> |
henrike@webrtc.org | d5a0506 | 2014-06-30 20:38:56 +0000 | [diff] [blame] | 25 | #include <openssl/x509.h> |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 26 | #include <openssl/x509v3.h> |
| 27 | |
kjellander | e96c45b | 2017-06-30 10:45:21 -0700 | [diff] [blame] | 28 | #include "webrtc/rtc_base/arraysize.h" |
| 29 | #include "webrtc/rtc_base/checks.h" |
| 30 | #include "webrtc/rtc_base/logging.h" |
| 31 | #include "webrtc/rtc_base/openssl.h" |
| 32 | #include "webrtc/rtc_base/safe_conversions.h" |
| 33 | #include "webrtc/rtc_base/sslroots.h" |
| 34 | #include "webrtc/rtc_base/stringutils.h" |
| 35 | #include "webrtc/rtc_base/thread.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 36 | |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 37 | #ifndef OPENSSL_IS_BORINGSSL |
| 38 | |
| 39 | // TODO: Use a nicer abstraction for mutex. |
| 40 | |
| 41 | #if defined(WEBRTC_WIN) |
| 42 | #define MUTEX_TYPE HANDLE |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 43 | #define MUTEX_SETUP(x) (x) = CreateMutex(nullptr, FALSE, nullptr) |
| 44 | #define MUTEX_CLEANUP(x) CloseHandle(x) |
| 45 | #define MUTEX_LOCK(x) WaitForSingleObject((x), INFINITE) |
| 46 | #define MUTEX_UNLOCK(x) ReleaseMutex(x) |
| 47 | #define THREAD_ID GetCurrentThreadId() |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 48 | #elif defined(WEBRTC_POSIX) |
| 49 | #define MUTEX_TYPE pthread_mutex_t |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 50 | #define MUTEX_SETUP(x) pthread_mutex_init(&(x), nullptr) |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 51 | #define MUTEX_CLEANUP(x) pthread_mutex_destroy(&(x)) |
| 52 | #define MUTEX_LOCK(x) pthread_mutex_lock(&(x)) |
| 53 | #define MUTEX_UNLOCK(x) pthread_mutex_unlock(&(x)) |
| 54 | #define THREAD_ID pthread_self() |
| 55 | #else |
| 56 | #error You must define mutex operations appropriate for your platform! |
| 57 | #endif |
| 58 | |
| 59 | struct CRYPTO_dynlock_value { |
| 60 | MUTEX_TYPE mutex; |
| 61 | }; |
| 62 | |
| 63 | #endif // #ifndef OPENSSL_IS_BORINGSSL |
| 64 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 65 | ////////////////////////////////////////////////////////////////////// |
| 66 | // SocketBIO |
| 67 | ////////////////////////////////////////////////////////////////////// |
| 68 | |
| 69 | static int socket_write(BIO* h, const char* buf, int num); |
| 70 | static int socket_read(BIO* h, char* buf, int size); |
| 71 | static int socket_puts(BIO* h, const char* str); |
| 72 | static long socket_ctrl(BIO* h, int cmd, long arg1, void* arg2); |
| 73 | static int socket_new(BIO* h); |
| 74 | static int socket_free(BIO* data); |
| 75 | |
davidben@webrtc.org | 36d5c3c | 2015-01-22 23:06:17 +0000 | [diff] [blame] | 76 | // TODO(davidben): This should be const once BoringSSL is assumed. |
| 77 | static BIO_METHOD methods_socket = { |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 78 | BIO_TYPE_BIO, "socket", socket_write, socket_read, socket_puts, 0, |
| 79 | socket_ctrl, socket_new, socket_free, nullptr, |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
davidben@webrtc.org | 36d5c3c | 2015-01-22 23:06:17 +0000 | [diff] [blame] | 82 | static BIO_METHOD* BIO_s_socket2() { return(&methods_socket); } |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 83 | |
henrike@webrtc.org | c50bf7c | 2014-05-14 18:24:13 +0000 | [diff] [blame] | 84 | static BIO* BIO_new_socket(rtc::AsyncSocket* socket) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 85 | BIO* ret = BIO_new(BIO_s_socket2()); |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 86 | if (ret == nullptr) { |
| 87 | return nullptr; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 88 | } |
| 89 | ret->ptr = socket; |
| 90 | return ret; |
| 91 | } |
| 92 | |
| 93 | static int socket_new(BIO* b) { |
| 94 | b->shutdown = 0; |
| 95 | b->init = 1; |
| 96 | b->num = 0; // 1 means socket closed |
| 97 | b->ptr = 0; |
| 98 | return 1; |
| 99 | } |
| 100 | |
| 101 | static int socket_free(BIO* b) { |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 102 | if (b == nullptr) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 103 | return 0; |
| 104 | return 1; |
| 105 | } |
| 106 | |
| 107 | static int socket_read(BIO* b, char* out, int outl) { |
| 108 | if (!out) |
| 109 | return -1; |
| 110 | rtc::AsyncSocket* socket = static_cast<rtc::AsyncSocket*>(b->ptr); |
| 111 | BIO_clear_retry_flags(b); |
Stefan Holmer | 9131efd | 2016-05-23 18:19:26 +0200 | [diff] [blame] | 112 | int result = socket->Recv(out, outl, nullptr); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 113 | if (result > 0) { |
| 114 | return result; |
| 115 | } else if (result == 0) { |
| 116 | b->num = 1; |
| 117 | } else if (socket->IsBlocking()) { |
| 118 | BIO_set_retry_read(b); |
| 119 | } |
| 120 | return -1; |
| 121 | } |
| 122 | |
| 123 | static int socket_write(BIO* b, const char* in, int inl) { |
| 124 | if (!in) |
| 125 | return -1; |
| 126 | rtc::AsyncSocket* socket = static_cast<rtc::AsyncSocket*>(b->ptr); |
| 127 | BIO_clear_retry_flags(b); |
| 128 | int result = socket->Send(in, inl); |
| 129 | if (result > 0) { |
| 130 | return result; |
| 131 | } else if (socket->IsBlocking()) { |
| 132 | BIO_set_retry_write(b); |
| 133 | } |
| 134 | return -1; |
| 135 | } |
| 136 | |
| 137 | static int socket_puts(BIO* b, const char* str) { |
henrike@webrtc.org | d89b69a | 2014-11-06 17:23:09 +0000 | [diff] [blame] | 138 | return socket_write(b, str, rtc::checked_cast<int>(strlen(str))); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static long socket_ctrl(BIO* b, int cmd, long num, void* ptr) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 142 | switch (cmd) { |
| 143 | case BIO_CTRL_RESET: |
| 144 | return 0; |
| 145 | case BIO_CTRL_EOF: |
| 146 | return b->num; |
| 147 | case BIO_CTRL_WPENDING: |
| 148 | case BIO_CTRL_PENDING: |
| 149 | return 0; |
| 150 | case BIO_CTRL_FLUSH: |
| 151 | return 1; |
| 152 | default: |
| 153 | return 0; |
| 154 | } |
| 155 | } |
| 156 | |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 157 | static void LogSslError() { |
| 158 | // Walk down the error stack to find the SSL error. |
| 159 | uint32_t error_code; |
| 160 | const char* file; |
| 161 | int line; |
| 162 | do { |
| 163 | error_code = ERR_get_error_line(&file, &line); |
| 164 | if (ERR_GET_LIB(error_code) == ERR_LIB_SSL) { |
| 165 | LOG(LS_ERROR) << "ERR_LIB_SSL: " << error_code << ", " << file << ":" |
| 166 | << line; |
| 167 | break; |
| 168 | } |
| 169 | } while (error_code != 0); |
| 170 | } |
| 171 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 172 | ///////////////////////////////////////////////////////////////////////////// |
| 173 | // OpenSSLAdapter |
| 174 | ///////////////////////////////////////////////////////////////////////////// |
| 175 | |
| 176 | namespace rtc { |
| 177 | |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 178 | #ifndef OPENSSL_IS_BORINGSSL |
| 179 | |
| 180 | // This array will store all of the mutexes available to OpenSSL. |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 181 | static MUTEX_TYPE* mutex_buf = nullptr; |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 182 | |
| 183 | static void locking_function(int mode, int n, const char * file, int line) { |
| 184 | if (mode & CRYPTO_LOCK) { |
| 185 | MUTEX_LOCK(mutex_buf[n]); |
| 186 | } else { |
| 187 | MUTEX_UNLOCK(mutex_buf[n]); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | static unsigned long id_function() { // NOLINT |
| 192 | // Use old-style C cast because THREAD_ID's type varies with the platform, |
| 193 | // in some cases requiring static_cast, and in others requiring |
| 194 | // reinterpret_cast. |
| 195 | return (unsigned long)THREAD_ID; // NOLINT |
| 196 | } |
| 197 | |
| 198 | static CRYPTO_dynlock_value* dyn_create_function(const char* file, int line) { |
| 199 | CRYPTO_dynlock_value* value = new CRYPTO_dynlock_value; |
| 200 | if (!value) |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 201 | return nullptr; |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 202 | MUTEX_SETUP(value->mutex); |
| 203 | return value; |
| 204 | } |
| 205 | |
| 206 | static void dyn_lock_function(int mode, CRYPTO_dynlock_value* l, |
| 207 | const char* file, int line) { |
| 208 | if (mode & CRYPTO_LOCK) { |
| 209 | MUTEX_LOCK(l->mutex); |
| 210 | } else { |
| 211 | MUTEX_UNLOCK(l->mutex); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | static void dyn_destroy_function(CRYPTO_dynlock_value* l, |
| 216 | const char* file, int line) { |
| 217 | MUTEX_CLEANUP(l->mutex); |
| 218 | delete l; |
| 219 | } |
| 220 | |
| 221 | #endif // #ifndef OPENSSL_IS_BORINGSSL |
| 222 | |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 223 | VerificationCallback OpenSSLAdapter::custom_verify_callback_ = nullptr; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 224 | |
| 225 | bool OpenSSLAdapter::InitializeSSL(VerificationCallback callback) { |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 226 | if (!InitializeSSLThread() || !SSL_library_init()) |
| 227 | return false; |
| 228 | #if !defined(ADDRESS_SANITIZER) || !defined(WEBRTC_MAC) || defined(WEBRTC_IOS) |
| 229 | // Loading the error strings crashes mac_asan. Omit this debugging aid there. |
| 230 | SSL_load_error_strings(); |
| 231 | #endif |
| 232 | ERR_load_BIO_strings(); |
| 233 | OpenSSL_add_all_algorithms(); |
| 234 | RAND_poll(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 235 | custom_verify_callback_ = callback; |
| 236 | return true; |
| 237 | } |
| 238 | |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 239 | bool OpenSSLAdapter::InitializeSSLThread() { |
| 240 | // BoringSSL is doing the locking internally, so the callbacks are not used |
| 241 | // in this case (and are no-ops anyways). |
| 242 | #ifndef OPENSSL_IS_BORINGSSL |
| 243 | mutex_buf = new MUTEX_TYPE[CRYPTO_num_locks()]; |
| 244 | if (!mutex_buf) |
| 245 | return false; |
| 246 | for (int i = 0; i < CRYPTO_num_locks(); ++i) |
| 247 | MUTEX_SETUP(mutex_buf[i]); |
| 248 | |
| 249 | // we need to cast our id_function to return an unsigned long -- pthread_t is |
| 250 | // a pointer |
| 251 | CRYPTO_set_id_callback(id_function); |
| 252 | CRYPTO_set_locking_callback(locking_function); |
| 253 | CRYPTO_set_dynlock_create_callback(dyn_create_function); |
| 254 | CRYPTO_set_dynlock_lock_callback(dyn_lock_function); |
| 255 | CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function); |
| 256 | #endif // #ifndef OPENSSL_IS_BORINGSSL |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | bool OpenSSLAdapter::CleanupSSL() { |
| 261 | #ifndef OPENSSL_IS_BORINGSSL |
| 262 | if (!mutex_buf) |
| 263 | return false; |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 264 | CRYPTO_set_id_callback(nullptr); |
| 265 | CRYPTO_set_locking_callback(nullptr); |
| 266 | CRYPTO_set_dynlock_create_callback(nullptr); |
| 267 | CRYPTO_set_dynlock_lock_callback(nullptr); |
| 268 | CRYPTO_set_dynlock_destroy_callback(nullptr); |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 269 | for (int i = 0; i < CRYPTO_num_locks(); ++i) |
| 270 | MUTEX_CLEANUP(mutex_buf[i]); |
| 271 | delete [] mutex_buf; |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 272 | mutex_buf = nullptr; |
Torbjorn Granlund | 9adc91d | 2016-03-24 14:05:06 +0100 | [diff] [blame] | 273 | #endif // #ifndef OPENSSL_IS_BORINGSSL |
| 274 | return true; |
| 275 | } |
| 276 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 277 | OpenSSLAdapter::OpenSSLAdapter(AsyncSocket* socket, |
| 278 | OpenSSLAdapterFactory* factory) |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 279 | : SSLAdapter(socket), |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 280 | factory_(factory), |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 281 | state_(SSL_NONE), |
| 282 | ssl_read_needs_write_(false), |
| 283 | ssl_write_needs_read_(false), |
| 284 | restartable_(false), |
| 285 | ssl_(nullptr), |
| 286 | ssl_ctx_(nullptr), |
| 287 | ssl_mode_(SSL_MODE_TLS), |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 288 | custom_verification_succeeded_(false) { |
| 289 | // If a factory is used, take a reference on the factory's SSL_CTX. |
| 290 | // Otherwise, we'll create our own later. |
| 291 | // Either way, we'll release our reference via SSL_CTX_free() in Cleanup(). |
| 292 | if (factory_) { |
| 293 | ssl_ctx_ = factory_->ssl_ctx(); |
| 294 | RTC_DCHECK(ssl_ctx_); |
| 295 | // Note: if using OpenSSL, requires version 1.1.0 or later. |
| 296 | SSL_CTX_up_ref(ssl_ctx_); |
| 297 | } |
| 298 | } |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 299 | |
| 300 | OpenSSLAdapter::~OpenSSLAdapter() { |
| 301 | Cleanup(); |
| 302 | } |
| 303 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 304 | void OpenSSLAdapter::SetMode(SSLMode mode) { |
| 305 | RTC_DCHECK(!ssl_ctx_); |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 306 | RTC_DCHECK(state_ == SSL_NONE); |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 307 | ssl_mode_ = mode; |
| 308 | } |
| 309 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 310 | int OpenSSLAdapter::StartSSL(const char* hostname, bool restartable) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 311 | if (state_ != SSL_NONE) |
| 312 | return -1; |
| 313 | |
| 314 | ssl_host_name_ = hostname; |
| 315 | restartable_ = restartable; |
| 316 | |
| 317 | if (socket_->GetState() != Socket::CS_CONNECTED) { |
| 318 | state_ = SSL_WAIT; |
| 319 | return 0; |
| 320 | } |
| 321 | |
| 322 | state_ = SSL_CONNECTING; |
| 323 | if (int err = BeginSSL()) { |
| 324 | Error("BeginSSL", err, false); |
| 325 | return err; |
| 326 | } |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 331 | int OpenSSLAdapter::BeginSSL() { |
| 332 | LOG(LS_INFO) << "OpenSSLAdapter::BeginSSL: " << ssl_host_name_; |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 333 | RTC_DCHECK(state_ == SSL_CONNECTING); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 334 | |
| 335 | int err = 0; |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 336 | BIO* bio = nullptr; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 337 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 338 | // First set up the context. We should either have a factory, with its own |
| 339 | // pre-existing context, or be running standalone, in which case we will |
| 340 | // need to create one, and specify |false| to disable session caching. |
| 341 | if (!factory_) { |
| 342 | RTC_DCHECK(!ssl_ctx_); |
| 343 | ssl_ctx_ = CreateContext(ssl_mode_, false); |
| 344 | } |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 345 | if (!ssl_ctx_) { |
| 346 | err = -1; |
| 347 | goto ssl_error; |
| 348 | } |
| 349 | |
Peter Boström | 0b518bf | 2016-01-27 12:35:40 +0100 | [diff] [blame] | 350 | bio = BIO_new_socket(socket_); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 351 | if (!bio) { |
| 352 | err = -1; |
| 353 | goto ssl_error; |
| 354 | } |
| 355 | |
| 356 | ssl_ = SSL_new(ssl_ctx_); |
| 357 | if (!ssl_) { |
| 358 | err = -1; |
| 359 | goto ssl_error; |
| 360 | } |
| 361 | |
| 362 | SSL_set_app_data(ssl_, this); |
| 363 | |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 364 | // SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER allows different buffers to be passed |
| 365 | // into SSL_write when a record could only be partially transmitted (and thus |
| 366 | // requires another call to SSL_write to finish transmission). This allows us |
| 367 | // to copy the data into our own buffer when this occurs, since the original |
| 368 | // buffer can't safely be accessed after control exits Send. |
| 369 | // TODO(deadbeef): Do we want SSL_MODE_ENABLE_PARTIAL_WRITE? It doesn't |
| 370 | // appear Send handles partial writes properly, though maybe we never notice |
| 371 | // since we never send more than 16KB at once.. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 372 | SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE | |
| 373 | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); |
| 374 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 375 | // Enable SNI, if a hostname is supplied. |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 376 | if (!ssl_host_name_.empty()) { |
| 377 | SSL_set_tlsext_host_name(ssl_, ssl_host_name_.c_str()); |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 378 | |
| 379 | // Enable session caching, if configured and a hostname is supplied. |
| 380 | if (factory_) { |
| 381 | SSL_SESSION* cached = factory_->LookupSession(ssl_host_name_); |
| 382 | if (cached) { |
| 383 | if (SSL_set_session(ssl_, cached) == 0) { |
| 384 | LOG(LS_WARNING) << "Failed to apply SSL session from cache"; |
| 385 | err = -1; |
| 386 | goto ssl_error; |
| 387 | } |
| 388 | |
| 389 | LOG(LS_INFO) << "Attempting to resume SSL session to " |
| 390 | << ssl_host_name_; |
| 391 | } |
| 392 | } |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Emad Omara | cb79d23 | 2017-07-20 16:34:34 -0700 | [diff] [blame] | 395 | // Set a couple common TLS extensions; even though we don't use them yet. |
| 396 | // TODO(emadomara) Add ALPN extension. |
| 397 | SSL_enable_ocsp_stapling(ssl_); |
| 398 | SSL_enable_signed_cert_timestamps(ssl_); |
| 399 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 400 | // Now that the initial config is done, transfer ownership of |bio| to the |
| 401 | // SSL object. If ContinueSSL() fails, the bio will be freed in Cleanup(). |
| 402 | SSL_set_bio(ssl_, bio, bio); |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 403 | bio = nullptr; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 404 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 405 | // Do the connect. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 406 | err = ContinueSSL(); |
| 407 | if (err != 0) |
| 408 | goto ssl_error; |
| 409 | |
| 410 | return err; |
| 411 | |
| 412 | ssl_error: |
| 413 | Cleanup(); |
| 414 | if (bio) |
| 415 | BIO_free(bio); |
| 416 | |
| 417 | return err; |
| 418 | } |
| 419 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 420 | int OpenSSLAdapter::ContinueSSL() { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 421 | RTC_DCHECK(state_ == SSL_CONNECTING); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 422 | |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 423 | // Clear the DTLS timer |
| 424 | Thread::Current()->Clear(this, MSG_TIMEOUT); |
| 425 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 426 | int code = SSL_connect(ssl_); |
| 427 | switch (SSL_get_error(ssl_, code)) { |
| 428 | case SSL_ERROR_NONE: |
| 429 | if (!SSLPostConnectionCheck(ssl_, ssl_host_name_.c_str())) { |
| 430 | LOG(LS_ERROR) << "TLS post connection check failed"; |
| 431 | // make sure we close the socket |
| 432 | Cleanup(); |
| 433 | // The connect failed so return -1 to shut down the socket |
| 434 | return -1; |
| 435 | } |
| 436 | |
| 437 | state_ = SSL_CONNECTED; |
| 438 | AsyncSocketAdapter::OnConnectEvent(this); |
| 439 | #if 0 // TODO: worry about this |
| 440 | // Don't let ourselves go away during the callbacks |
| 441 | PRefPtr<OpenSSLAdapter> lock(this); |
| 442 | LOG(LS_INFO) << " -- onStreamReadable"; |
| 443 | AsyncSocketAdapter::OnReadEvent(this); |
| 444 | LOG(LS_INFO) << " -- onStreamWriteable"; |
| 445 | AsyncSocketAdapter::OnWriteEvent(this); |
| 446 | #endif |
| 447 | break; |
| 448 | |
| 449 | case SSL_ERROR_WANT_READ: |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 450 | LOG(LS_VERBOSE) << " -- error want read"; |
| 451 | struct timeval timeout; |
| 452 | if (DTLSv1_get_timeout(ssl_, &timeout)) { |
| 453 | int delay = timeout.tv_sec * 1000 + timeout.tv_usec/1000; |
| 454 | |
Taylor Brandstetter | 5d97a9a | 2016-06-10 14:17:27 -0700 | [diff] [blame] | 455 | Thread::Current()->PostDelayed(RTC_FROM_HERE, delay, this, MSG_TIMEOUT, |
| 456 | 0); |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 457 | } |
| 458 | break; |
| 459 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 460 | case SSL_ERROR_WANT_WRITE: |
| 461 | break; |
| 462 | |
| 463 | case SSL_ERROR_ZERO_RETURN: |
| 464 | default: |
| 465 | LOG(LS_WARNING) << "ContinueSSL -- error " << code; |
| 466 | return (code != 0) ? code : -1; |
| 467 | } |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 472 | void OpenSSLAdapter::Error(const char* context, int err, bool signal) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 473 | LOG(LS_WARNING) << "OpenSSLAdapter::Error(" |
| 474 | << context << ", " << err << ")"; |
| 475 | state_ = SSL_ERROR; |
| 476 | SetError(err); |
| 477 | if (signal) |
| 478 | AsyncSocketAdapter::OnCloseEvent(this, err); |
| 479 | } |
| 480 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 481 | void OpenSSLAdapter::Cleanup() { |
| 482 | LOG(LS_INFO) << "OpenSSLAdapter::Cleanup"; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 483 | |
| 484 | state_ = SSL_NONE; |
| 485 | ssl_read_needs_write_ = false; |
| 486 | ssl_write_needs_read_ = false; |
| 487 | custom_verification_succeeded_ = false; |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 488 | pending_data_.Clear(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 489 | |
| 490 | if (ssl_) { |
| 491 | SSL_free(ssl_); |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 492 | ssl_ = nullptr; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | if (ssl_ctx_) { |
| 496 | SSL_CTX_free(ssl_ctx_); |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 497 | ssl_ctx_ = nullptr; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 498 | } |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 499 | |
| 500 | // Clear the DTLS timer |
| 501 | Thread::Current()->Clear(this, MSG_TIMEOUT); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 502 | } |
| 503 | |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 504 | int OpenSSLAdapter::DoSslWrite(const void* pv, size_t cb, int* error) { |
| 505 | // If we have pending data (that was previously only partially written by |
| 506 | // SSL_write), we shouldn't be attempting to write anything else. |
| 507 | RTC_DCHECK(pending_data_.empty() || pv == pending_data_.data()); |
| 508 | RTC_DCHECK(error != nullptr); |
| 509 | |
| 510 | ssl_write_needs_read_ = false; |
| 511 | int ret = SSL_write(ssl_, pv, checked_cast<int>(cb)); |
| 512 | *error = SSL_get_error(ssl_, ret); |
| 513 | switch (*error) { |
| 514 | case SSL_ERROR_NONE: |
| 515 | // Success! |
| 516 | return ret; |
| 517 | case SSL_ERROR_WANT_READ: |
| 518 | LOG(LS_INFO) << " -- error want read"; |
| 519 | ssl_write_needs_read_ = true; |
| 520 | SetError(EWOULDBLOCK); |
| 521 | break; |
| 522 | case SSL_ERROR_WANT_WRITE: |
| 523 | LOG(LS_INFO) << " -- error want write"; |
| 524 | SetError(EWOULDBLOCK); |
| 525 | break; |
| 526 | case SSL_ERROR_ZERO_RETURN: |
| 527 | // LOG(LS_INFO) << " -- remote side closed"; |
| 528 | SetError(EWOULDBLOCK); |
| 529 | // do we need to signal closure? |
| 530 | break; |
| 531 | case SSL_ERROR_SSL: |
| 532 | LogSslError(); |
| 533 | Error("SSL_write", ret ? ret : -1, false); |
| 534 | break; |
| 535 | default: |
| 536 | LOG(LS_WARNING) << "Unknown error from SSL_write: " << *error; |
| 537 | Error("SSL_write", ret ? ret : -1, false); |
| 538 | break; |
| 539 | } |
| 540 | |
| 541 | return SOCKET_ERROR; |
| 542 | } |
| 543 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 544 | // |
| 545 | // AsyncSocket Implementation |
| 546 | // |
| 547 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 548 | int OpenSSLAdapter::Send(const void* pv, size_t cb) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 549 | //LOG(LS_INFO) << "OpenSSLAdapter::Send(" << cb << ")"; |
| 550 | |
| 551 | switch (state_) { |
| 552 | case SSL_NONE: |
| 553 | return AsyncSocketAdapter::Send(pv, cb); |
| 554 | |
| 555 | case SSL_WAIT: |
| 556 | case SSL_CONNECTING: |
skvlad | c309e0e | 2016-07-28 17:15:20 -0700 | [diff] [blame] | 557 | SetError(ENOTCONN); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 558 | return SOCKET_ERROR; |
| 559 | |
| 560 | case SSL_CONNECTED: |
| 561 | break; |
| 562 | |
| 563 | case SSL_ERROR: |
| 564 | default: |
| 565 | return SOCKET_ERROR; |
| 566 | } |
| 567 | |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 568 | int ret; |
| 569 | int error; |
| 570 | |
| 571 | if (!pending_data_.empty()) { |
| 572 | ret = DoSslWrite(pending_data_.data(), pending_data_.size(), &error); |
| 573 | if (ret != static_cast<int>(pending_data_.size())) { |
| 574 | // We couldn't finish sending the pending data, so we definitely can't |
| 575 | // send any more data. Return with an EWOULDBLOCK error. |
| 576 | SetError(EWOULDBLOCK); |
| 577 | return SOCKET_ERROR; |
| 578 | } |
| 579 | // We completed sending the data previously passed into SSL_write! Now |
| 580 | // we're allowed to send more data. |
| 581 | pending_data_.Clear(); |
| 582 | } |
| 583 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 584 | // OpenSSL will return an error if we try to write zero bytes |
| 585 | if (cb == 0) |
| 586 | return 0; |
| 587 | |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 588 | ret = DoSslWrite(pv, cb, &error); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 589 | |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 590 | // If SSL_write fails with SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE, this |
| 591 | // means the underlying socket is blocked on reading or (more typically) |
| 592 | // writing. When this happens, OpenSSL requires that the next call to |
| 593 | // SSL_write uses the same arguments (though, with |
| 594 | // SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER, the actual buffer pointer may be |
| 595 | // different). |
| 596 | // |
| 597 | // However, after Send exits, we will have lost access to data the user of |
| 598 | // this class is trying to send, and there's no guarantee that the user of |
| 599 | // this class will call Send with the same arguements when it fails. So, we |
| 600 | // buffer the data ourselves. When we know the underlying socket is writable |
| 601 | // again from OnWriteEvent (or if Send is called again before that happens), |
| 602 | // we'll retry sending this buffered data. |
deadbeef | e5dce2b | 2017-06-02 11:52:06 -0700 | [diff] [blame] | 603 | if (error == SSL_ERROR_WANT_READ || error == SSL_ERROR_WANT_WRITE) { |
| 604 | // Shouldn't be able to get to this point if we already have pending data. |
| 605 | RTC_DCHECK(pending_data_.empty()); |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 606 | LOG(LS_WARNING) |
| 607 | << "SSL_write couldn't write to the underlying socket; buffering data."; |
| 608 | pending_data_.SetData(static_cast<const uint8_t*>(pv), cb); |
| 609 | // Since we're taking responsibility for sending this data, return its full |
| 610 | // size. The user of this class can consider it sent. |
| 611 | return cb; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 612 | } |
| 613 | |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 614 | return ret; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 615 | } |
| 616 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 617 | int OpenSSLAdapter::SendTo(const void* pv, |
| 618 | size_t cb, |
| 619 | const SocketAddress& addr) { |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 620 | if (socket_->GetState() == Socket::CS_CONNECTED && |
| 621 | addr == socket_->GetRemoteAddress()) { |
| 622 | return Send(pv, cb); |
| 623 | } |
| 624 | |
| 625 | SetError(ENOTCONN); |
| 626 | |
| 627 | return SOCKET_ERROR; |
| 628 | } |
| 629 | |
Stefan Holmer | 9131efd | 2016-05-23 18:19:26 +0200 | [diff] [blame] | 630 | int OpenSSLAdapter::Recv(void* pv, size_t cb, int64_t* timestamp) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 631 | //LOG(LS_INFO) << "OpenSSLAdapter::Recv(" << cb << ")"; |
| 632 | switch (state_) { |
| 633 | |
| 634 | case SSL_NONE: |
Stefan Holmer | 9131efd | 2016-05-23 18:19:26 +0200 | [diff] [blame] | 635 | return AsyncSocketAdapter::Recv(pv, cb, timestamp); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 636 | |
| 637 | case SSL_WAIT: |
| 638 | case SSL_CONNECTING: |
skvlad | c309e0e | 2016-07-28 17:15:20 -0700 | [diff] [blame] | 639 | SetError(ENOTCONN); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 640 | return SOCKET_ERROR; |
| 641 | |
| 642 | case SSL_CONNECTED: |
| 643 | break; |
| 644 | |
| 645 | case SSL_ERROR: |
| 646 | default: |
| 647 | return SOCKET_ERROR; |
| 648 | } |
| 649 | |
| 650 | // Don't trust OpenSSL with zero byte reads |
| 651 | if (cb == 0) |
| 652 | return 0; |
| 653 | |
| 654 | ssl_read_needs_write_ = false; |
| 655 | |
henrike@webrtc.org | d89b69a | 2014-11-06 17:23:09 +0000 | [diff] [blame] | 656 | int code = SSL_read(ssl_, pv, checked_cast<int>(cb)); |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 657 | int error = SSL_get_error(ssl_, code); |
| 658 | switch (error) { |
| 659 | case SSL_ERROR_NONE: |
| 660 | // LOG(LS_INFO) << " -- success"; |
| 661 | return code; |
| 662 | case SSL_ERROR_WANT_READ: |
| 663 | // LOG(LS_INFO) << " -- error want read"; |
| 664 | SetError(EWOULDBLOCK); |
| 665 | break; |
| 666 | case SSL_ERROR_WANT_WRITE: |
| 667 | // LOG(LS_INFO) << " -- error want write"; |
| 668 | ssl_read_needs_write_ = true; |
| 669 | SetError(EWOULDBLOCK); |
| 670 | break; |
| 671 | case SSL_ERROR_ZERO_RETURN: |
| 672 | // LOG(LS_INFO) << " -- remote side closed"; |
| 673 | SetError(EWOULDBLOCK); |
| 674 | // do we need to signal closure? |
| 675 | break; |
| 676 | case SSL_ERROR_SSL: |
| 677 | LogSslError(); |
| 678 | Error("SSL_read", (code ? code : -1), false); |
| 679 | break; |
| 680 | default: |
| 681 | LOG(LS_WARNING) << "Unknown error from SSL_read: " << error; |
| 682 | Error("SSL_read", (code ? code : -1), false); |
| 683 | break; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | return SOCKET_ERROR; |
| 687 | } |
| 688 | |
Stefan Holmer | 9131efd | 2016-05-23 18:19:26 +0200 | [diff] [blame] | 689 | int OpenSSLAdapter::RecvFrom(void* pv, |
| 690 | size_t cb, |
| 691 | SocketAddress* paddr, |
| 692 | int64_t* timestamp) { |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 693 | if (socket_->GetState() == Socket::CS_CONNECTED) { |
Stefan Holmer | 9131efd | 2016-05-23 18:19:26 +0200 | [diff] [blame] | 694 | int ret = Recv(pv, cb, timestamp); |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 695 | |
| 696 | *paddr = GetRemoteAddress(); |
| 697 | |
| 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | SetError(ENOTCONN); |
| 702 | |
| 703 | return SOCKET_ERROR; |
| 704 | } |
| 705 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 706 | int OpenSSLAdapter::Close() { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 707 | Cleanup(); |
| 708 | state_ = restartable_ ? SSL_WAIT : SSL_NONE; |
| 709 | return AsyncSocketAdapter::Close(); |
| 710 | } |
| 711 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 712 | Socket::ConnState OpenSSLAdapter::GetState() const { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 713 | //if (signal_close_) |
| 714 | // return CS_CONNECTED; |
| 715 | ConnState state = socket_->GetState(); |
| 716 | if ((state == CS_CONNECTED) |
| 717 | && ((state_ == SSL_WAIT) || (state_ == SSL_CONNECTING))) |
| 718 | state = CS_CONNECTING; |
| 719 | return state; |
| 720 | } |
| 721 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 722 | bool OpenSSLAdapter::IsResumedSession() { |
| 723 | return (ssl_ && SSL_session_reused(ssl_) == 1); |
| 724 | } |
| 725 | |
| 726 | void OpenSSLAdapter::OnMessage(Message* msg) { |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 727 | if (MSG_TIMEOUT == msg->message_id) { |
| 728 | LOG(LS_INFO) << "DTLS timeout expired"; |
| 729 | DTLSv1_handle_timeout(ssl_); |
| 730 | ContinueSSL(); |
| 731 | } |
| 732 | } |
| 733 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 734 | void OpenSSLAdapter::OnConnectEvent(AsyncSocket* socket) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 735 | LOG(LS_INFO) << "OpenSSLAdapter::OnConnectEvent"; |
| 736 | if (state_ != SSL_WAIT) { |
nisse | ede5da4 | 2017-01-12 05:15:36 -0800 | [diff] [blame] | 737 | RTC_DCHECK(state_ == SSL_NONE); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 738 | AsyncSocketAdapter::OnConnectEvent(socket); |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | state_ = SSL_CONNECTING; |
| 743 | if (int err = BeginSSL()) { |
| 744 | AsyncSocketAdapter::OnCloseEvent(socket, err); |
| 745 | } |
| 746 | } |
| 747 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 748 | void OpenSSLAdapter::OnReadEvent(AsyncSocket* socket) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 749 | //LOG(LS_INFO) << "OpenSSLAdapter::OnReadEvent"; |
| 750 | |
| 751 | if (state_ == SSL_NONE) { |
| 752 | AsyncSocketAdapter::OnReadEvent(socket); |
| 753 | return; |
| 754 | } |
| 755 | |
| 756 | if (state_ == SSL_CONNECTING) { |
| 757 | if (int err = ContinueSSL()) { |
| 758 | Error("ContinueSSL", err); |
| 759 | } |
| 760 | return; |
| 761 | } |
| 762 | |
| 763 | if (state_ != SSL_CONNECTED) |
| 764 | return; |
| 765 | |
| 766 | // Don't let ourselves go away during the callbacks |
| 767 | //PRefPtr<OpenSSLAdapter> lock(this); // TODO: fix this |
| 768 | if (ssl_write_needs_read_) { |
| 769 | //LOG(LS_INFO) << " -- onStreamWriteable"; |
| 770 | AsyncSocketAdapter::OnWriteEvent(socket); |
| 771 | } |
| 772 | |
| 773 | //LOG(LS_INFO) << " -- onStreamReadable"; |
| 774 | AsyncSocketAdapter::OnReadEvent(socket); |
| 775 | } |
| 776 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 777 | void OpenSSLAdapter::OnWriteEvent(AsyncSocket* socket) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 778 | //LOG(LS_INFO) << "OpenSSLAdapter::OnWriteEvent"; |
| 779 | |
| 780 | if (state_ == SSL_NONE) { |
| 781 | AsyncSocketAdapter::OnWriteEvent(socket); |
| 782 | return; |
| 783 | } |
| 784 | |
| 785 | if (state_ == SSL_CONNECTING) { |
| 786 | if (int err = ContinueSSL()) { |
| 787 | Error("ContinueSSL", err); |
| 788 | } |
| 789 | return; |
| 790 | } |
| 791 | |
| 792 | if (state_ != SSL_CONNECTED) |
| 793 | return; |
| 794 | |
| 795 | // Don't let ourselves go away during the callbacks |
| 796 | //PRefPtr<OpenSSLAdapter> lock(this); // TODO: fix this |
| 797 | |
| 798 | if (ssl_read_needs_write_) { |
| 799 | //LOG(LS_INFO) << " -- onStreamReadable"; |
| 800 | AsyncSocketAdapter::OnReadEvent(socket); |
| 801 | } |
| 802 | |
deadbeef | ed3b986 | 2017-06-02 10:33:16 -0700 | [diff] [blame] | 803 | // If a previous SSL_write failed due to the underlying socket being blocked, |
| 804 | // this will attempt finishing the write operation. |
| 805 | if (!pending_data_.empty()) { |
| 806 | int error; |
| 807 | if (DoSslWrite(pending_data_.data(), pending_data_.size(), &error) == |
| 808 | static_cast<int>(pending_data_.size())) { |
| 809 | pending_data_.Clear(); |
| 810 | } |
| 811 | } |
| 812 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 813 | //LOG(LS_INFO) << " -- onStreamWriteable"; |
| 814 | AsyncSocketAdapter::OnWriteEvent(socket); |
| 815 | } |
| 816 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 817 | void OpenSSLAdapter::OnCloseEvent(AsyncSocket* socket, int err) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 818 | LOG(LS_INFO) << "OpenSSLAdapter::OnCloseEvent(" << err << ")"; |
| 819 | AsyncSocketAdapter::OnCloseEvent(socket, err); |
| 820 | } |
| 821 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 822 | bool OpenSSLAdapter::VerifyServerName(SSL* ssl, const char* host, |
| 823 | bool ignore_bad_cert) { |
| 824 | if (!host) |
| 825 | return false; |
| 826 | |
| 827 | // Checking the return from SSL_get_peer_certificate here is not strictly |
| 828 | // necessary. With our setup, it is not possible for it to return |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 829 | // null. However, it is good form to check the return. |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 830 | X509* certificate = SSL_get_peer_certificate(ssl); |
| 831 | if (!certificate) |
| 832 | return false; |
| 833 | |
| 834 | // Logging certificates is extremely verbose. So it is disabled by default. |
| 835 | #ifdef LOG_CERTIFICATES |
| 836 | { |
| 837 | LOG(LS_INFO) << "Certificate from server:"; |
| 838 | BIO* mem = BIO_new(BIO_s_mem()); |
| 839 | X509_print_ex(mem, certificate, XN_FLAG_SEP_CPLUS_SPC, X509_FLAG_NO_HEADER); |
| 840 | BIO_write(mem, "\0", 1); |
| 841 | char* buffer; |
| 842 | BIO_get_mem_data(mem, &buffer); |
| 843 | LOG(LS_INFO) << buffer; |
| 844 | BIO_free(mem); |
| 845 | |
| 846 | char* cipher_description = |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 847 | SSL_CIPHER_description(SSL_get_current_cipher(ssl), nullptr, 128); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 848 | LOG(LS_INFO) << "Cipher: " << cipher_description; |
| 849 | OPENSSL_free(cipher_description); |
| 850 | } |
| 851 | #endif |
| 852 | |
| 853 | bool ok = false; |
davidben | 4ef903d | 2017-02-17 13:04:43 -0800 | [diff] [blame] | 854 | GENERAL_NAMES* names = reinterpret_cast<GENERAL_NAMES*>( |
| 855 | X509_get_ext_d2i(certificate, NID_subject_alt_name, nullptr, nullptr)); |
| 856 | if (names) { |
| 857 | for (size_t i = 0; i < sk_GENERAL_NAME_num(names); i++) { |
| 858 | const GENERAL_NAME* name = sk_GENERAL_NAME_value(names, i); |
| 859 | if (name->type != GEN_DNS) |
| 860 | continue; |
| 861 | std::string value( |
| 862 | reinterpret_cast<const char*>(ASN1_STRING_data(name->d.dNSName)), |
| 863 | ASN1_STRING_length(name->d.dNSName)); |
| 864 | // string_match takes NUL-terminated strings, so check for embedded NULs. |
| 865 | if (value.find('\0') != std::string::npos) |
| 866 | continue; |
| 867 | if (string_match(host, value.c_str())) { |
| 868 | ok = true; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 869 | break; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 870 | } |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 871 | } |
davidben | 4ef903d | 2017-02-17 13:04:43 -0800 | [diff] [blame] | 872 | GENERAL_NAMES_free(names); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | char data[256]; |
henrike@webrtc.org | d5a0506 | 2014-06-30 20:38:56 +0000 | [diff] [blame] | 876 | X509_NAME* subject; |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 877 | if (!ok && ((subject = X509_get_subject_name(certificate)) != nullptr) && |
| 878 | (X509_NAME_get_text_by_NID(subject, NID_commonName, data, sizeof(data)) > |
| 879 | 0)) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 880 | data[sizeof(data)-1] = 0; |
| 881 | if (_stricmp(data, host) == 0) |
| 882 | ok = true; |
| 883 | } |
| 884 | |
| 885 | X509_free(certificate); |
| 886 | |
| 887 | // This should only ever be turned on for debugging and development. |
| 888 | if (!ok && ignore_bad_cert) { |
| 889 | LOG(LS_WARNING) << "TLS certificate check FAILED. " |
| 890 | << "Allowing connection anyway."; |
| 891 | ok = true; |
| 892 | } |
| 893 | |
| 894 | return ok; |
| 895 | } |
| 896 | |
| 897 | bool OpenSSLAdapter::SSLPostConnectionCheck(SSL* ssl, const char* host) { |
| 898 | bool ok = VerifyServerName(ssl, host, ignore_bad_cert()); |
| 899 | |
| 900 | if (ok) { |
| 901 | ok = (SSL_get_verify_result(ssl) == X509_V_OK || |
| 902 | custom_verification_succeeded_); |
| 903 | } |
| 904 | |
| 905 | if (!ok && ignore_bad_cert()) { |
| 906 | LOG(LS_INFO) << "Other TLS post connection checks failed."; |
| 907 | ok = true; |
| 908 | } |
| 909 | |
| 910 | return ok; |
| 911 | } |
| 912 | |
tfarina | a41ab93 | 2015-10-30 16:08:48 -0700 | [diff] [blame] | 913 | #if !defined(NDEBUG) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 914 | |
| 915 | // We only use this for tracing and so it is only needed in debug mode |
| 916 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 917 | void OpenSSLAdapter::SSLInfoCallback(const SSL* s, int where, int ret) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 918 | const char* str = "undefined"; |
| 919 | int w = where & ~SSL_ST_MASK; |
| 920 | if (w & SSL_ST_CONNECT) { |
| 921 | str = "SSL_connect"; |
| 922 | } else if (w & SSL_ST_ACCEPT) { |
| 923 | str = "SSL_accept"; |
| 924 | } |
| 925 | if (where & SSL_CB_LOOP) { |
| 926 | LOG(LS_INFO) << str << ":" << SSL_state_string_long(s); |
| 927 | } else if (where & SSL_CB_ALERT) { |
| 928 | str = (where & SSL_CB_READ) ? "read" : "write"; |
| 929 | LOG(LS_INFO) << "SSL3 alert " << str |
| 930 | << ":" << SSL_alert_type_string_long(ret) |
| 931 | << ":" << SSL_alert_desc_string_long(ret); |
| 932 | } else if (where & SSL_CB_EXIT) { |
| 933 | if (ret == 0) { |
| 934 | LOG(LS_INFO) << str << ":failed in " << SSL_state_string_long(s); |
| 935 | } else if (ret < 0) { |
| 936 | LOG(LS_INFO) << str << ":error in " << SSL_state_string_long(s); |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
tfarina | a41ab93 | 2015-10-30 16:08:48 -0700 | [diff] [blame] | 941 | #endif |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 942 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 943 | int OpenSSLAdapter::SSLVerifyCallback(int ok, X509_STORE_CTX* store) { |
tfarina | a41ab93 | 2015-10-30 16:08:48 -0700 | [diff] [blame] | 944 | #if !defined(NDEBUG) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 945 | if (!ok) { |
| 946 | char data[256]; |
| 947 | X509* cert = X509_STORE_CTX_get_current_cert(store); |
| 948 | int depth = X509_STORE_CTX_get_error_depth(store); |
| 949 | int err = X509_STORE_CTX_get_error(store); |
| 950 | |
| 951 | LOG(LS_INFO) << "Error with certificate at depth: " << depth; |
| 952 | X509_NAME_oneline(X509_get_issuer_name(cert), data, sizeof(data)); |
| 953 | LOG(LS_INFO) << " issuer = " << data; |
| 954 | X509_NAME_oneline(X509_get_subject_name(cert), data, sizeof(data)); |
| 955 | LOG(LS_INFO) << " subject = " << data; |
| 956 | LOG(LS_INFO) << " err = " << err |
| 957 | << ":" << X509_verify_cert_error_string(err); |
| 958 | } |
| 959 | #endif |
| 960 | |
| 961 | // Get our stream pointer from the store |
| 962 | SSL* ssl = reinterpret_cast<SSL*>( |
| 963 | X509_STORE_CTX_get_ex_data(store, |
| 964 | SSL_get_ex_data_X509_STORE_CTX_idx())); |
| 965 | |
| 966 | OpenSSLAdapter* stream = |
| 967 | reinterpret_cast<OpenSSLAdapter*>(SSL_get_app_data(ssl)); |
| 968 | |
| 969 | if (!ok && custom_verify_callback_) { |
| 970 | void* cert = |
| 971 | reinterpret_cast<void*>(X509_STORE_CTX_get_current_cert(store)); |
| 972 | if (custom_verify_callback_(cert)) { |
| 973 | stream->custom_verification_succeeded_ = true; |
| 974 | LOG(LS_INFO) << "validated certificate using custom callback"; |
| 975 | ok = true; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | // Should only be used for debugging and development. |
| 980 | if (!ok && stream->ignore_bad_cert()) { |
| 981 | LOG(LS_WARNING) << "Ignoring cert error while verifying cert chain"; |
| 982 | ok = 1; |
| 983 | } |
| 984 | |
| 985 | return ok; |
| 986 | } |
| 987 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 988 | int OpenSSLAdapter::NewSSLSessionCallback(SSL* ssl, SSL_SESSION* session) { |
| 989 | OpenSSLAdapter* stream = |
| 990 | reinterpret_cast<OpenSSLAdapter*>(SSL_get_app_data(ssl)); |
| 991 | RTC_DCHECK(stream->factory_); |
| 992 | LOG(LS_INFO) << "Caching SSL session for " << stream->ssl_host_name_; |
| 993 | stream->factory_->AddSession(stream->ssl_host_name_, session); |
| 994 | return 1; // We've taken ownership of the session; OpenSSL shouldn't free it. |
| 995 | } |
| 996 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 997 | bool OpenSSLAdapter::ConfigureTrustedRootCertificates(SSL_CTX* ctx) { |
| 998 | // Add the root cert that we care about to the SSL context |
| 999 | int count_of_added_certs = 0; |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 1000 | for (size_t i = 0; i < arraysize(kSSLCertCertificateList); i++) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1001 | const unsigned char* cert_buffer = kSSLCertCertificateList[i]; |
| 1002 | size_t cert_buffer_len = kSSLCertCertificateSizeList[i]; |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 1003 | X509* cert = |
| 1004 | d2i_X509(nullptr, &cert_buffer, checked_cast<long>(cert_buffer_len)); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1005 | if (cert) { |
| 1006 | int return_value = X509_STORE_add_cert(SSL_CTX_get_cert_store(ctx), cert); |
| 1007 | if (return_value == 0) { |
| 1008 | LOG(LS_WARNING) << "Unable to add certificate."; |
| 1009 | } else { |
| 1010 | count_of_added_certs++; |
| 1011 | } |
| 1012 | X509_free(cert); |
| 1013 | } |
| 1014 | } |
| 1015 | return count_of_added_certs > 0; |
| 1016 | } |
| 1017 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 1018 | SSL_CTX* OpenSSLAdapter::CreateContext(SSLMode mode, bool enable_cache) { |
Emad Omara | c6de0c9 | 2017-06-21 16:40:56 -0700 | [diff] [blame] | 1019 | // Use (D)TLS 1.2. |
| 1020 | // Note: BoringSSL supports a range of versions by setting max/min version |
| 1021 | // (Default V1.0 to V1.2). However (D)TLSv1_2_client_method functions used |
| 1022 | // below in OpenSSL only support V1.2. |
| 1023 | SSL_CTX* ctx = nullptr; |
| 1024 | #ifdef OPENSSL_IS_BORINGSSL |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 1025 | ctx = SSL_CTX_new(mode == SSL_MODE_DTLS ? DTLS_method() : TLS_method()); |
Emad Omara | c6de0c9 | 2017-06-21 16:40:56 -0700 | [diff] [blame] | 1026 | #else |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 1027 | ctx = SSL_CTX_new(mode == SSL_MODE_DTLS ? DTLSv1_2_client_method() |
| 1028 | : TLSv1_2_client_method()); |
Emad Omara | c6de0c9 | 2017-06-21 16:40:56 -0700 | [diff] [blame] | 1029 | #endif // OPENSSL_IS_BORINGSSL |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 1030 | if (ctx == nullptr) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1031 | unsigned long error = ERR_get_error(); // NOLINT: type used by OpenSSL. |
| 1032 | LOG(LS_WARNING) << "SSL_CTX creation failed: " |
| 1033 | << '"' << ERR_reason_error_string(error) << "\" " |
| 1034 | << "(error=" << error << ')'; |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 1035 | return nullptr; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1036 | } |
| 1037 | if (!ConfigureTrustedRootCertificates(ctx)) { |
| 1038 | SSL_CTX_free(ctx); |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 1039 | return nullptr; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
tfarina | a41ab93 | 2015-10-30 16:08:48 -0700 | [diff] [blame] | 1042 | #if !defined(NDEBUG) |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1043 | SSL_CTX_set_info_callback(ctx, SSLInfoCallback); |
| 1044 | #endif |
| 1045 | |
| 1046 | SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, SSLVerifyCallback); |
| 1047 | SSL_CTX_set_verify_depth(ctx, 4); |
Emad Omara | c6de0c9 | 2017-06-21 16:40:56 -0700 | [diff] [blame] | 1048 | // Use defaults, but disable HMAC-SHA256 and HMAC-SHA384 ciphers |
| 1049 | // (note that SHA256 and SHA384 only select legacy CBC ciphers). |
| 1050 | // Additionally disable HMAC-SHA1 ciphers in ECDSA. These are the remaining |
| 1051 | // CBC-mode ECDSA ciphers. |
| 1052 | SSL_CTX_set_cipher_list( |
| 1053 | ctx, "ALL:!SHA256:!SHA384:!aPSK:!ECDSA+SHA1:!ADH:!LOW:!EXP:!MD5"); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1054 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 1055 | if (mode == SSL_MODE_DTLS) { |
pthatcher@webrtc.org | a9b1ec0 | 2014-12-29 23:00:14 +0000 | [diff] [blame] | 1056 | SSL_CTX_set_read_ahead(ctx, 1); |
| 1057 | } |
| 1058 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 1059 | if (enable_cache) { |
| 1060 | SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_CLIENT); |
| 1061 | SSL_CTX_sess_set_new_cb(ctx, &OpenSSLAdapter::NewSSLSessionCallback); |
| 1062 | } |
| 1063 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1064 | return ctx; |
| 1065 | } |
| 1066 | |
Justin Uberti | 1d44550 | 2017-08-14 17:04:34 -0700 | [diff] [blame^] | 1067 | ////////////////////////////////////////////////////////////////////// |
| 1068 | // OpenSSLAdapterFactory |
| 1069 | ////////////////////////////////////////////////////////////////////// |
| 1070 | |
| 1071 | OpenSSLAdapterFactory::OpenSSLAdapterFactory() |
| 1072 | : ssl_mode_(SSL_MODE_TLS), ssl_ctx_(nullptr) {} |
| 1073 | |
| 1074 | OpenSSLAdapterFactory::~OpenSSLAdapterFactory() { |
| 1075 | for (auto it : sessions_) { |
| 1076 | SSL_SESSION_free(it.second); |
| 1077 | } |
| 1078 | SSL_CTX_free(ssl_ctx_); |
| 1079 | } |
| 1080 | |
| 1081 | void OpenSSLAdapterFactory::SetMode(SSLMode mode) { |
| 1082 | RTC_DCHECK(!ssl_ctx_); |
| 1083 | ssl_mode_ = mode; |
| 1084 | } |
| 1085 | |
| 1086 | OpenSSLAdapter* OpenSSLAdapterFactory::CreateAdapter(AsyncSocket* socket) { |
| 1087 | if (!ssl_ctx_) { |
| 1088 | bool enable_cache = true; |
| 1089 | ssl_ctx_ = OpenSSLAdapter::CreateContext(ssl_mode_, enable_cache); |
| 1090 | if (!ssl_ctx_) { |
| 1091 | return nullptr; |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | return new OpenSSLAdapter(socket, this); |
| 1096 | } |
| 1097 | |
| 1098 | SSL_SESSION* OpenSSLAdapterFactory::LookupSession(const std::string& hostname) { |
| 1099 | auto it = sessions_.find(hostname); |
| 1100 | return (it != sessions_.end()) ? it->second : nullptr; |
| 1101 | } |
| 1102 | |
| 1103 | void OpenSSLAdapterFactory::AddSession(const std::string& hostname, |
| 1104 | SSL_SESSION* new_session) { |
| 1105 | SSL_SESSION* old_session = LookupSession(hostname); |
| 1106 | SSL_SESSION_free(old_session); |
| 1107 | sessions_[hostname] = new_session; |
| 1108 | } |
| 1109 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1110 | } // namespace rtc |