Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: webrtc/base/opensslstreamadapter.cc

Issue 1548733002: Change DTLS default from 1.0 to 1.2 for webrtc. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/app/webrtc/peerconnectioninterface.h ('k') | webrtc/base/sslstreamadapterhelper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #if HAVE_CONFIG_H 11 #if HAVE_CONFIG_H
12 #include "config.h" 12 #include "config.h"
13 #endif // HAVE_CONFIG_H 13 #endif // HAVE_CONFIG_H
14 14
15 #if HAVE_OPENSSL_SSL_H 15 #if HAVE_OPENSSL_SSL_H
16 16
17 #include "webrtc/base/opensslstreamadapter.h" 17 #include "webrtc/base/opensslstreamadapter.h"
18 18
19 #include <openssl/bio.h> 19 #include <openssl/bio.h>
20 #include <openssl/crypto.h> 20 #include <openssl/crypto.h>
21 #include <openssl/err.h> 21 #include <openssl/err.h>
22 #include <openssl/rand.h> 22 #include <openssl/rand.h>
23 #include <openssl/tls1.h> 23 #include <openssl/tls1.h>
24 #include <openssl/x509v3.h> 24 #include <openssl/x509v3.h>
25 25
26 #include <vector> 26 #include <vector>
27 27
28 #include "webrtc/base/checks.h"
28 #include "webrtc/base/common.h" 29 #include "webrtc/base/common.h"
29 #include "webrtc/base/logging.h" 30 #include "webrtc/base/logging.h"
30 #include "webrtc/base/safe_conversions.h" 31 #include "webrtc/base/safe_conversions.h"
31 #include "webrtc/base/stream.h" 32 #include "webrtc/base/stream.h"
32 #include "webrtc/base/openssl.h" 33 #include "webrtc/base/openssl.h"
33 #include "webrtc/base/openssladapter.h" 34 #include "webrtc/base/openssladapter.h"
34 #include "webrtc/base/openssldigest.h" 35 #include "webrtc/base/openssldigest.h"
35 #include "webrtc/base/opensslidentity.h" 36 #include "webrtc/base/opensslidentity.h"
36 #include "webrtc/base/stringutils.h" 37 #include "webrtc/base/stringutils.h"
37 #include "webrtc/base/thread.h" 38 #include "webrtc/base/thread.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 static int kDefaultSslEcCipher10 = 156 static int kDefaultSslEcCipher10 =
156 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA); 157 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
157 #ifdef OPENSSL_IS_BORINGSSL 158 #ifdef OPENSSL_IS_BORINGSSL
158 static int kDefaultSslCipher12 = 159 static int kDefaultSslCipher12 =
159 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256); 160 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256);
160 static int kDefaultSslEcCipher12 = 161 static int kDefaultSslEcCipher12 =
161 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256); 162 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256);
162 // Fallback cipher for DTLS 1.2 if hardware-accelerated AES-GCM is unavailable. 163 // Fallback cipher for DTLS 1.2 if hardware-accelerated AES-GCM is unavailable.
163 // TODO(davidben): Switch to the standardized CHACHA20_POLY1305 variant when 164 // TODO(davidben): Switch to the standardized CHACHA20_POLY1305 variant when
164 // available. 165 // available.
166 static int kDefaultSslCipher12NoAesGcmNonStandard =
167 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD);
168 static int kDefaultSslEcCipher12NoAesGcmNonStandard =
169 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD);
165 static int kDefaultSslCipher12NoAesGcm = 170 static int kDefaultSslCipher12NoAesGcm =
166 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD); 171 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256);
167 static int kDefaultSslEcCipher12NoAesGcm = 172 static int kDefaultSslEcCipher12NoAesGcm =
168 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD); 173 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256);
169 #else // !OPENSSL_IS_BORINGSSL 174 #else // !OPENSSL_IS_BORINGSSL
170 // OpenSSL sorts differently than BoringSSL, so the default cipher doesn't 175 // OpenSSL sorts differently than BoringSSL, so the default cipher doesn't
171 // change between TLS 1.0 and TLS 1.2 with the current setup. 176 // change between TLS 1.0 and TLS 1.2 with the current setup.
172 static int kDefaultSslCipher12 = 177 static int kDefaultSslCipher12 =
173 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA); 178 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA);
174 static int kDefaultSslEcCipher12 = 179 static int kDefaultSslEcCipher12 =
175 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA); 180 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
176 #endif 181 #endif
177 182
178 #if defined(_MSC_VER) 183 #if defined(_MSC_VER)
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 299 }
295 300
296 ///////////////////////////////////////////////////////////////////////////// 301 /////////////////////////////////////////////////////////////////////////////
297 // OpenSSLStreamAdapter 302 // OpenSSLStreamAdapter
298 ///////////////////////////////////////////////////////////////////////////// 303 /////////////////////////////////////////////////////////////////////////////
299 304
300 OpenSSLStreamAdapter::OpenSSLStreamAdapter(StreamInterface* stream) 305 OpenSSLStreamAdapter::OpenSSLStreamAdapter(StreamInterface* stream)
301 : SSLStreamAdapter(stream), 306 : SSLStreamAdapter(stream),
302 state_(SSL_NONE), 307 state_(SSL_NONE),
303 role_(SSL_CLIENT), 308 role_(SSL_CLIENT),
304 ssl_read_needs_write_(false), ssl_write_needs_read_(false), 309 ssl_read_needs_write_(false),
305 ssl_(NULL), ssl_ctx_(NULL), 310 ssl_write_needs_read_(false),
311 ssl_(NULL),
312 ssl_ctx_(NULL),
306 custom_verification_succeeded_(false), 313 custom_verification_succeeded_(false),
307 ssl_mode_(SSL_MODE_TLS), 314 ssl_mode_(SSL_MODE_TLS),
308 ssl_max_version_(SSL_PROTOCOL_TLS_11) { 315 ssl_max_version_(SSL_PROTOCOL_TLS_12) {}
309 }
310 316
311 OpenSSLStreamAdapter::~OpenSSLStreamAdapter() { 317 OpenSSLStreamAdapter::~OpenSSLStreamAdapter() {
312 Cleanup(); 318 Cleanup();
313 } 319 }
314 320
315 void OpenSSLStreamAdapter::SetIdentity(SSLIdentity* identity) { 321 void OpenSSLStreamAdapter::SetIdentity(SSLIdentity* identity) {
316 ASSERT(!identity_); 322 ASSERT(!identity_);
317 identity_.reset(static_cast<OpenSSLIdentity*>(identity)); 323 identity_.reset(static_cast<OpenSSLIdentity*>(identity));
318 } 324 }
319 325
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 switch (version) { 1137 switch (version) {
1132 case SSL_PROTOCOL_TLS_10: 1138 case SSL_PROTOCOL_TLS_10:
1133 case SSL_PROTOCOL_TLS_11: 1139 case SSL_PROTOCOL_TLS_11:
1134 return kDefaultSslCipher10; 1140 return kDefaultSslCipher10;
1135 case SSL_PROTOCOL_TLS_12: 1141 case SSL_PROTOCOL_TLS_12:
1136 default: 1142 default:
1137 #ifdef OPENSSL_IS_BORINGSSL 1143 #ifdef OPENSSL_IS_BORINGSSL
1138 if (EVP_has_aes_hardware()) { 1144 if (EVP_has_aes_hardware()) {
1139 return kDefaultSslCipher12; 1145 return kDefaultSslCipher12;
1140 } else { 1146 } else {
1141 return kDefaultSslCipher12NoAesGcm; 1147 if (EVP_aead_chacha20_poly1305()) {
1148 return kDefaultSslCipher12NoAesGcm;
1149 } else {
1150 RTC_CHECK(EVP_aead_chacha20_poly1305_old());
1151 return kDefaultSslCipher12NoAesGcmNonStandard;
1152 }
davidben_webrtc 2016/01/11 21:10:55 Eh? Both of these functions will only ever return
1142 } 1153 }
1143 #else // !OPENSSL_IS_BORINGSSL 1154 #else // !OPENSSL_IS_BORINGSSL
1144 return kDefaultSslCipher12; 1155 return kDefaultSslCipher12;
1145 #endif 1156 #endif
1146 } 1157 }
1147 } else if (key_type == KT_ECDSA) { 1158 } else if (key_type == KT_ECDSA) {
1148 switch (version) { 1159 switch (version) {
1149 case SSL_PROTOCOL_TLS_10: 1160 case SSL_PROTOCOL_TLS_10:
1150 case SSL_PROTOCOL_TLS_11: 1161 case SSL_PROTOCOL_TLS_11:
1151 return kDefaultSslEcCipher10; 1162 return kDefaultSslEcCipher10;
1152 case SSL_PROTOCOL_TLS_12: 1163 case SSL_PROTOCOL_TLS_12:
1153 default: 1164 default:
1154 #ifdef OPENSSL_IS_BORINGSSL 1165 #ifdef OPENSSL_IS_BORINGSSL
1155 if (EVP_has_aes_hardware()) { 1166 if (EVP_has_aes_hardware()) {
1156 return kDefaultSslEcCipher12; 1167 return kDefaultSslEcCipher12;
1157 } else { 1168 } else {
1158 return kDefaultSslEcCipher12NoAesGcm; 1169 if (EVP_aead_chacha20_poly1305()) {
1170 return kDefaultSslEcCipher12NoAesGcm;
1171 } else {
1172 RTC_CHECK(EVP_aead_chacha20_poly1305_old());
1173 return kDefaultSslEcCipher12NoAesGcmNonStandard;
1174 }
1159 } 1175 }
1160 #else // !OPENSSL_IS_BORINGSSL 1176 #else // !OPENSSL_IS_BORINGSSL
1161 return kDefaultSslEcCipher12; 1177 return kDefaultSslEcCipher12;
1162 #endif 1178 #endif
1163 } 1179 }
1164 } else { 1180 } else {
1165 RTC_NOTREACHED(); 1181 RTC_NOTREACHED();
1166 return kDefaultSslEcCipher12; 1182 return kDefaultSslEcCipher12;
1167 } 1183 }
1168 } 1184 }
1169 1185
1170 } // namespace rtc 1186 } // namespace rtc
1171 1187
1172 #endif // HAVE_OPENSSL_SSL_H 1188 #endif // HAVE_OPENSSL_SSL_H
OLDNEW
« no previous file with comments | « talk/app/webrtc/peerconnectioninterface.h ('k') | webrtc/base/sslstreamadapterhelper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698