Convert uint16_t to int for WebRTC cipher/crypto suite.

This is a follow up CL on https://codereview.webrtc.org/1337673002

BUG=
R=pthatcher@webrtc.org

Review URL: https://codereview.webrtc.org/1377733004 .

Cr-Commit-Position: refs/heads/master@{#10175}
This commit is contained in:
Guo-wei Shieh
2015-10-05 12:43:27 -07:00
parent 1b33da1298
commit 6caafbe5b6
15 changed files with 50 additions and 55 deletions

View File

@ -734,7 +734,7 @@ void StatsCollector::ExtractSessionInfo() {
channel_report->AddString(StatsReport::kStatsValueNameSrtpCipher, channel_report->AddString(StatsReport::kStatsValueNameSrtpCipher,
srtp_cipher); srtp_cipher);
} }
uint16_t ssl_cipher = channel_iter.ssl_cipher; int ssl_cipher = channel_iter.ssl_cipher;
if (ssl_cipher && if (ssl_cipher &&
rtc::SSLStreamAdapter::GetSslCipherSuiteName(ssl_cipher).length()) { rtc::SSLStreamAdapter::GetSslCipherSuiteName(ssl_cipher).length()) {
channel_report->AddString( channel_report->AddString(

View File

@ -61,7 +61,7 @@ using webrtc::StatsReports;
namespace { namespace {
// This value comes from openssl/tls1.h // This value comes from openssl/tls1.h
const uint16_t TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014; const int TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014;
} // namespace } // namespace
namespace cricket { namespace cricket {

View File

@ -2149,7 +2149,7 @@ void WebRtcSession::ReportNegotiatedCiphers(
} }
const std::string& srtp_cipher = stats.channel_stats[0].srtp_cipher; const std::string& srtp_cipher = stats.channel_stats[0].srtp_cipher;
uint16_t ssl_cipher = stats.channel_stats[0].ssl_cipher; int ssl_cipher = stats.channel_stats[0].ssl_cipher;
if (srtp_cipher.empty() && !ssl_cipher) { if (srtp_cipher.empty() && !ssl_cipher) {
return; return;
} }

View File

@ -148,26 +148,26 @@ static const SslCipherMapEntry kSslCipherMap[] = {
// Default cipher used between OpenSSL/BoringSSL stream adapters. // Default cipher used between OpenSSL/BoringSSL stream adapters.
// This needs to be updated when the default of the SSL library changes. // This needs to be updated when the default of the SSL library changes.
// static_cast<uint16_t> causes build warnings on windows platform. // static_cast<uint16_t> causes build warnings on windows platform.
static uint16_t kDefaultSslCipher10 = static int kDefaultSslCipher10 =
static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA); static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA);
static uint16_t kDefaultSslEcCipher10 = static int kDefaultSslEcCipher10 =
static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA); static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
#ifdef OPENSSL_IS_BORINGSSL #ifdef OPENSSL_IS_BORINGSSL
static uint16_t kDefaultSslCipher12 = static int kDefaultSslCipher12 =
static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256); static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256);
static uint16_t kDefaultSslEcCipher12 = static int kDefaultSslEcCipher12 =
static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256); static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256);
// Fallback cipher for DTLS 1.2 if hardware-accelerated AES-GCM is unavailable. // Fallback cipher for DTLS 1.2 if hardware-accelerated AES-GCM is unavailable.
static uint16_t kDefaultSslCipher12NoAesGcm = static int kDefaultSslCipher12NoAesGcm =
static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305); static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305);
static uint16_t kDefaultSslEcCipher12NoAesGcm = static int kDefaultSslEcCipher12NoAesGcm =
static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305); static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305);
#else // !OPENSSL_IS_BORINGSSL #else // !OPENSSL_IS_BORINGSSL
// OpenSSL sorts differently than BoringSSL, so the default cipher doesn't // OpenSSL sorts differently than BoringSSL, so the default cipher doesn't
// change between TLS 1.0 and TLS 1.2 with the current setup. // change between TLS 1.0 and TLS 1.2 with the current setup.
static uint16_t kDefaultSslCipher12 = static int kDefaultSslCipher12 =
static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA); static_cast<uint16_t>(TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA);
static uint16_t kDefaultSslEcCipher12 = static int kDefaultSslEcCipher12 =
static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA); static_cast<uint16_t>(TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
#endif #endif
@ -348,7 +348,7 @@ bool OpenSSLStreamAdapter::SetPeerCertificateDigest(const std::string
return true; return true;
} }
std::string OpenSSLStreamAdapter::GetSslCipherSuiteName(uint16_t cipher) { std::string OpenSSLStreamAdapter::GetSslCipherSuiteName(int cipher) {
#ifdef OPENSSL_IS_BORINGSSL #ifdef OPENSSL_IS_BORINGSSL
const SSL_CIPHER* ssl_cipher = SSL_get_cipher_by_value(cipher); const SSL_CIPHER* ssl_cipher = SSL_get_cipher_by_value(cipher);
if (!ssl_cipher) { if (!ssl_cipher) {
@ -369,7 +369,7 @@ std::string OpenSSLStreamAdapter::GetSslCipherSuiteName(uint16_t cipher) {
#endif #endif
} }
bool OpenSSLStreamAdapter::GetSslCipherSuite(uint16_t* cipher) { bool OpenSSLStreamAdapter::GetSslCipherSuite(int* cipher) {
if (state_ != SSL_CONNECTED) if (state_ != SSL_CONNECTED)
return false; return false;
@ -1130,8 +1130,7 @@ bool OpenSSLStreamAdapter::HaveExporter() {
#endif #endif
} }
uint16_t OpenSSLStreamAdapter::GetDefaultSslCipherForTest( int OpenSSLStreamAdapter::GetDefaultSslCipherForTest(SSLProtocolVersion version,
SSLProtocolVersion version,
KeyType key_type) { KeyType key_type) {
if (key_type == KT_RSA) { if (key_type == KT_RSA) {
switch (version) { switch (version) {

View File

@ -88,9 +88,9 @@ class OpenSSLStreamAdapter : public SSLStreamAdapter {
StreamState GetState() const override; StreamState GetState() const override;
// TODO(guoweis): Move this away from a static class method. // TODO(guoweis): Move this away from a static class method.
static std::string GetSslCipherSuiteName(uint16_t cipher); static std::string GetSslCipherSuiteName(int cipher);
bool GetSslCipherSuite(uint16_t* cipher) override; bool GetSslCipherSuite(int* cipher) override;
// Key Extractor interface // Key Extractor interface
bool ExportKeyingMaterial(const std::string& label, bool ExportKeyingMaterial(const std::string& label,
@ -110,7 +110,7 @@ class OpenSSLStreamAdapter : public SSLStreamAdapter {
static bool HaveExporter(); static bool HaveExporter();
// TODO(guoweis): Move this away from a static class method. // TODO(guoweis): Move this away from a static class method.
static uint16_t GetDefaultSslCipherForTest(SSLProtocolVersion version, static int GetDefaultSslCipherForTest(SSLProtocolVersion version,
KeyType key_type); KeyType key_type);
protected: protected:

View File

@ -34,7 +34,7 @@ namespace rtc {
const char CS_AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; 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"; const char CS_AES_CM_128_HMAC_SHA1_32[] = "AES_CM_128_HMAC_SHA1_32";
uint16_t GetSrtpCryptoSuiteFromName(const std::string& cipher) { int GetSrtpCryptoSuiteFromName(const std::string& cipher) {
if (cipher == CS_AES_CM_128_HMAC_SHA1_32) if (cipher == CS_AES_CM_128_HMAC_SHA1_32)
return SRTP_AES128_CM_SHA1_32; return SRTP_AES128_CM_SHA1_32;
if (cipher == CS_AES_CM_128_HMAC_SHA1_80) if (cipher == CS_AES_CM_128_HMAC_SHA1_80)
@ -52,7 +52,7 @@ SSLStreamAdapter* SSLStreamAdapter::Create(StreamInterface* stream) {
#endif #endif
} }
bool SSLStreamAdapter::GetSslCipherSuite(uint16_t* cipher) { bool SSLStreamAdapter::GetSslCipherSuite(int* cipher) {
return false; return false;
} }
@ -79,8 +79,7 @@ bool SSLStreamAdapter::GetDtlsSrtpCipher(std::string* cipher) {
bool SSLStreamAdapter::HaveDtls() { return false; } bool SSLStreamAdapter::HaveDtls() { return false; }
bool SSLStreamAdapter::HaveDtlsSrtp() { return false; } bool SSLStreamAdapter::HaveDtlsSrtp() { return false; }
bool SSLStreamAdapter::HaveExporter() { return false; } bool SSLStreamAdapter::HaveExporter() { return false; }
uint16_t SSLStreamAdapter::GetDefaultSslCipherForTest( int SSLStreamAdapter::GetDefaultSslCipherForTest(SSLProtocolVersion version,
SSLProtocolVersion version,
KeyType key_type) { KeyType key_type) {
return 0; return 0;
} }
@ -94,13 +93,12 @@ bool SSLStreamAdapter::HaveDtlsSrtp() {
bool SSLStreamAdapter::HaveExporter() { bool SSLStreamAdapter::HaveExporter() {
return OpenSSLStreamAdapter::HaveExporter(); return OpenSSLStreamAdapter::HaveExporter();
} }
uint16_t SSLStreamAdapter::GetDefaultSslCipherForTest( int SSLStreamAdapter::GetDefaultSslCipherForTest(SSLProtocolVersion version,
SSLProtocolVersion version,
KeyType key_type) { KeyType key_type) {
return OpenSSLStreamAdapter::GetDefaultSslCipherForTest(version, key_type); return OpenSSLStreamAdapter::GetDefaultSslCipherForTest(version, key_type);
} }
std::string SSLStreamAdapter::GetSslCipherSuiteName(uint16_t cipher) { std::string SSLStreamAdapter::GetSslCipherSuiteName(int cipher) {
return OpenSSLStreamAdapter::GetSslCipherSuiteName(cipher); return OpenSSLStreamAdapter::GetSslCipherSuiteName(cipher);
} }
#endif // !SSL_USE_SCHANNEL && !SSL_USE_OPENSSL #endif // !SSL_USE_SCHANNEL && !SSL_USE_OPENSSL

View File

@ -20,8 +20,8 @@
namespace rtc { namespace rtc {
// Constants for SRTP profiles. // Constants for SRTP profiles.
const uint16_t SRTP_AES128_CM_SHA1_80 = 0x0001; const int SRTP_AES128_CM_SHA1_80 = 0x0001;
const uint16_t SRTP_AES128_CM_SHA1_32 = 0x0002; const int SRTP_AES128_CM_SHA1_32 = 0x0002;
// Cipher suite to use for SRTP. Typically a 80-bit HMAC will be used, except // Cipher suite to use for SRTP. Typically a 80-bit HMAC will be used, except
// in applications (voice) where the additional bandwidth may be significant. // in applications (voice) where the additional bandwidth may be significant.
@ -34,7 +34,7 @@ extern const char CS_AES_CM_128_HMAC_SHA1_32[];
// Returns the DTLS-SRTP protection profile ID, as defined in // Returns the DTLS-SRTP protection profile ID, as defined in
// https://tools.ietf.org/html/rfc5764#section-4.1.2, for the given SRTP // https://tools.ietf.org/html/rfc5764#section-4.1.2, for the given SRTP
// Crypto-suite, as defined in https://tools.ietf.org/html/rfc4568#section-6.2 // Crypto-suite, as defined in https://tools.ietf.org/html/rfc4568#section-6.2
uint16_t GetSrtpCryptoSuiteFromName(const std::string& cipher_rfc_name); int GetSrtpCryptoSuiteFromName(const std::string& cipher_rfc_name);
// SSLStreamAdapter : A StreamInterfaceAdapter that does SSL/TLS. // SSLStreamAdapter : A StreamInterfaceAdapter that does SSL/TLS.
// After SSL has been started, the stream will only open on successful // After SSL has been started, the stream will only open on successful
@ -152,7 +152,7 @@ class SSLStreamAdapter : public StreamAdapterInterface {
// Retrieves the IANA registration id of the cipher suite used for the // Retrieves the IANA registration id of the cipher suite used for the
// connection (e.g. 0x2F for "TLS_RSA_WITH_AES_128_CBC_SHA"). // connection (e.g. 0x2F for "TLS_RSA_WITH_AES_128_CBC_SHA").
virtual bool GetSslCipherSuite(uint16_t* cipher); virtual bool GetSslCipherSuite(int* cipher);
// Key Exporter interface from RFC 5705 // Key Exporter interface from RFC 5705
// Arguments are: // Arguments are:
@ -185,13 +185,13 @@ class SSLStreamAdapter : public StreamAdapterInterface {
// Returns the default Ssl cipher used between streams of this class // Returns the default Ssl cipher used between streams of this class
// for the given protocol version. This is used by the unit tests. // for the given protocol version. This is used by the unit tests.
// TODO(guoweis): Move this away from a static class method. // TODO(guoweis): Move this away from a static class method.
static uint16_t GetDefaultSslCipherForTest(SSLProtocolVersion version, static int GetDefaultSslCipherForTest(SSLProtocolVersion version,
KeyType key_type); KeyType key_type);
// TODO(guoweis): Move this away from a static class method. Currently this is // TODO(guoweis): Move this away from a static class method. Currently this is
// introduced such that any caller could depend on sslstreamadapter.h without // introduced such that any caller could depend on sslstreamadapter.h without
// depending on specific SSL implementation. // depending on specific SSL implementation.
static std::string GetSslCipherSuiteName(uint16_t cipher); static std::string GetSslCipherSuiteName(int cipher);
private: private:
// If true, the server certificate need not match the configured // If true, the server certificate need not match the configured

View File

@ -410,7 +410,7 @@ class SSLStreamAdapterTestBase : public testing::Test,
return server_ssl_->GetPeerCertificate(cert); return server_ssl_->GetPeerCertificate(cert);
} }
bool GetSslCipherSuite(bool client, uint16_t* retval) { bool GetSslCipherSuite(bool client, int* retval) {
if (client) if (client)
return client_ssl_->GetSslCipherSuite(retval); return client_ssl_->GetSslCipherSuite(retval);
else else
@ -972,9 +972,9 @@ TEST_P(SSLStreamAdapterTestDTLS, TestGetSslCipherSuite) {
SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_10, rtc::SSL_PROTOCOL_DTLS_10); SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_10, rtc::SSL_PROTOCOL_DTLS_10);
TestHandshake(); TestHandshake();
uint16_t client_cipher; int client_cipher;
ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher)); ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher));
uint16_t server_cipher; int server_cipher;
ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher)); ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher));
ASSERT_EQ(client_cipher, server_cipher); ASSERT_EQ(client_cipher, server_cipher);
@ -990,9 +990,9 @@ TEST_P(SSLStreamAdapterTestDTLS, TestGetSslCipherSuiteDtls12Both) {
SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_12, rtc::SSL_PROTOCOL_DTLS_12); SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_12, rtc::SSL_PROTOCOL_DTLS_12);
TestHandshake(); TestHandshake();
uint16_t client_cipher; int client_cipher;
ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher)); ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher));
uint16_t server_cipher; int server_cipher;
ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher)); ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher));
ASSERT_EQ(client_cipher, server_cipher); ASSERT_EQ(client_cipher, server_cipher);
@ -1007,9 +1007,9 @@ TEST_P(SSLStreamAdapterTestDTLS, TestGetSslCipherSuiteDtls12Client) {
SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_10, rtc::SSL_PROTOCOL_DTLS_12); SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_10, rtc::SSL_PROTOCOL_DTLS_12);
TestHandshake(); TestHandshake();
uint16_t client_cipher; int client_cipher;
ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher)); ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher));
uint16_t server_cipher; int server_cipher;
ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher)); ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher));
ASSERT_EQ(client_cipher, server_cipher); ASSERT_EQ(client_cipher, server_cipher);
@ -1024,9 +1024,9 @@ TEST_P(SSLStreamAdapterTestDTLS, TestGetSslCipherSuiteDtls12Server) {
SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_12, rtc::SSL_PROTOCOL_DTLS_10); SetupProtocolVersions(rtc::SSL_PROTOCOL_DTLS_12, rtc::SSL_PROTOCOL_DTLS_10);
TestHandshake(); TestHandshake();
uint16_t client_cipher; int client_cipher;
ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher)); ASSERT_TRUE(GetSslCipherSuite(true, &client_cipher));
uint16_t server_cipher; int server_cipher;
ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher)); ASSERT_TRUE(GetSslCipherSuite(false, &server_cipher));
ASSERT_EQ(client_cipher, server_cipher); ASSERT_EQ(client_cipher, server_cipher);

View File

@ -186,7 +186,7 @@ bool DtlsTransportChannelWrapper::GetSslRole(rtc::SSLRole* role) const {
return true; return true;
} }
bool DtlsTransportChannelWrapper::GetSslCipherSuite(uint16_t* cipher) { bool DtlsTransportChannelWrapper::GetSslCipherSuite(int* cipher) {
if (dtls_state_ != STATE_OPEN) { if (dtls_state_ != STATE_OPEN) {
return false; return false;
} }

View File

@ -141,7 +141,7 @@ class DtlsTransportChannelWrapper : public TransportChannelImpl {
bool SetSslRole(rtc::SSLRole role) override; bool SetSslRole(rtc::SSLRole role) override;
// Find out which DTLS cipher was negotiated // Find out which DTLS cipher was negotiated
bool GetSslCipherSuite(uint16_t* cipher) override; bool GetSslCipherSuite(int* cipher) override;
// Once DTLS has been established, this method retrieves the certificate in // Once DTLS has been established, this method retrieves the certificate in
// use by the remote peer, for use in external identity verification. // use by the remote peer, for use in external identity verification.

View File

@ -228,10 +228,10 @@ class DtlsTestClient : public sigslot::has_slots<> {
} }
} }
void CheckSsl(uint16_t expected_cipher) { void CheckSsl(int expected_cipher) {
for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it =
channels_.begin(); it != channels_.end(); ++it) { channels_.begin(); it != channels_.end(); ++it) {
uint16_t cipher; int cipher;
bool rv = (*it)->GetSslCipherSuite(&cipher); bool rv = (*it)->GetSslCipherSuite(&cipher);
if (negotiated_dtls_ && expected_cipher) { if (negotiated_dtls_ && expected_cipher) {

View File

@ -251,7 +251,7 @@ class FakeTransportChannel : public TransportChannelImpl,
return false; return false;
} }
bool GetSslCipherSuite(uint16_t* cipher) override { return false; } bool GetSslCipherSuite(int* cipher) override { return false; }
rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const { rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const {
return local_cert_; return local_cert_;

View File

@ -114,7 +114,7 @@ class P2PTransportChannel : public TransportChannelImpl,
bool GetSrtpCryptoSuite(std::string* cipher) override { return false; } bool GetSrtpCryptoSuite(std::string* cipher) override { return false; }
// Find out which DTLS cipher was negotiated. // Find out which DTLS cipher was negotiated.
bool GetSslCipherSuite(uint16_t* cipher) override { return false; } bool GetSslCipherSuite(int* cipher) override { return false; }
// Returns null because the channel is not encrypted by default. // Returns null because the channel is not encrypted by default.
rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override { rtc::scoped_refptr<rtc::RTCCertificate> GetLocalCertificate() const override {

View File

@ -111,7 +111,7 @@ struct TransportChannelStats {
int component = 0; int component = 0;
ConnectionInfos connection_infos; ConnectionInfos connection_infos;
std::string srtp_cipher; std::string srtp_cipher;
uint16_t ssl_cipher = 0; int ssl_cipher = 0;
}; };
// Information about all the channels of a transport. // Information about all the channels of a transport.

View File

@ -113,9 +113,7 @@ class TransportChannel : public sigslot::has_slots<> {
// Finds out which DTLS cipher was negotiated. // Finds out which DTLS cipher was negotiated.
// TODO(guoweis): Remove this once all dependencies implement this. // TODO(guoweis): Remove this once all dependencies implement this.
virtual bool GetSslCipherSuite(uint16_t* cipher) { virtual bool GetSslCipherSuite(int* cipher) { return false; }
return false;
}
// Gets the local RTCCertificate used for DTLS. // Gets the local RTCCertificate used for DTLS.
virtual rtc::scoped_refptr<rtc::RTCCertificate> virtual rtc::scoped_refptr<rtc::RTCCertificate>