henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [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 | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 11 | #include "webrtc/base/sslstreamadapter.h" |
| 12 | #include "webrtc/base/sslconfig.h" |
| 13 | |
torbjorng | 172f009 | 2015-10-07 04:57:55 -0700 | [diff] [blame] | 14 | #if SSL_USE_OPENSSL |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 15 | |
| 16 | #include "webrtc/base/opensslstreamadapter.h" |
| 17 | |
torbjorng | 172f009 | 2015-10-07 04:57:55 -0700 | [diff] [blame] | 18 | #endif // SSL_USE_OPENSSL |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 19 | |
| 20 | /////////////////////////////////////////////////////////////////////////////// |
| 21 | |
| 22 | namespace rtc { |
| 23 | |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [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 | 521ed7b | 2015-11-18 19:41:53 -0800 | [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 | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 39 | return SRTP_AES128_CM_SHA1_32; |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 40 | if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_80) |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 41 | return SRTP_AES128_CM_SHA1_80; |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 42 | return SRTP_INVALID_CRYPTO_SUITE; |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 43 | } |
| 44 | |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 45 | SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) { |
torbjorng | 172f009 | 2015-10-07 04:57:55 -0700 | [diff] [blame] | 46 | #if SSL_USE_OPENSSL |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 47 | return new OpenSSLStreamAdapter(stream); |
torbjorng | 172f009 | 2015-10-07 04:57:55 -0700 | [diff] [blame] | 48 | #else // !SSL_USE_OPENSSL |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 49 | return NULL; |
torbjorng | 172f009 | 2015-10-07 04:57:55 -0700 | [diff] [blame] | 50 | #endif // SSL_USE_OPENSSL |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 53 | bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 54 | return false; |
| 55 | } |
| 56 | |
| 57 | bool SSLStreamAdapter::ExportKeyingMaterial(const std::string& label, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 58 | const uint8_t* context, |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 59 | size_t context_len, |
| 60 | bool use_context, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 61 | uint8_t* result, |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 62 | size_t result_len) { |
| 63 | return false; // Default is unsupported |
| 64 | } |
| 65 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 66 | bool SSLStreamAdapter::SetDtlsSrtpCryptoSuites( |
| 67 | const std::vector<int>& crypto_suites) { |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 68 | return false; |
| 69 | } |
| 70 | |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 71 | bool SSLStreamAdapter::GetDtlsSrtpCryptoSuite(int* crypto_suite) { |
kwiberg@webrtc.org | 67186fe | 2015-03-09 22:21:53 +0000 | [diff] [blame] | 72 | return false; |
| 73 | } |
| 74 | |
torbjorng | 172f009 | 2015-10-07 04:57:55 -0700 | [diff] [blame] | 75 | #if SSL_USE_OPENSSL |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [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 | } |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 85 | bool SSLStreamAdapter::IsAcceptableCipher(int cipher, KeyType key_type) { |
| 86 | return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type); |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 87 | } |
torbjorng | 43166b8 | 2016-03-11 00:06:47 -0800 | [diff] [blame] | 88 | bool SSLStreamAdapter::IsAcceptableCipher(const std::string& cipher, |
| 89 | KeyType key_type) { |
| 90 | return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type); |
| 91 | } |
Guo-wei Shieh | 521ed7b | 2015-11-18 19:41:53 -0800 | [diff] [blame] | 92 | std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) { |
| 93 | return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite); |
pthatcher@webrtc.org | 3ee4fe5 | 2015-02-11 22:34:36 +0000 | [diff] [blame] | 94 | } |
torbjorng | 172f009 | 2015-10-07 04:57:55 -0700 | [diff] [blame] | 95 | #endif // SSL_USE_OPENSSL |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 96 | |
| 97 | /////////////////////////////////////////////////////////////////////////////// |
| 98 | |
| 99 | } // namespace rtc |