2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2004 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "webrtc/base/sslstreamadapter.h"
|
|
|
|
|
#include "webrtc/base/sslconfig.h"
|
|
|
|
|
|
2015-10-07 04:57:55 -07:00
|
|
|
#if SSL_USE_OPENSSL
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
#include "webrtc/base/opensslstreamadapter.h"
|
|
|
|
|
|
2015-10-07 04:57:55 -07:00
|
|
|
#endif // SSL_USE_OPENSSL
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
|
2015-09-30 21:48:54 -07:00
|
|
|
// TODO(guoweis): Move this to SDP layer and use int form internally.
|
|
|
|
|
// webrtc:5043.
|
|
|
|
|
const char CS_AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80";
|
|
|
|
|
const char CS_AES_CM_128_HMAC_SHA1_32[] = "AES_CM_128_HMAC_SHA1_32";
|
2016-08-04 05:20:32 -07:00
|
|
|
const char CS_AEAD_AES_128_GCM[] = "AEAD_AES_128_GCM";
|
|
|
|
|
const char CS_AEAD_AES_256_GCM[] = "AEAD_AES_256_GCM";
|
2015-09-30 21:48:54 -07:00
|
|
|
|
2015-11-18 19:41:53 -08:00
|
|
|
std::string SrtpCryptoSuiteToName(int crypto_suite) {
|
2016-08-04 05:20:32 -07:00
|
|
|
switch (crypto_suite) {
|
|
|
|
|
case SRTP_AES128_CM_SHA1_32:
|
2015-11-18 19:41:53 -08:00
|
|
|
return CS_AES_CM_128_HMAC_SHA1_32;
|
2016-08-04 05:20:32 -07:00
|
|
|
case SRTP_AES128_CM_SHA1_80:
|
2015-11-18 19:41:53 -08:00
|
|
|
return CS_AES_CM_128_HMAC_SHA1_80;
|
2016-08-04 05:20:32 -07:00
|
|
|
case SRTP_AEAD_AES_128_GCM:
|
|
|
|
|
return CS_AEAD_AES_128_GCM;
|
|
|
|
|
case SRTP_AEAD_AES_256_GCM:
|
|
|
|
|
return CS_AEAD_AES_256_GCM;
|
|
|
|
|
default:
|
|
|
|
|
return std::string();
|
|
|
|
|
}
|
2015-11-18 19:41:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrtpCryptoSuiteFromName(const std::string& crypto_suite) {
|
|
|
|
|
if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_32)
|
2015-09-30 21:48:54 -07:00
|
|
|
return SRTP_AES128_CM_SHA1_32;
|
2015-11-18 19:41:53 -08:00
|
|
|
if (crypto_suite == CS_AES_CM_128_HMAC_SHA1_80)
|
2015-09-30 21:48:54 -07:00
|
|
|
return SRTP_AES128_CM_SHA1_80;
|
2016-08-04 05:20:32 -07:00
|
|
|
if (crypto_suite == CS_AEAD_AES_128_GCM)
|
|
|
|
|
return SRTP_AEAD_AES_128_GCM;
|
|
|
|
|
if (crypto_suite == CS_AEAD_AES_256_GCM)
|
|
|
|
|
return SRTP_AEAD_AES_256_GCM;
|
2015-11-18 19:41:53 -08:00
|
|
|
return SRTP_INVALID_CRYPTO_SUITE;
|
2015-09-30 21:48:54 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-04 05:20:32 -07:00
|
|
|
bool GetSrtpKeyAndSaltLengths(int crypto_suite, int *key_length,
|
|
|
|
|
int *salt_length) {
|
|
|
|
|
switch (crypto_suite) {
|
|
|
|
|
case SRTP_AES128_CM_SHA1_32:
|
|
|
|
|
case SRTP_AES128_CM_SHA1_80:
|
|
|
|
|
// SRTP_AES128_CM_HMAC_SHA1_32 and SRTP_AES128_CM_HMAC_SHA1_80 are defined
|
|
|
|
|
// in RFC 5764 to use a 128 bits key and 112 bits salt for the cipher.
|
|
|
|
|
*key_length = 16;
|
|
|
|
|
*salt_length = 14;
|
|
|
|
|
break;
|
|
|
|
|
case SRTP_AEAD_AES_128_GCM:
|
|
|
|
|
// SRTP_AEAD_AES_128_GCM is defined in RFC 7714 to use a 128 bits key and
|
|
|
|
|
// a 96 bits salt for the cipher.
|
|
|
|
|
*key_length = 16;
|
|
|
|
|
*salt_length = 12;
|
|
|
|
|
break;
|
|
|
|
|
case SRTP_AEAD_AES_256_GCM:
|
|
|
|
|
// SRTP_AEAD_AES_256_GCM is defined in RFC 7714 to use a 256 bits key and
|
|
|
|
|
// a 96 bits salt for the cipher.
|
|
|
|
|
*key_length = 32;
|
|
|
|
|
*salt_length = 12;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsGcmCryptoSuite(int crypto_suite) {
|
|
|
|
|
return (crypto_suite == SRTP_AEAD_AES_256_GCM ||
|
|
|
|
|
crypto_suite == SRTP_AEAD_AES_128_GCM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsGcmCryptoSuiteName(const std::string& crypto_suite) {
|
|
|
|
|
return (crypto_suite == CS_AEAD_AES_256_GCM ||
|
|
|
|
|
crypto_suite == CS_AEAD_AES_128_GCM);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
|
CryptoOptions CryptoOptions::NoGcm() {
|
|
|
|
|
CryptoOptions options;
|
|
|
|
|
options.enable_gcm_crypto_suites = false;
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 18:00:26 +00:00
|
|
|
SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) {
|
2015-10-07 04:57:55 -07:00
|
|
|
#if SSL_USE_OPENSSL
|
2014-05-13 18:00:26 +00:00
|
|
|
return new OpenSSLStreamAdapter(stream);
|
2015-10-07 04:57:55 -07:00
|
|
|
#else // !SSL_USE_OPENSSL
|
2014-05-13 18:00:26 +00:00
|
|
|
return NULL;
|
2015-10-07 04:57:55 -07:00
|
|
|
#endif // SSL_USE_OPENSSL
|
2014-05-13 18:00:26 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-26 11:25:05 -07:00
|
|
|
SSLStreamAdapter::SSLStreamAdapter(StreamInterface* stream)
|
|
|
|
|
: StreamAdapterInterface(stream),
|
|
|
|
|
ignore_bad_cert_(false),
|
|
|
|
|
client_auth_enabled_(true) {}
|
|
|
|
|
|
|
|
|
|
SSLStreamAdapter::~SSLStreamAdapter() {}
|
|
|
|
|
|
2015-11-18 19:41:53 -08:00
|
|
|
bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) {
|
2015-03-09 22:21:53 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SSLStreamAdapter::ExportKeyingMaterial(const std::string& label,
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
const uint8_t* context,
|
2015-03-09 22:21:53 +00:00
|
|
|
size_t context_len,
|
|
|
|
|
bool use_context,
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
uint8_t* result,
|
2015-03-09 22:21:53 +00:00
|
|
|
size_t result_len) {
|
|
|
|
|
return false; // Default is unsupported
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 19:41:53 -08:00
|
|
|
bool SSLStreamAdapter::SetDtlsSrtpCryptoSuites(
|
|
|
|
|
const std::vector<int>& crypto_suites) {
|
2015-03-09 22:21:53 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-18 19:41:53 -08:00
|
|
|
bool SSLStreamAdapter::GetDtlsSrtpCryptoSuite(int* crypto_suite) {
|
2015-03-09 22:21:53 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-07 04:57:55 -07:00
|
|
|
#if SSL_USE_OPENSSL
|
2014-05-13 18:00:26 +00:00
|
|
|
bool SSLStreamAdapter::HaveDtls() {
|
|
|
|
|
return OpenSSLStreamAdapter::HaveDtls();
|
|
|
|
|
}
|
|
|
|
|
bool SSLStreamAdapter::HaveDtlsSrtp() {
|
|
|
|
|
return OpenSSLStreamAdapter::HaveDtlsSrtp();
|
|
|
|
|
}
|
|
|
|
|
bool SSLStreamAdapter::HaveExporter() {
|
|
|
|
|
return OpenSSLStreamAdapter::HaveExporter();
|
|
|
|
|
}
|
2016-06-15 17:15:23 -07:00
|
|
|
bool SSLStreamAdapter::IsBoringSsl() {
|
|
|
|
|
return OpenSSLStreamAdapter::IsBoringSsl();
|
|
|
|
|
}
|
2016-03-11 00:06:47 -08:00
|
|
|
bool SSLStreamAdapter::IsAcceptableCipher(int cipher, KeyType key_type) {
|
|
|
|
|
return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type);
|
|
|
|
|
}
|
|
|
|
|
bool SSLStreamAdapter::IsAcceptableCipher(const std::string& cipher,
|
|
|
|
|
KeyType key_type) {
|
|
|
|
|
return OpenSSLStreamAdapter::IsAcceptableCipher(cipher, key_type);
|
2015-09-30 21:48:54 -07:00
|
|
|
}
|
2015-11-18 19:41:53 -08:00
|
|
|
std::string SSLStreamAdapter::SslCipherSuiteToName(int cipher_suite) {
|
|
|
|
|
return OpenSSLStreamAdapter::SslCipherSuiteToName(cipher_suite);
|
2015-02-11 22:34:36 +00:00
|
|
|
}
|
2015-10-07 04:57:55 -07:00
|
|
|
#endif // SSL_USE_OPENSSL
|
2014-05-13 18:00:26 +00:00
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
} // namespace rtc
|