| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 #ifdef HAVE_DTLS_SRTP | 45 #ifdef HAVE_DTLS_SRTP |
| 46 // SRTP cipher suite table | 46 // SRTP cipher suite table |
| 47 struct SrtpCipherMapEntry { | 47 struct SrtpCipherMapEntry { |
| 48 const char* external_name; | 48 const char* external_name; |
| 49 const char* internal_name; | 49 const char* internal_name; |
| 50 }; | 50 }; |
| 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 {CS_AES_CM_128_HMAC_SHA1_80, "SRTP_AES128_CM_SHA1_80"}, |
| 55 {"AES_CM_128_HMAC_SHA1_32", "SRTP_AES128_CM_SHA1_32"}, | 55 {CS_AES_CM_128_HMAC_SHA1_32, "SRTP_AES128_CM_SHA1_32"}, |
| 56 {NULL, NULL} | 56 {NULL, NULL}}; |
| 57 }; | |
| 58 #endif | 57 #endif |
| 59 | 58 |
| 60 #ifndef OPENSSL_IS_BORINGSSL | 59 #ifndef OPENSSL_IS_BORINGSSL |
| 60 |
| 61 // Cipher name table. Maps internal OpenSSL cipher ids to the RFC name. | 61 // Cipher name table. Maps internal OpenSSL cipher ids to the RFC name. |
| 62 struct SslCipherMapEntry { | 62 struct SslCipherMapEntry { |
| 63 uint32_t openssl_id; | 63 uint32_t openssl_id; |
| 64 const char* rfc_name; | 64 const char* rfc_name; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 #define DEFINE_CIPHER_ENTRY_SSL3(name) {SSL3_CK_##name, "TLS_"#name} | 67 #define DEFINE_CIPHER_ENTRY_SSL3(name) {SSL3_CK_##name, "TLS_"#name} |
| 68 #define DEFINE_CIPHER_ENTRY_TLS1(name) {TLS1_CK_##name, "TLS_"#name} | 68 #define DEFINE_CIPHER_ENTRY_TLS1(name) {TLS1_CK_##name, "TLS_"#name} |
| 69 | 69 |
| 70 // There currently is no method available to get a RFC-compliant name for a | 70 // There currently is no method available to get a RFC-compliant name for a |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // ECDH GCM based ciphersuites from RFC5289. | 132 // ECDH GCM based ciphersuites from RFC5289. |
| 133 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_128_GCM_SHA256), | 133 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_128_GCM_SHA256), |
| 134 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_256_GCM_SHA384), | 134 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_ECDSA_WITH_AES_256_GCM_SHA384), |
| 135 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_128_GCM_SHA256), | 135 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_128_GCM_SHA256), |
| 136 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_256_GCM_SHA384), | 136 DEFINE_CIPHER_ENTRY_TLS1(ECDHE_RSA_WITH_AES_256_GCM_SHA384), |
| 137 | 137 |
| 138 {0, NULL} | 138 {0, NULL} |
| 139 }; | 139 }; |
| 140 #endif // #ifndef OPENSSL_IS_BORINGSSL | 140 #endif // #ifndef OPENSSL_IS_BORINGSSL |
| 141 | 141 |
| 142 #if defined(_MSC_VER) |
| 143 #pragma warning(push) |
| 144 #pragma warning(disable : 4309) |
| 145 #pragma warning(disable : 4310) |
| 146 #endif // defined(_MSC_VER) |
| 147 |
| 142 // Default cipher used between OpenSSL/BoringSSL stream adapters. | 148 // Default cipher used between OpenSSL/BoringSSL stream adapters. |
| 143 // This needs to be updated when the default of the SSL library changes. | 149 // This needs to be updated when the default of the SSL library changes. |
| 144 static const char kDefaultSslCipher10[] = | 150 // static_cast<uint16_t> causes build warnings on windows platform. |
| 145 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"; | 151 static uint16_t kDefaultSslCipher10 = |
| 146 static const char kDefaultSslEcCipher10[] = | 152 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA); |
| 147 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"; | 153 static uint16_t kDefaultSslEcCipher10 = |
| 148 | 154 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA); |
| 149 #ifdef OPENSSL_IS_BORINGSSL | 155 #ifdef OPENSSL_IS_BORINGSSL |
| 150 static const char kDefaultSslCipher12[] = | 156 static uint16_t kDefaultSslCipher12 = |
| 151 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"; | 157 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256); |
| 152 static const char kDefaultSslEcCipher12[] = | 158 static uint16_t kDefaultSslEcCipher12 = |
| 153 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"; | 159 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256); |
| 154 // Fallback cipher for DTLS 1.2 if hardware-accelerated AES-GCM is unavailable. | 160 // Fallback cipher for DTLS 1.2 if hardware-accelerated AES-GCM is unavailable. |
| 155 static const char kDefaultSslCipher12NoAesGcm[] = | 161 static uint16_t kDefaultSslCipher12NoAesGcm = |
| 156 "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"; | 162 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305); |
| 157 static const char kDefaultSslEcCipher12NoAesGcm[] = | 163 static uint16_t kDefaultSslEcCipher12NoAesGcm = |
| 158 "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"; | 164 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305); |
| 159 #else // !OPENSSL_IS_BORINGSSL | 165 #else // !OPENSSL_IS_BORINGSSL |
| 160 // OpenSSL sorts differently than BoringSSL, so the default cipher doesn't | 166 // 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. | 167 // change between TLS 1.0 and TLS 1.2 with the current setup. |
| 162 static const char kDefaultSslCipher12[] = | 168 static uint16_t kDefaultSslCipher12 = |
| 163 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"; | 169 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA); |
| 164 static const char kDefaultSslEcCipher12[] = | 170 static uint16_t kDefaultSslEcCipher12 = |
| 165 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"; | 171 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA); |
| 166 #endif | 172 #endif |
| 167 | 173 |
| 174 #if defined(_MSC_VER) |
| 175 #pragma warning(pop) |
| 176 #endif // defined(_MSC_VER) |
| 177 |
| 168 ////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////// |
| 169 // StreamBIO | 179 // StreamBIO |
| 170 ////////////////////////////////////////////////////////////////////// | 180 ////////////////////////////////////////////////////////////////////// |
| 171 | 181 |
| 172 static int stream_write(BIO* h, const char* buf, int num); | 182 static int stream_write(BIO* h, const char* buf, int num); |
| 173 static int stream_read(BIO* h, char* buf, int size); | 183 static int stream_read(BIO* h, char* buf, int size); |
| 174 static int stream_puts(BIO* h, const char* str); | 184 static int stream_puts(BIO* h, const char* str); |
| 175 static long stream_ctrl(BIO* h, int cmd, long arg1, void* arg2); | 185 static long stream_ctrl(BIO* h, int cmd, long arg1, void* arg2); |
| 176 static int stream_new(BIO* h); | 186 static int stream_new(BIO* h); |
| 177 static int stream_free(BIO* data); | 187 static int stream_free(BIO* data); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 341 } |
| 332 if (expected_len != digest_len) | 342 if (expected_len != digest_len) |
| 333 return false; | 343 return false; |
| 334 | 344 |
| 335 peer_certificate_digest_value_.SetData(digest_val, digest_len); | 345 peer_certificate_digest_value_.SetData(digest_val, digest_len); |
| 336 peer_certificate_digest_algorithm_ = digest_alg; | 346 peer_certificate_digest_algorithm_ = digest_alg; |
| 337 | 347 |
| 338 return true; | 348 return true; |
| 339 } | 349 } |
| 340 | 350 |
| 341 #ifndef OPENSSL_IS_BORINGSSL | 351 std::string OpenSSLStreamAdapter::GetSslCipherSuiteName(uint16_t cipher) { |
| 342 const char* OpenSSLStreamAdapter::GetRfcSslCipherName( | 352 #ifdef OPENSSL_IS_BORINGSSL |
| 343 const SSL_CIPHER* cipher) { | 353 const SSL_CIPHER* ssl_cipher = SSL_get_cipher_by_value(cipher); |
| 354 if (!ssl_cipher) { |
| 355 return std::string(); |
| 356 } |
| 357 char* cipher_name = SSL_CIPHER_get_rfc_name(ssl_cipher); |
| 358 std::string rfc_name = std::string(cipher_name); |
| 359 OPENSSL_free(cipher_name); |
| 360 return rfc_name; |
| 361 #else |
| 344 ASSERT(cipher != NULL); | 362 ASSERT(cipher != NULL); |
| 345 for (const SslCipherMapEntry* entry = kSslCipherMap; entry->rfc_name; | 363 for (const SslCipherMapEntry* entry = kSslCipherMap; entry->rfc_name; |
| 346 ++entry) { | 364 ++entry) { |
| 347 if (cipher->id == entry->openssl_id) { | 365 if (cipher->id == entry->openssl_id) { |
| 348 return entry->rfc_name; | 366 return entry->rfc_name; |
| 349 } | 367 } |
| 350 } | 368 } |
| 351 return NULL; | 369 return std::string(); |
| 370 #endif |
| 352 } | 371 } |
| 353 #endif | |
| 354 | 372 |
| 355 bool OpenSSLStreamAdapter::GetSslCipher(std::string* cipher) { | 373 bool OpenSSLStreamAdapter::GetSslCipherSuite(uint16_t* cipher) { |
| 356 if (state_ != SSL_CONNECTED) | 374 if (state_ != SSL_CONNECTED) |
| 357 return false; | 375 return false; |
| 358 | 376 |
| 359 const SSL_CIPHER* current_cipher = SSL_get_current_cipher(ssl_); | 377 const SSL_CIPHER* current_cipher = SSL_get_current_cipher(ssl_); |
| 360 if (current_cipher == NULL) { | 378 if (current_cipher == NULL) { |
| 361 return false; | 379 return false; |
| 362 } | 380 } |
| 363 | 381 |
| 364 #ifdef OPENSSL_IS_BORINGSSL | 382 *cipher = static_cast<uint16_t>(SSL_CIPHER_get_id(current_cipher)); |
| 365 char* cipher_name = SSL_CIPHER_get_rfc_name(current_cipher); | |
| 366 #else | |
| 367 const char* cipher_name = GetRfcSslCipherName(current_cipher); | |
| 368 #endif | |
| 369 if (cipher_name == NULL) { | |
| 370 return false; | |
| 371 } | |
| 372 | |
| 373 *cipher = cipher_name; | |
| 374 #ifdef OPENSSL_IS_BORINGSSL | |
| 375 OPENSSL_free(cipher_name); | |
| 376 #endif | |
| 377 return true; | 383 return true; |
| 378 } | 384 } |
| 379 | 385 |
| 380 // Key Extractor interface | 386 // Key Extractor interface |
| 381 bool OpenSSLStreamAdapter::ExportKeyingMaterial(const std::string& label, | 387 bool OpenSSLStreamAdapter::ExportKeyingMaterial(const std::string& label, |
| 382 const uint8* context, | 388 const uint8* context, |
| 383 size_t context_len, | 389 size_t context_len, |
| 384 bool use_context, | 390 bool use_context, |
| 385 uint8* result, | 391 uint8* result, |
| 386 size_t result_len) { | 392 size_t result_len) { |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 } | 1124 } |
| 1119 | 1125 |
| 1120 bool OpenSSLStreamAdapter::HaveExporter() { | 1126 bool OpenSSLStreamAdapter::HaveExporter() { |
| 1121 #ifdef HAVE_DTLS_SRTP | 1127 #ifdef HAVE_DTLS_SRTP |
| 1122 return true; | 1128 return true; |
| 1123 #else | 1129 #else |
| 1124 return false; | 1130 return false; |
| 1125 #endif | 1131 #endif |
| 1126 } | 1132 } |
| 1127 | 1133 |
| 1128 std::string OpenSSLStreamAdapter::GetDefaultSslCipher( | 1134 uint16_t OpenSSLStreamAdapter::GetDefaultSslCipherForTest( |
| 1129 SSLProtocolVersion version, | 1135 SSLProtocolVersion version, |
| 1130 KeyType key_type) { | 1136 KeyType key_type) { |
| 1131 if (key_type == KT_RSA) { | 1137 if (key_type == KT_RSA) { |
| 1132 switch (version) { | 1138 switch (version) { |
| 1133 case SSL_PROTOCOL_TLS_10: | 1139 case SSL_PROTOCOL_TLS_10: |
| 1134 case SSL_PROTOCOL_TLS_11: | 1140 case SSL_PROTOCOL_TLS_11: |
| 1135 return kDefaultSslCipher10; | 1141 return kDefaultSslCipher10; |
| 1136 case SSL_PROTOCOL_TLS_12: | 1142 case SSL_PROTOCOL_TLS_12: |
| 1137 default: | 1143 default: |
| 1138 #ifdef OPENSSL_IS_BORINGSSL | 1144 #ifdef OPENSSL_IS_BORINGSSL |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1156 if (EVP_has_aes_hardware()) { | 1162 if (EVP_has_aes_hardware()) { |
| 1157 return kDefaultSslEcCipher12; | 1163 return kDefaultSslEcCipher12; |
| 1158 } else { | 1164 } else { |
| 1159 return kDefaultSslEcCipher12NoAesGcm; | 1165 return kDefaultSslEcCipher12NoAesGcm; |
| 1160 } | 1166 } |
| 1161 #else // !OPENSSL_IS_BORINGSSL | 1167 #else // !OPENSSL_IS_BORINGSSL |
| 1162 return kDefaultSslEcCipher12; | 1168 return kDefaultSslEcCipher12; |
| 1163 #endif | 1169 #endif |
| 1164 } | 1170 } |
| 1165 } else { | 1171 } else { |
| 1166 return std::string(); | 1172 RTC_NOTREACHED(); |
| 1173 return kDefaultSslEcCipher12; |
| 1167 } | 1174 } |
| 1168 } | 1175 } |
| 1169 | 1176 |
| 1170 } // namespace rtc | 1177 } // namespace rtc |
| 1171 | 1178 |
| 1172 #endif // HAVE_OPENSSL_SSL_H | 1179 #endif // HAVE_OPENSSL_SSL_H |
| OLD | NEW |