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 |
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 |
45 SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) { | 97 SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) { |
46 #if SSL_USE_OPENSSL | 98 #if SSL_USE_OPENSSL |
47 return new OpenSSLStreamAdapter(stream); | 99 return new OpenSSLStreamAdapter(stream); |
48 #else // !SSL_USE_OPENSSL | 100 #else // !SSL_USE_OPENSSL |
49 return NULL; | 101 return NULL; |
50 #endif // SSL_USE_OPENSSL | 102 #endif // SSL_USE_OPENSSL |
51 } | 103 } |
52 | 104 |
53 bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { | 105 bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { |
54 return false; | 106 return false; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type); | 142 return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type); |
91 } | 143 } |
92 std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { | 144 std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { |
93 return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite); | 145 return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite); |
94 } | 146 } |
95 #endif // SSL_USE_OPENSSL | 147 #endif // SSL_USE_OPENSSL |
96 | 148 |
97 /////////////////////////////////////////////////////////////////////////////// | 149 /////////////////////////////////////////////////////////////////////////////// |
98 | 150 |
99 } // namespace rtc | 151 } // namespace rtc |
OLD | NEW |