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

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

Issue 1828773003: Revert of Remove code interfacing legacy openssl. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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 | « webrtc/base/opensslidentity.cc ('k') | webrtc/base/ssladapter.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
(...skipping 20 matching lines...) Expand all
31 #include "webrtc/base/stream.h" 31 #include "webrtc/base/stream.h"
32 #include "webrtc/base/openssl.h" 32 #include "webrtc/base/openssl.h"
33 #include "webrtc/base/openssladapter.h" 33 #include "webrtc/base/openssladapter.h"
34 #include "webrtc/base/openssldigest.h" 34 #include "webrtc/base/openssldigest.h"
35 #include "webrtc/base/opensslidentity.h" 35 #include "webrtc/base/opensslidentity.h"
36 #include "webrtc/base/stringutils.h" 36 #include "webrtc/base/stringutils.h"
37 #include "webrtc/base/thread.h" 37 #include "webrtc/base/thread.h"
38 38
39 namespace rtc { 39 namespace rtc {
40 40
41 #if (OPENSSL_VERSION_NUMBER >= 0x10001000L)
42 #define HAVE_DTLS_SRTP
43 #endif
44
45 #ifdef HAVE_DTLS_SRTP
41 // SRTP cipher suite table. |internal_name| is used to construct a 46 // SRTP cipher suite table. |internal_name| is used to construct a
42 // colon-separated profile strings which is needed by 47 // colon-separated profile strings which is needed by
43 // SSL_CTX_set_tlsext_use_srtp(). 48 // SSL_CTX_set_tlsext_use_srtp().
44 struct SrtpCipherMapEntry { 49 struct SrtpCipherMapEntry {
45 const char* internal_name; 50 const char* internal_name;
46 const int id; 51 const int id;
47 }; 52 };
48 53
49 // This isn't elegant, but it's better than an external reference 54 // This isn't elegant, but it's better than an external reference
50 static SrtpCipherMapEntry SrtpCipherMap[] = { 55 static SrtpCipherMapEntry SrtpCipherMap[] = {
51 {"SRTP_AES128_CM_SHA1_80", SRTP_AES128_CM_SHA1_80}, 56 {"SRTP_AES128_CM_SHA1_80", SRTP_AES128_CM_SHA1_80},
52 {"SRTP_AES128_CM_SHA1_32", SRTP_AES128_CM_SHA1_32}, 57 {"SRTP_AES128_CM_SHA1_32", SRTP_AES128_CM_SHA1_32},
53 {nullptr, 0}}; 58 {nullptr, 0}};
59 #endif
60
61 #ifndef OPENSSL_IS_BORINGSSL
62
63 // Cipher name table. Maps internal OpenSSL cipher ids to the RFC name.
64 struct SslCipherMapEntry {
65 uint32_t openssl_id;
66 const char* rfc_name;
67 };
68
69 #define DEFINE_CIPHER_ENTRY_SSL3(name) {SSL3_CK_##name, "TLS_"#name}
70 #define DEFINE_CIPHER_ENTRY_TLS1(name) {TLS1_CK_##name, "TLS_"#name}
71
72 // There currently is no method available to get a RFC-compliant name for a
73 // cipher suite from BoringSSL, so we need to define the mapping manually here.
74 // This should go away once BoringSSL supports "SSL_CIPHER_standard_name"
75 // (as available in OpenSSL if compiled with tracing enabled) or a similar
76 // method.
77 static const SslCipherMapEntry kSslCipherMap[] = {
78 // TLS v1.0 ciphersuites from RFC2246.
79 DEFINE_CIPHER_ENTRY_SSL3(RSA_RC4_128_SHA),
80 {SSL3_CK_RSA_DES_192_CBC3_SHA,
81 "TLS_RSA_WITH_3DES_EDE_CBC_SHA"},
82
83 // AES ciphersuites from RFC3268.
84 {TLS1_CK_RSA_WITH_AES_128_SHA,
85 "TLS_RSA_WITH_AES_128_CBC_SHA"},
86 {TLS1_CK_DHE_RSA_WITH_AES_128_SHA,
87 "TLS_DHE_RSA_WITH_AES_128_CBC_SHA"},
88 {TLS1_CK_RSA_WITH_AES_256_SHA,
89 "TLS_RSA_WITH_AES_256_CBC_SHA"},
90 {TLS1_CK_DHE_RSA_WITH_AES_256_SHA,
91 "TLS_DHE_RSA_WITH_AES_256_CBC_SHA"},
92
93 // ECC ciphersuites from RFC4492.
94 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_RC4_128_SHA),
95 {TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA,
96 "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA"},
97 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_128_CBC_SHA),
98 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_256_CBC_SHA),
99
100 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_RC4_128_SHA),
101 {TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA,
102 "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA"},
103 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_128_CBC_SHA),
104 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_256_CBC_SHA),
105
106 // TLS v1.2 ciphersuites.
107 {TLS1_CK_RSA_WITH_AES_128_SHA256,
108 "TLS_RSA_WITH_AES_128_CBC_SHA256"},
109 {TLS1_CK_RSA_WITH_AES_256_SHA256,
110 "TLS_RSA_WITH_AES_256_CBC_SHA256"},
111 {TLS1_CK_DHE_RSA_WITH_AES_128_SHA256,
112 "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"},
113 {TLS1_CK_DHE_RSA_WITH_AES_256_SHA256,
114 "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256"},
115
116 // TLS v1.2 GCM ciphersuites from RFC5288.
117 DEFINE_CIPHER_ENTRY_TLS1(RSA_WITH_AES_128_GCM_SHA256),
118 DEFINE_CIPHER_ENTRY_TLS1(RSA_WITH_AES_256_GCM_SHA384),
119 DEFINE_CIPHER_ENTRY_TLS1(DHE_RSA_WITH_AES_128_GCM_SHA256),
120 DEFINE_CIPHER_ENTRY_TLS1(DHE_RSA_WITH_AES_256_GCM_SHA384),
121 DEFINE_CIPHER_ENTRY_TLS1(DH_RSA_WITH_AES_128_GCM_SHA256),
122 DEFINE_CIPHER_ENTRY_TLS1(DH_RSA_WITH_AES_256_GCM_SHA384),
123
124 // ECDH HMAC based ciphersuites from RFC5289.
125 {TLS1_CK_ECDHE_ECDSA_WITH_AES_128_SHA256,
126 "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"},
127 {TLS1_CK_ECDHE_ECDSA_WITH_AES_256_SHA384,
128 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384"},
129 {TLS1_CK_ECDHE_RSA_WITH_AES_128_SHA256,
130 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"},
131 {TLS1_CK_ECDHE_RSA_WITH_AES_256_SHA384,
132 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384"},
133
134 // ECDH GCM based ciphersuites from RFC5289.
135 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_128_GCM_SHA256),
136 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_256_GCM_SHA384),
137 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_128_GCM_SHA256),
138 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_256_GCM_SHA384),
139
140 {0, NULL}
141 };
142 #endif // #ifndef OPENSSL_IS_BORINGSSL
54 143
55 #if defined(_MSC_VER) 144 #if defined(_MSC_VER)
56 #pragma warning(push) 145 #pragma warning(push)
57 #pragma warning(disable : 4309) 146 #pragma warning(disable : 4309)
58 #pragma warning(disable : 4310) 147 #pragma warning(disable : 4310)
59 #endif // defined(_MSC_VER) 148 #endif // defined(_MSC_VER)
60 149
61 #if defined(_MSC_VER) 150 #if defined(_MSC_VER)
62 #pragma warning(pop) 151 #pragma warning(pop)
63 #endif // defined(_MSC_VER) 152 #endif // defined(_MSC_VER)
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (expected_len != digest_len) 319 if (expected_len != digest_len)
231 return false; 320 return false;
232 321
233 peer_certificate_digest_value_.SetData(digest_val, digest_len); 322 peer_certificate_digest_value_.SetData(digest_val, digest_len);
234 peer_certificate_digest_algorithm_ = digest_alg; 323 peer_certificate_digest_algorithm_ = digest_alg;
235 324
236 return true; 325 return true;
237 } 326 }
238 327
239 std::string OpenSSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { 328 std::string OpenSSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) {
329 #ifdef OPENSSL_IS_BORINGSSL
240 const SSL_CIPHER* ssl_cipher = SSL_get_cipher_by_value(cipher_suite); 330 const SSL_CIPHER* ssl_cipher = SSL_get_cipher_by_value(cipher_suite);
241 if (!ssl_cipher) { 331 if (!ssl_cipher) {
242 return std::string(); 332 return std::string();
243 } 333 }
244 char* cipher_name = SSL_CIPHER_get_rfc_name(ssl_cipher); 334 char* cipher_name = SSL_CIPHER_get_rfc_name(ssl_cipher);
245 std::string rfc_name = std::string(cipher_name); 335 std::string rfc_name = std::string(cipher_name);
246 OPENSSL_free(cipher_name); 336 OPENSSL_free(cipher_name);
247 return rfc_name; 337 return rfc_name;
338 #else
339 for (const SslCipherMapEntry* entry = kSslCipherMap; entry->rfc_name;
340 ++entry) {
341 if (cipher_suite == static_cast<int>(entry->openssl_id)) {
342 return entry->rfc_name;
343 }
344 }
345 return std::string();
346 #endif
248 } 347 }
249 348
250 bool OpenSSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { 349 bool OpenSSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) {
251 if (state_ != SSL_CONNECTED) 350 if (state_ != SSL_CONNECTED)
252 return false; 351 return false;
253 352
254 const SSL_CIPHER* current_cipher = SSL_get_current_cipher(ssl_); 353 const SSL_CIPHER* current_cipher = SSL_get_current_cipher(ssl_);
255 if (current_cipher == NULL) { 354 if (current_cipher == NULL) {
256 return false; 355 return false;
257 } 356 }
(...skipping 24 matching lines...) Expand all
282 return -1; 381 return -1;
283 } 382 }
284 383
285 // Key Extractor interface 384 // Key Extractor interface
286 bool OpenSSLStreamAdapter::ExportKeyingMaterial(const std::string& label, 385 bool OpenSSLStreamAdapter::ExportKeyingMaterial(const std::string& label,
287 const uint8_t* context, 386 const uint8_t* context,
288 size_t context_len, 387 size_t context_len,
289 bool use_context, 388 bool use_context,
290 uint8_t* result, 389 uint8_t* result,
291 size_t result_len) { 390 size_t result_len) {
391 #ifdef HAVE_DTLS_SRTP
292 int i; 392 int i;
293 393
294 i = SSL_export_keying_material(ssl_, result, result_len, label.c_str(), 394 i = SSL_export_keying_material(ssl_, result, result_len, label.c_str(),
295 label.length(), const_cast<uint8_t*>(context), 395 label.length(), const_cast<uint8_t*>(context),
296 context_len, use_context); 396 context_len, use_context);
297 397
298 if (i != 1) 398 if (i != 1)
299 return false; 399 return false;
300 400
301 return true; 401 return true;
402 #else
403 return false;
404 #endif
302 } 405 }
303 406
304 bool OpenSSLStreamAdapter::SetDtlsSrtpCryptoSuites( 407 bool OpenSSLStreamAdapter::SetDtlsSrtpCryptoSuites(
305 const std::vector<int>& ciphers) { 408 const std::vector<int>& ciphers) {
409 #ifdef HAVE_DTLS_SRTP
306 std::string internal_ciphers; 410 std::string internal_ciphers;
307 411
308 if (state_ != SSL_NONE) 412 if (state_ != SSL_NONE)
309 return false; 413 return false;
310 414
311 for (std::vector<int>::const_iterator cipher = ciphers.begin(); 415 for (std::vector<int>::const_iterator cipher = ciphers.begin();
312 cipher != ciphers.end(); ++cipher) { 416 cipher != ciphers.end(); ++cipher) {
313 bool found = false; 417 bool found = false;
314 for (SrtpCipherMapEntry* entry = SrtpCipherMap; entry->internal_name; 418 for (SrtpCipherMapEntry* entry = SrtpCipherMap; entry->internal_name;
315 ++entry) { 419 ++entry) {
(...skipping 10 matching lines...) Expand all
326 LOG(LS_ERROR) << "Could not find cipher: " << *cipher; 430 LOG(LS_ERROR) << "Could not find cipher: " << *cipher;
327 return false; 431 return false;
328 } 432 }
329 } 433 }
330 434
331 if (internal_ciphers.empty()) 435 if (internal_ciphers.empty())
332 return false; 436 return false;
333 437
334 srtp_ciphers_ = internal_ciphers; 438 srtp_ciphers_ = internal_ciphers;
335 return true; 439 return true;
440 #else
441 return false;
442 #endif
336 } 443 }
337 444
338 bool OpenSSLStreamAdapter::GetDtlsSrtpCryptoSuite(int* crypto_suite) { 445 bool OpenSSLStreamAdapter::GetDtlsSrtpCryptoSuite(int* crypto_suite) {
446 #ifdef HAVE_DTLS_SRTP
339 ASSERT(state_ == SSL_CONNECTED); 447 ASSERT(state_ == SSL_CONNECTED);
340 if (state_ != SSL_CONNECTED) 448 if (state_ != SSL_CONNECTED)
341 return false; 449 return false;
342 450
343 const SRTP_PROTECTION_PROFILE *srtp_profile = 451 const SRTP_PROTECTION_PROFILE *srtp_profile =
344 SSL_get_selected_srtp_profile(ssl_); 452 SSL_get_selected_srtp_profile(ssl_);
345 453
346 if (!srtp_profile) 454 if (!srtp_profile)
347 return false; 455 return false;
348 456
349 *crypto_suite = srtp_profile->id; 457 *crypto_suite = srtp_profile->id;
350 ASSERT(!SrtpCryptoSuiteToName(*crypto_suite).empty()); 458 ASSERT(!SrtpCryptoSuiteToName(*crypto_suite).empty());
351 return true; 459 return true;
460 #else
461 return false;
462 #endif
352 } 463 }
353 464
354 int OpenSSLStreamAdapter::StartSSLWithServer(const char* server_name) { 465 int OpenSSLStreamAdapter::StartSSLWithServer(const char* server_name) {
355 ASSERT(server_name != NULL && server_name[0] != '\0'); 466 ASSERT(server_name != NULL && server_name[0] != '\0');
356 ssl_server_name_ = server_name; 467 ssl_server_name_ = server_name;
357 return StartSSL(); 468 return StartSSL();
358 } 469 }
359 470
360 int OpenSSLStreamAdapter::StartSSLWithPeer() { 471 int OpenSSLStreamAdapter::StartSSLWithPeer() {
361 ASSERT(ssl_server_name_.empty()); 472 ASSERT(ssl_server_name_.empty());
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 765
655 ssl_ = SSL_new(ssl_ctx_); 766 ssl_ = SSL_new(ssl_ctx_);
656 if (!ssl_) { 767 if (!ssl_) {
657 BIO_free(bio); 768 BIO_free(bio);
658 return -1; 769 return -1;
659 } 770 }
660 771
661 SSL_set_app_data(ssl_, this); 772 SSL_set_app_data(ssl_, this);
662 773
663 SSL_set_bio(ssl_, bio, bio); // the SSL object owns the bio now. 774 SSL_set_bio(ssl_, bio, bio); // the SSL object owns the bio now.
775 #ifndef OPENSSL_IS_BORINGSSL
776 if (ssl_mode_ == SSL_MODE_DTLS) {
777 // Enable read-ahead for DTLS so whole packets are read from internal BIO
778 // before parsing. This is done internally by BoringSSL for DTLS.
779 SSL_set_read_ahead(ssl_, 1);
780 }
781 #endif
664 782
665 SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE | 783 SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE |
666 SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); 784 SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
667 785
668 // Specify an ECDH group for ECDHE ciphers, otherwise they cannot be 786 // Specify an ECDH group for ECDHE ciphers, otherwise they cannot be
669 // negotiated when acting as the server. Use NIST's P-256 which is commonly 787 // negotiated when acting as the server. Use NIST's P-256 which is commonly
670 // supported. 788 // supported.
671 EC_KEY* ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); 789 EC_KEY* ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
672 if (ecdh == NULL) 790 if (ecdh == NULL)
673 return -1; 791 return -1;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 DTLSv1_handle_timeout(ssl_); 891 DTLSv1_handle_timeout(ssl_);
774 ContinueSSL(); 892 ContinueSSL();
775 } else { 893 } else {
776 StreamInterface::OnMessage(msg); 894 StreamInterface::OnMessage(msg);
777 } 895 }
778 } 896 }
779 897
780 SSL_CTX* OpenSSLStreamAdapter::SetupSSLContext() { 898 SSL_CTX* OpenSSLStreamAdapter::SetupSSLContext() {
781 SSL_CTX *ctx = NULL; 899 SSL_CTX *ctx = NULL;
782 900
901 #ifdef OPENSSL_IS_BORINGSSL
783 ctx = SSL_CTX_new(ssl_mode_ == SSL_MODE_DTLS ? 902 ctx = SSL_CTX_new(ssl_mode_ == SSL_MODE_DTLS ?
784 DTLS_method() : TLS_method()); 903 DTLS_method() : TLS_method());
785 // Version limiting for BoringSSL will be done below. 904 // Version limiting for BoringSSL will be done below.
905 #else
906 const SSL_METHOD* method;
907 switch (ssl_max_version_) {
908 case SSL_PROTOCOL_TLS_10:
909 case SSL_PROTOCOL_TLS_11:
910 // OpenSSL doesn't support setting min/max versions, so we always use
911 // (D)TLS 1.0 if a max. version below the max. available is requested.
912 if (ssl_mode_ == SSL_MODE_DTLS) {
913 if (role_ == SSL_CLIENT) {
914 method = DTLSv1_client_method();
915 } else {
916 method = DTLSv1_server_method();
917 }
918 } else {
919 if (role_ == SSL_CLIENT) {
920 method = TLSv1_client_method();
921 } else {
922 method = TLSv1_server_method();
923 }
924 }
925 break;
926 case SSL_PROTOCOL_TLS_12:
927 default:
928 if (ssl_mode_ == SSL_MODE_DTLS) {
929 #if (OPENSSL_VERSION_NUMBER >= 0x10002000L)
930 // DTLS 1.2 only available starting from OpenSSL 1.0.2
931 if (role_ == SSL_CLIENT) {
932 method = DTLS_client_method();
933 } else {
934 method = DTLS_server_method();
935 }
936 #else
937 if (role_ == SSL_CLIENT) {
938 method = DTLSv1_client_method();
939 } else {
940 method = DTLSv1_server_method();
941 }
942 #endif
943 } else {
944 #if (OPENSSL_VERSION_NUMBER >= 0x10100000L)
945 // New API only available starting from OpenSSL 1.1.0
946 if (role_ == SSL_CLIENT) {
947 method = TLS_client_method();
948 } else {
949 method = TLS_server_method();
950 }
951 #else
952 if (role_ == SSL_CLIENT) {
953 method = SSLv23_client_method();
954 } else {
955 method = SSLv23_server_method();
956 }
957 #endif
958 }
959 break;
960 }
961 ctx = SSL_CTX_new(method);
962 #endif // OPENSSL_IS_BORINGSSL
786 963
787 if (ctx == NULL) 964 if (ctx == NULL)
788 return NULL; 965 return NULL;
789 966
967 #ifdef OPENSSL_IS_BORINGSSL
790 SSL_CTX_set_min_version(ctx, ssl_mode_ == SSL_MODE_DTLS ? 968 SSL_CTX_set_min_version(ctx, ssl_mode_ == SSL_MODE_DTLS ?
791 DTLS1_VERSION : TLS1_VERSION); 969 DTLS1_VERSION : TLS1_VERSION);
792 switch (ssl_max_version_) { 970 switch (ssl_max_version_) {
793 case SSL_PROTOCOL_TLS_10: 971 case SSL_PROTOCOL_TLS_10:
794 SSL_CTX_set_max_version(ctx, ssl_mode_ == SSL_MODE_DTLS ? 972 SSL_CTX_set_max_version(ctx, ssl_mode_ == SSL_MODE_DTLS ?
795 DTLS1_VERSION : TLS1_VERSION); 973 DTLS1_VERSION : TLS1_VERSION);
796 break; 974 break;
797 case SSL_PROTOCOL_TLS_11: 975 case SSL_PROTOCOL_TLS_11:
798 SSL_CTX_set_max_version(ctx, ssl_mode_ == SSL_MODE_DTLS ? 976 SSL_CTX_set_max_version(ctx, ssl_mode_ == SSL_MODE_DTLS ?
799 DTLS1_VERSION : TLS1_1_VERSION); 977 DTLS1_VERSION : TLS1_1_VERSION);
800 break; 978 break;
801 case SSL_PROTOCOL_TLS_12: 979 case SSL_PROTOCOL_TLS_12:
802 default: 980 default:
803 SSL_CTX_set_max_version(ctx, ssl_mode_ == SSL_MODE_DTLS ? 981 SSL_CTX_set_max_version(ctx, ssl_mode_ == SSL_MODE_DTLS ?
804 DTLS1_2_VERSION : TLS1_2_VERSION); 982 DTLS1_2_VERSION : TLS1_2_VERSION);
805 break; 983 break;
806 } 984 }
985 #endif
807 986
808 if (identity_ && !identity_->ConfigureIdentity(ctx)) { 987 if (identity_ && !identity_->ConfigureIdentity(ctx)) {
809 SSL_CTX_free(ctx); 988 SSL_CTX_free(ctx);
810 return NULL; 989 return NULL;
811 } 990 }
812 991
813 #if !defined(NDEBUG) 992 #if !defined(NDEBUG)
814 SSL_CTX_set_info_callback(ctx, OpenSSLAdapter::SSLInfoCallback); 993 SSL_CTX_set_info_callback(ctx, OpenSSLAdapter::SSLInfoCallback);
815 #endif 994 #endif
816 995
817 int mode = SSL_VERIFY_PEER; 996 int mode = SSL_VERIFY_PEER;
818 if (client_auth_enabled()) { 997 if (client_auth_enabled()) {
819 // Require a certificate from the client. 998 // Require a certificate from the client.
820 // Note: Normally this is always true in production, but it may be disabled 999 // Note: Normally this is always true in production, but it may be disabled
821 // for testing purposes (e.g. SSLAdapter unit tests). 1000 // for testing purposes (e.g. SSLAdapter unit tests).
822 mode |= SSL_VERIFY_FAIL_IF_NO_PEER_CERT; 1001 mode |= SSL_VERIFY_FAIL_IF_NO_PEER_CERT;
823 } 1002 }
824 1003
825 SSL_CTX_set_verify(ctx, mode, SSLVerifyCallback); 1004 SSL_CTX_set_verify(ctx, mode, SSLVerifyCallback);
826 SSL_CTX_set_verify_depth(ctx, 4); 1005 SSL_CTX_set_verify_depth(ctx, 4);
827 // Select list of available ciphers. Note that !SHA256 and !SHA384 only 1006 // Select list of available ciphers. Note that !SHA256 and !SHA384 only
828 // remove HMAC-SHA256 and HMAC-SHA384 cipher suites, not GCM cipher suites 1007 // remove HMAC-SHA256 and HMAC-SHA384 cipher suites, not GCM cipher suites
829 // with SHA256 or SHA384 as the handshake hash. 1008 // with SHA256 or SHA384 as the handshake hash.
830 // This matches the list of SSLClientSocketOpenSSL in Chromium. 1009 // This matches the list of SSLClientSocketOpenSSL in Chromium.
831 SSL_CTX_set_cipher_list(ctx, 1010 SSL_CTX_set_cipher_list(ctx,
832 "DEFAULT:!NULL:!aNULL:!SHA256:!SHA384:!aECDH:!AESGCM+AES256:!aPSK"); 1011 "DEFAULT:!NULL:!aNULL:!SHA256:!SHA384:!aECDH:!AESGCM+AES256:!aPSK");
833 1012
1013 #ifdef HAVE_DTLS_SRTP
834 if (!srtp_ciphers_.empty()) { 1014 if (!srtp_ciphers_.empty()) {
835 if (SSL_CTX_set_tlsext_use_srtp(ctx, srtp_ciphers_.c_str())) { 1015 if (SSL_CTX_set_tlsext_use_srtp(ctx, srtp_ciphers_.c_str())) {
836 SSL_CTX_free(ctx); 1016 SSL_CTX_free(ctx);
837 return NULL; 1017 return NULL;
838 } 1018 }
839 } 1019 }
1020 #endif
840 1021
841 return ctx; 1022 return ctx;
842 } 1023 }
843 1024
844 int OpenSSLStreamAdapter::SSLVerifyCallback(int ok, X509_STORE_CTX* store) { 1025 int OpenSSLStreamAdapter::SSLVerifyCallback(int ok, X509_STORE_CTX* store) {
845 // Get our SSL structure from the store 1026 // Get our SSL structure from the store
846 SSL* ssl = reinterpret_cast<SSL*>(X509_STORE_CTX_get_ex_data( 1027 SSL* ssl = reinterpret_cast<SSL*>(X509_STORE_CTX_get_ex_data(
847 store, 1028 store,
848 SSL_get_ex_data_X509_STORE_CTX_idx())); 1029 SSL_get_ex_data_X509_STORE_CTX_idx()));
849 OpenSSLStreamAdapter* stream = 1030 OpenSSLStreamAdapter* stream =
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } 1102 }
922 1103
923 return ok; 1104 return ok;
924 } 1105 }
925 1106
926 bool OpenSSLStreamAdapter::HaveDtls() { 1107 bool OpenSSLStreamAdapter::HaveDtls() {
927 return true; 1108 return true;
928 } 1109 }
929 1110
930 bool OpenSSLStreamAdapter::HaveDtlsSrtp() { 1111 bool OpenSSLStreamAdapter::HaveDtlsSrtp() {
1112 #ifdef HAVE_DTLS_SRTP
931 return true; 1113 return true;
1114 #else
1115 return false;
1116 #endif
932 } 1117 }
933 1118
934 bool OpenSSLStreamAdapter::HaveExporter() { 1119 bool OpenSSLStreamAdapter::HaveExporter() {
1120 #ifdef HAVE_DTLS_SRTP
935 return true; 1121 return true;
1122 #else
1123 return false;
1124 #endif
936 } 1125 }
937 1126
938 #define CDEF(X) \ 1127 #define CDEF(X) \
939 { static_cast<uint16_t>(TLS1_CK_##X & 0xffff), "TLS_" #X } 1128 { static_cast<uint16_t>(TLS1_CK_##X & 0xffff), "TLS_" #X }
940 1129
941 struct cipher_list { 1130 struct cipher_list {
942 uint16_t cipher; 1131 uint16_t cipher;
943 const char* cipher_str; 1132 const char* cipher_str;
944 }; 1133 };
945 1134
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 return true; 1187 return true;
999 } 1188 }
1000 } 1189 }
1001 1190
1002 return false; 1191 return false;
1003 } 1192 }
1004 1193
1005 } // namespace rtc 1194 } // namespace rtc
1006 1195
1007 #endif // HAVE_OPENSSL_SSL_H 1196 #endif // HAVE_OPENSSL_SSL_H
OLDNEW
« no previous file with comments | « webrtc/base/opensslidentity.cc ('k') | webrtc/base/ssladapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698