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
11 #if HAVE_CONFIG_H
12 #include "config.h"
13 #endif // HAVE_CONFIG_H
14
15 #include "webrtc/base/sslstreamadapter.h"
16 #include "webrtc/base/sslconfig.h"
17
18 #if SSL_USE_OPENSSL
19
20 #include "webrtc/base/opensslstreamadapter.h"
21
22 #endif // SSL_USE_OPENSSL
23
24 ///////////////////////////////////////////////////////////////////////////////
25
26 namespace rtc {
27
28 // TODO(guoweis): Move this to SDP layer and use int form internally.
29 // webrtc:5043.
30 const char CS_AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80";
31 const char CS_AES_CM_128_HMAC_SHA1_32[] = "AES_CM_128_HMAC_SHA1_32";
32
SrtpCryptoSuiteToName(int crypto_suite)33 std::string SrtpCryptoSuiteToName(int crypto_suite) {
34 if (crypto_suite == SRTP_AES128_CM_SHA1_32)
35 return CS_AES_CM_128_HMAC_SHA1_32;
36 if (crypto_suite == SRTP_AES128_CM_SHA1_80)
37 return CS_AES_CM_128_HMAC_SHA1_80;
38 return std::string();
39 }
40
SrtpCryptoSuiteFromName(const std::string & crypto_suite)41 int SrtpCryptoSuiteFromName(const std::string& crypto_suite) {
42 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_32)
43 return SRTP_AES128_CM_SHA1_32;
44 if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_80)
45 return SRTP_AES128_CM_SHA1_80;
46 return SRTP_INVALID_CRYPTO_SUITE;
47 }
48
Create(StreamInterface * stream)49 SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) {
50 #if SSL_USE_OPENSSL
51 return new OpenSSLStreamAdapter(stream);
52 #else // !SSL_USE_OPENSSL
53 return NULL;
54 #endif // SSL_USE_OPENSSL
55 }
56
GetSslCipherSuite(int * cipher_suite)57 bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) {
58 return false;
59 }
60
ExportKeyingMaterial(const std::string & label,const uint8_t * context,size_t context_len,bool use_context,uint8_t * result,size_t result_len)61 bool SSLStreamAdapter::ExportKeyingMaterial(const std::string& label,
62 const uint8_t* context,
63 size_t context_len,
64 bool use_context,
65 uint8_t* result,
66 size_t result_len) {
67 return false; // Default is unsupported
68 }
69
SetDtlsSrtpCryptoSuites(const std::vector<int> & crypto_suites)70 bool SSLStreamAdapter::SetDtlsSrtpCryptoSuites(
71 const std::vector<int>& crypto_suites) {
72 return false;
73 }
74
GetDtlsSrtpCryptoSuite(int * crypto_suite)75 bool SSLStreamAdapter::GetDtlsSrtpCryptoSuite(int* crypto_suite) {
76 return false;
77 }
78
79 #if SSL_USE_OPENSSL
HaveDtls()80 bool SSLStreamAdapter::HaveDtls() {
81 return OpenSSLStreamAdapter::HaveDtls();
82 }
HaveDtlsSrtp()83 bool SSLStreamAdapter::HaveDtlsSrtp() {
84 return OpenSSLStreamAdapter::HaveDtlsSrtp();
85 }
HaveExporter()86 bool SSLStreamAdapter::HaveExporter() {
87 return OpenSSLStreamAdapter::HaveExporter();
88 }
GetDefaultSslCipherForTest(SSLProtocolVersion version,KeyType key_type)89 int SSLStreamAdapter::GetDefaultSslCipherForTest(SSLProtocolVersion version,
90 KeyType key_type) {
91 return OpenSSLStreamAdapter::GetDefaultSslCipherForTest(version, key_type);
92 }
93
SslCipherSuiteToName(int cipher_suite)94 std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) {
95 return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite);
96 }
97 #endif // SSL_USE_OPENSSL
98
99 ///////////////////////////////////////////////////////////////////////////////
100
101 } // namespace rtc
102