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

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

Issue 1528843005: Add support for GCM cipher suites from RFC 7714. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Disable GCM if ENABLE_EXTERNAL_AUTH is defined. Created 4 years, 5 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/sslstreamadapter.h ('k') | webrtc/base/sslstreamadapter_unittest.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 #include "webrtc/base/sslstreamadapter.h" 11 #include "webrtc/base/sslstreamadapter.h"
12 #include "webrtc/base/sslconfig.h" 12 #include "webrtc/base/sslconfig.h"
13 13
14 #if SSL_USE_OPENSSL 14 #if SSL_USE_OPENSSL
15 15
16 #include "webrtc/base/opensslstreamadapter.h" 16 #include "webrtc/base/opensslstreamadapter.h"
17 17
18 #endif // SSL_USE_OPENSSL 18 #endif // SSL_USE_OPENSSL
19 19
20 /////////////////////////////////////////////////////////////////////////////// 20 ///////////////////////////////////////////////////////////////////////////////
21 21
22 namespace rtc { 22 namespace rtc {
23 23
24 // TODO(guoweis): Move this to SDP layer and use int form internally. 24 // TODO(guoweis): Move this to SDP layer and use int form internally.
25 // webrtc:5043. 25 // webrtc:5043.
26 const char CS_AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; 26 const char CS_AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80";
27 const char CS_AES_CM_128_HMAC_SHA1_32[] = "AES_CM_128_HMAC_SHA1_32"; 27 const char CS_AES_CM_128_HMAC_SHA1_32[] = "AES_CM_128_HMAC_SHA1_32";
28 const char CS_AEAD_AES_128_GCM[] = "AEAD_AES_128_GCM";
29 const char CS_AEAD_AES_256_GCM[] = "AEAD_AES_256_GCM";
28 30
29 std::string SrtpCryptoSuiteToName(int crypto_suite) { 31 std::string SrtpCryptoSuiteToName(int crypto_suite) {
30 if (crypto_suite == SRTP_AES128_CM_SHA1_32) 32 switch (crypto_suite) {
33 case SRTP_AES128_CM_SHA1_32:
31 return CS_AES_CM_128_HMAC_SHA1_32; 34 return CS_AES_CM_128_HMAC_SHA1_32;
32 if (crypto_suite == SRTP_AES128_CM_SHA1_80) 35 case SRTP_AES128_CM_SHA1_80:
33 return CS_AES_CM_128_HMAC_SHA1_80; 36 return CS_AES_CM_128_HMAC_SHA1_80;
34 return std::string(); 37 case SRTP_AEAD_AES_128_GCM:
38 return CS_AEAD_AES_128_GCM;
39 case SRTP_AEAD_AES_256_GCM:
40 return CS_AEAD_AES_256_GCM;
41 default:
42 return std::string();
43 }
35 } 44 }
36 45
37 int SrtpCryptoSuiteFromName(const std::string& crypto_suite) { 46 int SrtpCryptoSuiteFromName(const std::string& crypto_suite) {
38 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_32) 47 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_32)
39 return SRTP_AES128_CM_SHA1_32; 48 return SRTP_AES128_CM_SHA1_32;
40 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_80) 49 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_80)
41 return SRTP_AES128_CM_SHA1_80; 50 return SRTP_AES128_CM_SHA1_80;
51 if (crypto_suite == CS_AEAD_AES_128_GCM)
52 return SRTP_AEAD_AES_128_GCM;
53 if (crypto_suite == CS_AEAD_AES_256_GCM)
54 return SRTP_AEAD_AES_256_GCM;
42 return SRTP_INVALID_CRYPTO_SUITE; 55 return SRTP_INVALID_CRYPTO_SUITE;
43 } 56 }
44 57
58 bool GetSrtpKeyAndSaltLengths(int crypto_suite, int *key_length,
59 int *salt_length) {
60 switch (crypto_suite) {
61 case SRTP_AES128_CM_SHA1_32:
62 case SRTP_AES128_CM_SHA1_80:
63 // SRTP_AES128_CM_HMAC_SHA1_32 and SRTP_AES128_CM_HMAC_SHA1_80 are defined
64 // in RFC 5764 to use a 128 bits key and 112 bits salt for the cipher.
65 *key_length = 16;
66 *salt_length = 14;
67 break;
68 case SRTP_AEAD_AES_128_GCM:
69 // SRTP_AEAD_AES_128_GCM is defined in RFC 7714 to use a 128 bits key and
70 // a 96 bits salt for the cipher.
71 *key_length = 16;
72 *salt_length = 12;
73 break;
74 case SRTP_AEAD_AES_256_GCM:
75 // SRTP_AEAD_AES_256_GCM is defined in RFC 7714 to use a 256 bits key and
76 // a 96 bits salt for the cipher.
77 *key_length = 32;
78 *salt_length = 12;
79 break;
80 default:
81 return false;
82 }
83 return true;
84 }
85
86 bool IsGcmCryptoSuite(int crypto_suite) {
87 return (crypto_suite == SRTP_AEAD_AES_256_GCM ||
88 crypto_suite == SRTP_AEAD_AES_128_GCM);
89 }
90
91 bool IsGcmCryptoSuiteName(const std::string& crypto_suite) {
92 return (crypto_suite == CS_AEAD_AES_256_GCM ||
93 crypto_suite == CS_AEAD_AES_128_GCM);
94 }
95
96 // static
97 CryptoOptions CryptoOptions::NoGcm() {
98 CryptoOptions options;
99 options.enable_gcm_crypto_suites = false;
100 return options;
101 }
102
45 SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) { 103 SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) {
46 #if SSL_USE_OPENSSL 104 #if SSL_USE_OPENSSL
47 return new OpenSSLStreamAdapter(stream); 105 return new OpenSSLStreamAdapter(stream);
48 #else // !SSL_USE_OPENSSL 106 #else // !SSL_USE_OPENSSL
49 return NULL; 107 return NULL;
50 #endif // SSL_USE_OPENSSL 108 #endif // SSL_USE_OPENSSL
51 } 109 }
52 110
53 bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { 111 bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) {
54 return false; 112 return false;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type); 151 return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type);
94 } 152 }
95 std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { 153 std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) {
96 return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite); 154 return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite);
97 } 155 }
98 #endif // SSL_USE_OPENSSL 156 #endif // SSL_USE_OPENSSL
99 157
100 /////////////////////////////////////////////////////////////////////////////// 158 ///////////////////////////////////////////////////////////////////////////////
101 159
102 } // namespace rtc 160 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/sslstreamadapter.h ('k') | webrtc/base/sslstreamadapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698