henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 11 | #include "webrtc/base/sslstreamadapter.h" |
| 12 | #include "webrtc/base/sslconfig.h" |
| 13 | |
torbjorng | 7cd5061 | 2015-10-07 11:57:55 | [diff] [blame] | 14 | #if SSL_USE_OPENSSL |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 15 | |
| 16 | #include "webrtc/base/opensslstreamadapter.h" |
| 17 | |
torbjorng | 7cd5061 | 2015-10-07 11:57:55 | [diff] [blame] | 18 | #endif // SSL_USE_OPENSSL |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 19 | |
| 20 | /////////////////////////////////////////////////////////////////////////////// |
| 21 | |
| 22 | namespace rtc { |
| 23 | |
Guo-wei Shieh | 5acc8ec | 2015-10-01 04:48:54 | [diff] [blame] | 24 | // TODO(guoweis): Move this to SDP layer and use int form internally. |
| 25 | // webrtc:5043. |
| 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"; |
| 28 | |
Guo-wei Shieh | 838c3b5 | 2015-11-19 03:41:53 | [diff] [blame] | 29 | std::string SrtpCryptoSuiteToName(int crypto_suite) { |
| 30 | if (crypto_suite == SRTP_AES128_CM_SHA1_32) |
| 31 | return CS_AES_CM_128_HMAC_SHA1_32; |
| 32 | if (crypto_suite == SRTP_AES128_CM_SHA1_80) |
| 33 | return CS_AES_CM_128_HMAC_SHA1_80; |
| 34 | return std::string(); |
| 35 | } |
| 36 | |
| 37 | int SrtpCryptoSuiteFromName(const std::string& crypto_suite) { |
| 38 | if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_32) |
Guo-wei Shieh | 5acc8ec | 2015-10-01 04:48:54 | [diff] [blame] | 39 | return SRTP_AES128_CM_SHA1_32; |
Guo-wei Shieh | 838c3b5 | 2015-11-19 03:41:53 | [diff] [blame] | 40 | if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_80) |
Guo-wei Shieh | 5acc8ec | 2015-10-01 04:48:54 | [diff] [blame] | 41 | return SRTP_AES128_CM_SHA1_80; |
Guo-wei Shieh | 838c3b5 | 2015-11-19 03:41:53 | [diff] [blame] | 42 | return SRTP_INVALID_CRYPTO_SUITE; |
Guo-wei Shieh | 5acc8ec | 2015-10-01 04:48:54 | [diff] [blame] | 43 | } |
| 44 | |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 45 | SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) { |
torbjorng | 7cd5061 | 2015-10-07 11:57:55 | [diff] [blame] | 46 | #if SSL_USE_OPENSSL |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 47 | return new OpenSSLStreamAdapter(stream); |
torbjorng | 7cd5061 | 2015-10-07 11:57:55 | [diff] [blame] | 48 | #else // !SSL_USE_OPENSSL |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 49 | return NULL; |
torbjorng | 7cd5061 | 2015-10-07 11:57:55 | [diff] [blame] | 50 | #endif // SSL_USE_OPENSSL |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 51 | } |
| 52 | |
Guo-wei Shieh | 838c3b5 | 2015-11-19 03:41:53 | [diff] [blame] | 53 | bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { |
kwiberg@webrtc.org | 786b634 | 2015-03-09 22:21:53 | [diff] [blame] | 54 | return false; |
| 55 | } |
| 56 | |
| 57 | bool SSLStreamAdapter::ExportKeyingMaterial(const std::string& label, |
Peter Boström | 07e22e6 | 2015-10-07 10:23:21 | [diff] [blame] | 58 | const uint8_t* context, |
kwiberg@webrtc.org | 786b634 | 2015-03-09 22:21:53 | [diff] [blame] | 59 | size_t context_len, |
| 60 | bool use_context, |
Peter Boström | 07e22e6 | 2015-10-07 10:23:21 | [diff] [blame] | 61 | uint8_t* result, |
kwiberg@webrtc.org | 786b634 | 2015-03-09 22:21:53 | [diff] [blame] | 62 | size_t result_len) { |
| 63 | return false; // Default is unsupported |
| 64 | } |
| 65 | |
Guo-wei Shieh | 838c3b5 | 2015-11-19 03:41:53 | [diff] [blame] | 66 | bool SSLStreamAdapter::SetDtlsSrtpCryptoSuites( |
| 67 | const std::vector<int>& crypto_suites) { |
kwiberg@webrtc.org | 786b634 | 2015-03-09 22:21:53 | [diff] [blame] | 68 | return false; |
| 69 | } |
| 70 | |
Guo-wei Shieh | 838c3b5 | 2015-11-19 03:41:53 | [diff] [blame] | 71 | bool SSLStreamAdapter::GetDtlsSrtpCryptoSuite(int* crypto_suite) { |
kwiberg@webrtc.org | 786b634 | 2015-03-09 22:21:53 | [diff] [blame] | 72 | return false; |
| 73 | } |
| 74 | |
torbjorng | 7cd5061 | 2015-10-07 11:57:55 | [diff] [blame] | 75 | #if SSL_USE_OPENSSL |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 76 | bool SSLStreamAdapter::HaveDtls() { |
| 77 | return OpenSSLStreamAdapter::HaveDtls(); |
| 78 | } |
| 79 | bool SSLStreamAdapter::HaveDtlsSrtp() { |
| 80 | return OpenSSLStreamAdapter::HaveDtlsSrtp(); |
| 81 | } |
| 82 | bool SSLStreamAdapter::HaveExporter() { |
| 83 | return OpenSSLStreamAdapter::HaveExporter(); |
| 84 | } |
Taylor Brandstetter | fa82254 | 2016-06-16 00:15:23 | [diff] [blame] | 85 | bool SSLStreamAdapter::IsBoringSsl() { |
| 86 | return OpenSSLStreamAdapter::IsBoringSsl(); |
| 87 | } |
torbjorng | dea3f23 | 2016-03-11 08:06:47 | [diff] [blame] | 88 | bool SSLStreamAdapter::IsAcceptableCipher(int cipher, KeyType key_type) { |
| 89 | return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type); |
Guo-wei Shieh | 5acc8ec | 2015-10-01 04:48:54 | [diff] [blame] | 90 | } |
torbjorng | dea3f23 | 2016-03-11 08:06:47 | [diff] [blame] | 91 | bool SSLStreamAdapter::IsAcceptableCipher(const std::string& cipher, |
| 92 | KeyType key_type) { |
| 93 | return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type); |
| 94 | } |
Guo-wei Shieh | 838c3b5 | 2015-11-19 03:41:53 | [diff] [blame] | 95 | std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { |
| 96 | return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite); |
pthatcher@webrtc.org | 2fb6991 | 2015-02-11 22:34:36 | [diff] [blame] | 97 | } |
torbjorng | 7cd5061 | 2015-10-07 11:57:55 | [diff] [blame] | 98 | #endif // SSL_USE_OPENSSL |
henrike@webrtc.org | 47be73b | 2014-05-13 18:00:26 | [diff] [blame] | 99 | |
| 100 | /////////////////////////////////////////////////////////////////////////////// |
| 101 | |
| 102 | } // namespace rtc |