Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 | 51 |
| 52 // This isn't elegant, but it's better than an external reference | 52 // This isn't elegant, but it's better than an external reference |
| 53 static SrtpCipherMapEntry SrtpCipherMap[] = { | 53 static SrtpCipherMapEntry SrtpCipherMap[] = { |
| 54 {"AES_CM_128_HMAC_SHA1_80", "SRTP_AES128_CM_SHA1_80"}, | 54 {"AES_CM_128_HMAC_SHA1_80", "SRTP_AES128_CM_SHA1_80"}, |
| 55 {"AES_CM_128_HMAC_SHA1_32", "SRTP_AES128_CM_SHA1_32"}, | 55 {"AES_CM_128_HMAC_SHA1_32", "SRTP_AES128_CM_SHA1_32"}, |
| 56 {NULL, NULL} | 56 {NULL, NULL} |
| 57 }; | 57 }; |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 #ifndef OPENSSL_IS_BORINGSSL | 60 #ifndef OPENSSL_IS_BORINGSSL |
| 61 // Cipher name table. Maps internal OpenSSL cipher ids to the RFC name. | |
| 62 struct SslCipherMapEntry { | |
| 63 uint32_t openssl_id; | |
| 64 const char* rfc_name; | |
| 65 }; | |
| 66 | 61 |
| 67 #define DEFINE_CIPHER_ENTRY_SSL3(name) {SSL3_CK_##name, "TLS_"#name} | 62 #define DEFINE_CIPHER_ENTRY_SSL3(name) {SSL3_CK_##name, "TLS_"#name} |
| 68 #define DEFINE_CIPHER_ENTRY_TLS1(name) {TLS1_CK_##name, "TLS_"#name} | 63 #define DEFINE_CIPHER_ENTRY_TLS1(name) {TLS1_CK_##name, "TLS_"#name} |
| 69 | 64 |
| 70 // There currently is no method available to get a RFC-compliant name for a | 65 // There currently is no method available to get a RFC-compliant name for a |
| 71 // cipher suite from BoringSSL, so we need to define the mapping manually here. | 66 // cipher suite from BoringSSL, so we need to define the mapping manually here. |
| 72 // This should go away once BoringSSL supports "SSL_CIPHER_standard_name" | 67 // This should go away once BoringSSL supports "SSL_CIPHER_standard_name" |
| 73 // (as available in OpenSSL if compiled with tracing enabled) or a similar | 68 // (as available in OpenSSL if compiled with tracing enabled) or a similar |
| 74 // method. | 69 // method. |
| 75 static const SslCipherMapEntry kSslCipherMap[] = { | 70 static const SslCipherMapEntry kSslCipherMap[] = { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 // ECDH GCM based ciphersuites from RFC5289. | 127 // ECDH GCM based ciphersuites from RFC5289. |
| 133 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_128_GCM_SHA256), | 128 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_128_GCM_SHA256), |
| 134 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_256_GCM_SHA384), | 129 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_256_GCM_SHA384), |
| 135 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_128_GCM_SHA256), | 130 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_128_GCM_SHA256), |
| 136 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_256_GCM_SHA384), | 131 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_256_GCM_SHA384), |
| 137 | 132 |
| 138 {0, NULL} | 133 {0, NULL} |
| 139 }; | 134 }; |
| 140 #endif // #ifndef OPENSSL_IS_BORINGSSL | 135 #endif // #ifndef OPENSSL_IS_BORINGSSL |
| 141 | 136 |
| 137 // TLS_NULL_WITH_NULL_NULL provides no more protection than an unsecured | |
| 138 // connection. Must not be negotiated. | |
| 139 static const SslCipher kNullSslCipher = {0, "TLS_NULL_WITH_NULL_NULL"}; | |
| 140 | |
| 142 // Default cipher used between OpenSSL/BoringSSL stream adapters. | 141 // Default cipher used between OpenSSL/BoringSSL stream adapters. |
| 143 // This needs to be updated when the default of the SSL library changes. | 142 // This needs to be updated when the default of the SSL library changes. |
| 144 static const char kDefaultSslCipher10[] = | 143 static const SslCipher kDefaultSslCipher10 = { |
| 145 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"; | 144 0xC014, |
|
juberti
2015/09/24 13:41:15
The fact we need to get the id and name right here
guoweis_webrtc
2015/09/24 18:27:13
Problem is that when doing the verification of UMA
juberti
2015/09/24 21:37:31
This still seems like a bad path. I could totally
| |
| 146 static const char kDefaultSslEcCipher10[] = | 145 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"}; |
| 147 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"; | 146 static const SslCipher kDefaultSslEcCipher10 = { |
| 147 0xC00A, | |
| 148 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"}; | |
| 148 | 149 |
| 149 #ifdef OPENSSL_IS_BORINGSSL | 150 #ifdef OPENSSL_IS_BORINGSSL |
| 150 static const char kDefaultSslCipher12[] = | 151 static const SslCipher kDefaultSslCipher12 = { |
| 151 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"; | 152 0xC02F, |
| 152 static const char kDefaultSslEcCipher12[] = | 153 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"}; |
| 153 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"; | 154 static const SslCipher kDefaultSslEcCipher12 = { |
| 155 0xC02B, | |
| 156 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"}; | |
| 154 // Fallback cipher for DTLS 1.2 if hardware-accelerated AES-GCM is unavailable. | 157 // Fallback cipher for DTLS 1.2 if hardware-accelerated AES-GCM is unavailable. |
| 155 static const char kDefaultSslCipher12NoAesGcm[] = | 158 static const SslCipher kDefaultSslCipher12NoAesGcm = { |
| 156 "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"; | 159 0xCC13, |
| 157 static const char kDefaultSslEcCipher12NoAesGcm[] = | 160 "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"}; |
| 158 "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"; | 161 static const SslCipher kDefaultSslEcCipher12NoAesGcm = { |
| 162 0xCC14, | |
| 163 "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"}; | |
| 159 #else // !OPENSSL_IS_BORINGSSL | 164 #else // !OPENSSL_IS_BORINGSSL |
| 160 // OpenSSL sorts differently than BoringSSL, so the default cipher doesn't | 165 // OpenSSL sorts differently than BoringSSL, so the default cipher doesn't |
| 161 // change between TLS 1.0 and TLS 1.2 with the current setup. | 166 // change between TLS 1.0 and TLS 1.2 with the current setup. |
| 162 static const char kDefaultSslCipher12[] = | 167 static const SslCipher kDefaultSslCipher12 = { |
| 163 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"; | 168 0xC014, |
| 164 static const char kDefaultSslEcCipher12[] = | 169 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"}; |
| 165 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"; | 170 static const SslCipher kDefaultSslEcCipher12 = { |
| 171 0xC00A, | |
| 172 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"}; | |
| 166 #endif | 173 #endif |
| 167 | 174 |
| 168 ////////////////////////////////////////////////////////////////////// | 175 ////////////////////////////////////////////////////////////////////// |
| 169 // StreamBIO | 176 // StreamBIO |
| 170 ////////////////////////////////////////////////////////////////////// | 177 ////////////////////////////////////////////////////////////////////// |
| 171 | 178 |
| 172 static int stream_write(BIO* h, const char* buf, int num); | 179 static int stream_write(BIO* h, const char* buf, int num); |
| 173 static int stream_read(BIO* h, char* buf, int size); | 180 static int stream_read(BIO* h, char* buf, int size); |
| 174 static int stream_puts(BIO* h, const char* str); | 181 static int stream_puts(BIO* h, const char* str); |
| 175 static long stream_ctrl(BIO* h, int cmd, long arg1, void* arg2); | 182 static long stream_ctrl(BIO* h, int cmd, long arg1, void* arg2); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 for (const SslCipherMapEntry* entry = kSslCipherMap; entry->rfc_name; | 352 for (const SslCipherMapEntry* entry = kSslCipherMap; entry->rfc_name; |
| 346 ++entry) { | 353 ++entry) { |
| 347 if (cipher->id == entry->openssl_id) { | 354 if (cipher->id == entry->openssl_id) { |
| 348 return entry->rfc_name; | 355 return entry->rfc_name; |
| 349 } | 356 } |
| 350 } | 357 } |
| 351 return NULL; | 358 return NULL; |
| 352 } | 359 } |
| 353 #endif | 360 #endif |
| 354 | 361 |
| 355 bool OpenSSLStreamAdapter::GetSslCipher(std::string* cipher) { | 362 bool OpenSSLStreamAdapter::GetSslCipher(SslCipher* cipher) { |
| 356 if (state_ != SSL_CONNECTED) | 363 if (state_ != SSL_CONNECTED) |
| 357 return false; | 364 return false; |
| 358 | 365 |
| 359 const SSL_CIPHER* current_cipher = SSL_get_current_cipher(ssl_); | 366 const SSL_CIPHER* current_cipher = SSL_get_current_cipher(ssl_); |
| 360 if (current_cipher == NULL) { | 367 if (current_cipher == NULL) { |
| 361 return false; | 368 return false; |
| 362 } | 369 } |
| 363 | 370 |
| 371 cipher->ssl_id = static_cast<uint16_t>(SSL_CIPHER_get_id(current_cipher)); | |
| 372 | |
| 364 #ifdef OPENSSL_IS_BORINGSSL | 373 #ifdef OPENSSL_IS_BORINGSSL |
| 365 char* cipher_name = SSL_CIPHER_get_rfc_name(current_cipher); | 374 char* cipher_name = SSL_CIPHER_get_rfc_name(current_cipher); |
| 366 #else | 375 #else |
| 367 const char* cipher_name = GetRfcSslCipherName(current_cipher); | 376 const char* cipher_name = GetRfcSslCipherName(current_cipher); |
| 368 #endif | 377 #endif |
| 369 if (cipher_name == NULL) { | 378 if (cipher_name == NULL) { |
| 370 return false; | 379 return false; |
| 371 } | 380 } |
| 372 | 381 |
| 373 *cipher = cipher_name; | 382 cipher->rfc_name = cipher_name; |
| 374 #ifdef OPENSSL_IS_BORINGSSL | 383 #ifdef OPENSSL_IS_BORINGSSL |
| 375 OPENSSL_free(cipher_name); | 384 OPENSSL_free(cipher_name); |
| 376 #endif | 385 #endif |
| 377 return true; | 386 return true; |
| 378 } | 387 } |
| 379 | 388 |
| 380 // Key Extractor interface | 389 // Key Extractor interface |
| 381 bool OpenSSLStreamAdapter::ExportKeyingMaterial(const std::string& label, | 390 bool OpenSSLStreamAdapter::ExportKeyingMaterial(const std::string& label, |
| 382 const uint8* context, | 391 const uint8* context, |
| 383 size_t context_len, | 392 size_t context_len, |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1118 } | 1127 } |
| 1119 | 1128 |
| 1120 bool OpenSSLStreamAdapter::HaveExporter() { | 1129 bool OpenSSLStreamAdapter::HaveExporter() { |
| 1121 #ifdef HAVE_DTLS_SRTP | 1130 #ifdef HAVE_DTLS_SRTP |
| 1122 return true; | 1131 return true; |
| 1123 #else | 1132 #else |
| 1124 return false; | 1133 return false; |
| 1125 #endif | 1134 #endif |
| 1126 } | 1135 } |
| 1127 | 1136 |
| 1128 std::string OpenSSLStreamAdapter::GetDefaultSslCipher( | 1137 const SslCipher& OpenSSLStreamAdapter::GetDefaultSslCipher( |
| 1129 SSLProtocolVersion version, | 1138 SSLProtocolVersion version, |
| 1130 KeyType key_type) { | 1139 KeyType key_type) { |
| 1131 if (key_type == KT_RSA) { | 1140 if (key_type == KT_RSA) { |
| 1132 switch (version) { | 1141 switch (version) { |
| 1133 case SSL_PROTOCOL_TLS_10: | 1142 case SSL_PROTOCOL_TLS_10: |
| 1134 case SSL_PROTOCOL_TLS_11: | 1143 case SSL_PROTOCOL_TLS_11: |
| 1135 return kDefaultSslCipher10; | 1144 return kDefaultSslCipher10; |
| 1136 case SSL_PROTOCOL_TLS_12: | 1145 case SSL_PROTOCOL_TLS_12: |
| 1137 default: | 1146 default: |
| 1138 #ifdef OPENSSL_IS_BORINGSSL | 1147 #ifdef OPENSSL_IS_BORINGSSL |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1156 if (EVP_has_aes_hardware()) { | 1165 if (EVP_has_aes_hardware()) { |
| 1157 return kDefaultSslEcCipher12; | 1166 return kDefaultSslEcCipher12; |
| 1158 } else { | 1167 } else { |
| 1159 return kDefaultSslEcCipher12NoAesGcm; | 1168 return kDefaultSslEcCipher12NoAesGcm; |
| 1160 } | 1169 } |
| 1161 #else // !OPENSSL_IS_BORINGSSL | 1170 #else // !OPENSSL_IS_BORINGSSL |
| 1162 return kDefaultSslEcCipher12; | 1171 return kDefaultSslEcCipher12; |
| 1163 #endif | 1172 #endif |
| 1164 } | 1173 } |
| 1165 } else { | 1174 } else { |
| 1166 return std::string(); | 1175 RTC_NOTREACHED(); |
| 1176 return kNullSslCipher; | |
| 1167 } | 1177 } |
| 1168 } | 1178 } |
| 1169 | 1179 |
| 1170 } // namespace rtc | 1180 } // namespace rtc |
| 1171 | 1181 |
| 1172 #endif // HAVE_OPENSSL_SSL_H | 1182 #endif // HAVE_OPENSSL_SSL_H |
| OLD | NEW |