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

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

Issue 1774583002: Add IsAcceptableCipher, use instead of GetDefaultCipher. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Remove kDefaultSsl* constants 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
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 {0, NULL} 140 {0, NULL}
141 }; 141 };
142 #endif // #ifndef OPENSSL_IS_BORINGSSL 142 #endif // #ifndef OPENSSL_IS_BORINGSSL
143 143
144 #if defined(_MSC_VER) 144 #if defined(_MSC_VER)
145 #pragma warning(push) 145 #pragma warning(push)
146 #pragma warning(disable : 4309) 146 #pragma warning(disable : 4309)
147 #pragma warning(disable : 4310) 147 #pragma warning(disable : 4310)
148 #endif // defined(_MSC_VER) 148 #endif // defined(_MSC_VER)
149 149
150 // Default cipher used between OpenSSL/BoringSSL stream adapters.
151 // This needs to be updated when the default of the SSL library changes.
152 // static_cast<uint16_t> causes build warnings on windows platform.
153 static int kDefaultSslCipher10 =
154 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA);
155 static int kDefaultSslEcCipher10 =
156 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
157 #ifdef OPENSSL_IS_BORINGSSL
158 static int kDefaultSslCipher12 =
159 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256);
160 static int kDefaultSslEcCipher12 =
161 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
164 #ifdef TLS1_CK_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
165 // This ciphersuite was added in boringssl 13414b3a..., changing the fallback
166 // ciphersuite. For compatibility during a transitional period, support old
167 // boringssl versions. TODO(torbjorng): Remove this.
168 static int kDefaultSslCipher12NoAesGcm =
169 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256);
170 #else
171 static int kDefaultSslCipher12NoAesGcm =
172 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305_OLD);
173 #endif
174
175 #ifdef TLS1_CK_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
176 // This ciphersuite was added in boringssl 13414b3a..., changing the fallback
177 // ciphersuite. For compatibility during a transitional period, support old
178 // boringssl versions. TODO(torbjorng): Remove this.
179 static int kDefaultSslEcCipher12NoAesGcm =
180 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256);
181 #else
182 static int kDefaultSslEcCipher12NoAesGcm =
183 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305_OLD);
184 #endif
185
186 #else // !OPENSSL_IS_BORINGSSL
187 // OpenSSL sorts differently than BoringSSL, so the default cipher doesn't
188 // change between TLS 1.0 and TLS 1.2 with the current setup.
189 static int kDefaultSslCipher12 =
190 static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA);
191 static int kDefaultSslEcCipher12 =
192 static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
193 #endif // OPENSSL_IS_BORINGSSL
194
195 #if defined(_MSC_VER) 150 #if defined(_MSC_VER)
196 #pragma warning(pop) 151 #pragma warning(pop)
197 #endif // defined(_MSC_VER) 152 #endif // defined(_MSC_VER)
198 153
199 ////////////////////////////////////////////////////////////////////// 154 //////////////////////////////////////////////////////////////////////
200 // StreamBIO 155 // StreamBIO
201 ////////////////////////////////////////////////////////////////////// 156 //////////////////////////////////////////////////////////////////////
202 157
203 static int stream_write(BIO* h, const char* buf, int num); 158 static int stream_write(BIO* h, const char* buf, int num);
204 static int stream_read(BIO* h, char* buf, int size); 159 static int stream_read(BIO* h, char* buf, int size);
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 } 1095 }
1141 1096
1142 bool OpenSSLStreamAdapter::HaveExporter() { 1097 bool OpenSSLStreamAdapter::HaveExporter() {
1143 #ifdef HAVE_DTLS_SRTP 1098 #ifdef HAVE_DTLS_SRTP
1144 return true; 1099 return true;
1145 #else 1100 #else
1146 return false; 1101 return false;
1147 #endif 1102 #endif
1148 } 1103 }
1149 1104
1150 int OpenSSLStreamAdapter::GetDefaultSslCipherForTest(SSLProtocolVersion version, 1105 #define CDEF(X) \
1151 KeyType key_type) { 1106 { static_cast<uint16_t>(TLS1_CK_##X & 0xffff), "TLS_" #X }
1107
1108 struct cipher_list {
1109 uint16_t cipher;
1110 const char* cipher_str;
1111 };
1112
1113 // TODO(torbjorng): Perhaps add more cipher suites to these lists.
1114 static const cipher_list OK_RSA_ciphers[] = {
1115 CDEF(ECDHE_RSA_WITH_AES_128_CBC_SHA),
1116 CDEF(ECDHE_RSA_WITH_AES_256_CBC_SHA),
1117 CDEF(ECDHE_RSA_WITH_AES_128_GCM_SHA256),
1118 #ifdef TLS1_CK_ECDHE_RSA_WITH_AES_256_GCM_SHA256
1119 CDEF(ECDHE_RSA_WITH_AES_256_GCM_SHA256),
1120 #endif
1121 CDEF(ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256),
1122 };
1123
1124 static const cipher_list OK_ECDSA_ciphers[] = {
1125 CDEF(ECDHE_ECDSA_WITH_AES_128_CBC_SHA),
1126 CDEF(ECDHE_ECDSA_WITH_AES_256_CBC_SHA),
1127 CDEF(ECDHE_ECDSA_WITH_AES_128_GCM_SHA256),
1128 #ifdef TLS1_CK_ECDHE_ECDSA_WITH_AES_256_GCM_SHA256
1129 CDEF(ECDHE_ECDSA_WITH_AES_256_GCM_SHA256),
1130 #endif
1131 CDEF(ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256),
1132 };
1133
1134 bool OpenSSLStreamAdapter::IsAcceptableCipher(int cipher,
1135 KeyType key_type) {
davidben_webrtc 2016/03/08 20:29:05 What is the test actually trying to check? Are you
torbjorng (webrtc) 2016/03/09 13:10:31 Mainly I am trying to assert we got a reasonable c
davidben_webrtc 2016/03/09 20:30:26 I think it depends on what you're interested in ch
torbjorng (webrtc) 2016/03/10 21:29:03 Thanks, let's consider that for the future, but st
davidben_webrtc 2016/03/10 21:40:05 Really? I've been under the impression you all nee
1152 if (key_type == KT_RSA) { 1136 if (key_type == KT_RSA) {
1153 switch (version) { 1137 for (const cipher_list &c : OK_RSA_ciphers) {
1154 case SSL_PROTOCOL_TLS_10: 1138 if (cipher == c.cipher)
1155 case SSL_PROTOCOL_TLS_11: 1139 return true;
1156 return kDefaultSslCipher10;
1157 case SSL_PROTOCOL_TLS_12:
1158 default:
1159 #ifdef OPENSSL_IS_BORINGSSL
1160 if (EVP_has_aes_hardware()) {
1161 return kDefaultSslCipher12;
1162 } else {
1163 return kDefaultSslCipher12NoAesGcm;
1164 }
1165 #else // !OPENSSL_IS_BORINGSSL
1166 return kDefaultSslCipher12;
1167 #endif
1168 } 1140 }
1169 } else if (key_type == KT_ECDSA) { 1141 }
1170 switch (version) { 1142
1171 case SSL_PROTOCOL_TLS_10: 1143 if (key_type == KT_ECDSA) {
1172 case SSL_PROTOCOL_TLS_11: 1144 for (const cipher_list &c : OK_ECDSA_ciphers) {
1173 return kDefaultSslEcCipher10; 1145 if (cipher == c.cipher)
1174 case SSL_PROTOCOL_TLS_12: 1146 return true;
1175 default:
1176 #ifdef OPENSSL_IS_BORINGSSL
1177 if (EVP_has_aes_hardware()) {
1178 return kDefaultSslEcCipher12;
1179 } else {
1180 return kDefaultSslEcCipher12NoAesGcm;
1181 }
1182 #else // !OPENSSL_IS_BORINGSSL
1183 return kDefaultSslEcCipher12;
1184 #endif
1185 } 1147 }
1186 } else {
1187 RTC_NOTREACHED();
1188 return kDefaultSslEcCipher12;
1189 } 1148 }
1149
1150 // TODO(torbjorng): Remove before landing.
1151 LOG(LS_ERROR) << "Attempted use of truly terrible cipher suite: "
1152 << OpenSSLStreamAdapter::SslCipherSuiteToName(cipher) << "("
1153 << cipher << ")";
1154 return false;
1155 }
1156
1157 bool OpenSSLStreamAdapter::IsAcceptableCipher(std::string cipher,
1158 KeyType key_type) {
1159 if (key_type == KT_RSA) {
1160 for (const cipher_list &c : OK_RSA_ciphers) {
1161 if (cipher == c.cipher_str)
1162 return true;
1163 }
1164 }
1165
1166 if (key_type == KT_ECDSA) {
1167 for (const cipher_list &c : OK_ECDSA_ciphers) {
1168 if (cipher == c.cipher_str)
1169 return true;
1170 }
1171 }
1172
1173 // TODO(torbjorng): Remove before landing.
1174 LOG(LS_ERROR) << "Attempted use of truly terrible cipher suite: " << cipher;
1175 return false;
1190 } 1176 }
1191 1177
1192 } // namespace rtc 1178 } // namespace rtc
1193 1179
1194 #endif // HAVE_OPENSSL_SSL_H 1180 #endif // HAVE_OPENSSL_SSL_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698