From f9da44dbcf3f42a7361688f88c8fcf8f9d237781 Mon Sep 17 00:00:00 2001 From: hbos Date: Thu, 9 Jun 2016 03:18:28 -0700 Subject: [PATCH] RTCPeerConnectionInterface.mm createNativeConfiguration and other clean-up. This CL turns nativeConfiguration into createNativeConfiguration returning a pointer or nil on failure. This method's certificate generation is updated to use the new API and reports failure (nil) if unsuccessful instead of relying on the default certificate. We also remove the implicit assumption (now incorrect) that RSA is the default. This is the same type of changes as was done in https://codereview.webrtc.org/1965313002 but this file (RTCPeerConnectionInterface.mm) was forgotten. With no more usages of kIdentityName it and dtlsidentitystore.cc is removed. Also removes unnecessary #include in peerconnectioninterface.h that was still remnant due to an indirect include of kIdentityName. RTCConfiguration+Private.h now lists method nativeEncryptionKeyTypeForKeyType which was added in the above mentioned prior CL. BUG=webrtc:5707, webrtc:5708 Review-Url: https://codereview.webrtc.org/2035473004 Cr-Commit-Position: refs/heads/master@{#13089} --- talk/app/webrtc/objc/RTCPeerConnection.mm | 8 ++- .../webrtc/objc/RTCPeerConnectionFactory.mm | 7 ++- .../RTCPeerConnectionInterface+Internal.h | 6 +- .../webrtc/objc/RTCPeerConnectionInterface.mm | 59 +++++++++++++------ webrtc/api/BUILD.gn | 1 - webrtc/api/api.gyp | 1 - webrtc/api/dtlsidentitystore.cc | 19 ------ webrtc/api/dtlsidentitystore.h | 5 -- webrtc/api/peerconnectioninterface.h | 1 - .../Classes/RTCConfiguration+Private.h | 2 + .../Framework/Classes/RTCConfiguration.mm | 20 +++---- 11 files changed, 68 insertions(+), 61 deletions(-) delete mode 100644 webrtc/api/dtlsidentitystore.cc diff --git a/talk/app/webrtc/objc/RTCPeerConnection.mm b/talk/app/webrtc/objc/RTCPeerConnection.mm index da092c8026..2491cf7c97 100644 --- a/talk/app/webrtc/objc/RTCPeerConnection.mm +++ b/talk/app/webrtc/objc/RTCPeerConnection.mm @@ -211,8 +211,12 @@ class RTCStatsObserver : public StatsObserver { } - (BOOL)setConfiguration:(RTCConfiguration *)configuration { - return self.peerConnection->SetConfiguration( - configuration.nativeConfiguration); + std::unique_ptr config( + [configuration createNativeConfiguration]); + if (!config) { + return NO; + } + return self.peerConnection->SetConfiguration(*config); } - (RTCSessionDescription*)localDescription { diff --git a/talk/app/webrtc/objc/RTCPeerConnectionFactory.mm b/talk/app/webrtc/objc/RTCPeerConnectionFactory.mm index c156df74a5..13afa8da23 100644 --- a/talk/app/webrtc/objc/RTCPeerConnectionFactory.mm +++ b/talk/app/webrtc/objc/RTCPeerConnectionFactory.mm @@ -99,8 +99,13 @@ - (RTCPeerConnection *)peerConnectionWithConfiguration:(RTCConfiguration *)configuration constraints:(RTCMediaConstraints *)constraints delegate:(id)delegate { + std::unique_ptr config( + [configuration createNativeConfiguration]); + if (!config) { + return nil; + } return [[RTCPeerConnection alloc] initWithFactory:self.nativeFactory.get() - config:configuration.nativeConfiguration + config:*config constraints:constraints.constraints delegate:delegate]; } diff --git a/talk/app/webrtc/objc/RTCPeerConnectionInterface+Internal.h b/talk/app/webrtc/objc/RTCPeerConnectionInterface+Internal.h index ffa01c6fff..ecd236d971 100644 --- a/talk/app/webrtc/objc/RTCPeerConnectionInterface+Internal.h +++ b/talk/app/webrtc/objc/RTCPeerConnectionInterface+Internal.h @@ -31,7 +31,9 @@ @interface RTCConfiguration () -@property(nonatomic, readonly) - webrtc::PeerConnectionInterface::RTCConfiguration nativeConfiguration; ++ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:(RTCEncryptionKeyType)keyType; + +- (webrtc::PeerConnectionInterface::RTCConfiguration *) + createNativeConfiguration; @end diff --git a/talk/app/webrtc/objc/RTCPeerConnectionInterface.mm b/talk/app/webrtc/objc/RTCPeerConnectionInterface.mm index 7cc10e9d85..1ab9c56429 100644 --- a/talk/app/webrtc/objc/RTCPeerConnectionInterface.mm +++ b/talk/app/webrtc/objc/RTCPeerConnectionInterface.mm @@ -33,6 +33,8 @@ #include +#include "webrtc/base/rtccertificategenerator.h" + @implementation RTCConfiguration @synthesize iceTransportsType = _iceTransportsType; @@ -83,30 +85,49 @@ #pragma mark - Private -- (webrtc::PeerConnectionInterface::RTCConfiguration)nativeConfiguration { - webrtc::PeerConnectionInterface::RTCConfiguration nativeConfig; - nativeConfig.type = [RTCEnumConverter nativeEnumForIceTransportsType:_iceTransportsType]; +- (webrtc::PeerConnectionInterface::RTCConfiguration *) + createNativeConfiguration { + std::unique_ptr + nativeConfig(new webrtc::PeerConnectionInterface::RTCConfiguration()); + nativeConfig->type = + [RTCEnumConverter nativeEnumForIceTransportsType:_iceTransportsType]; for (RTCICEServer *iceServer : _iceServers) { - nativeConfig.servers.push_back(iceServer.iceServer); + nativeConfig->servers.push_back(iceServer.iceServer); } - nativeConfig.bundle_policy = [RTCEnumConverter nativeEnumForBundlePolicy:_bundlePolicy]; - nativeConfig.rtcp_mux_policy = [RTCEnumConverter nativeEnumForRtcpMuxPolicy:_rtcpMuxPolicy]; - nativeConfig.tcp_candidate_policy = + nativeConfig->bundle_policy = + [RTCEnumConverter nativeEnumForBundlePolicy:_bundlePolicy]; + nativeConfig->rtcp_mux_policy = + [RTCEnumConverter nativeEnumForRtcpMuxPolicy:_rtcpMuxPolicy]; + nativeConfig->tcp_candidate_policy = [RTCEnumConverter nativeEnumForTcpCandidatePolicy:_tcpCandidatePolicy]; - nativeConfig.audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; - nativeConfig.ice_connection_receiving_timeout = _iceConnectionReceivingTimeout; - nativeConfig.ice_backup_candidate_pair_ping_interval = _iceBackupCandidatePairPingInterval; - if (_keyType == kRTCEncryptionKeyTypeECDSA) { - std::unique_ptr identity( - rtc::SSLIdentity::Generate(webrtc::kIdentityName, rtc::KT_ECDSA)); - if (identity) { - nativeConfig.certificates.push_back( - rtc::RTCCertificate::Create(std::move(identity))); - } else { - RTCLogWarning(@"Failed to generate ECDSA identity. RSA will be used."); + nativeConfig->audio_jitter_buffer_max_packets = _audioJitterBufferMaxPackets; + nativeConfig->ice_connection_receiving_timeout = + _iceConnectionReceivingTimeout; + nativeConfig->ice_backup_candidate_pair_ping_interval = + _iceBackupCandidatePairPingInterval; + rtc::KeyType keyType = + [[self class] nativeEncryptionKeyTypeForKeyType:_keyType]; + if (keyType != rtc::KT_DEFAULT) { + rtc::scoped_refptr certificate = + rtc::RTCCertificateGenerator::GenerateCertificate( + rtc::KeyParams(keyType), rtc::Optional()); + if (!certificate) { + RTCLogError(@"Failed to generate certificate."); + return nullptr; } + nativeConfig->certificates.push_back(certificate); + } + return nativeConfig.release(); +} + ++ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType: + (RTCEncryptionKeyType)keyType { + switch (keyType) { + case kRTCEncryptionKeyTypeRSA: + return rtc::KT_RSA; + case kRTCEncryptionKeyTypeECDSA: + return rtc::KT_ECDSA; } - return nativeConfig; } @end diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn index b7d87ef482..ecef934a3e 100644 --- a/webrtc/api/BUILD.gn +++ b/webrtc/api/BUILD.gn @@ -34,7 +34,6 @@ source_set("libjingle_peerconnection") { "datachannel.cc", "datachannel.h", "datachannelinterface.h", - "dtlsidentitystore.cc", "dtlsidentitystore.h", "dtmfsender.cc", "dtmfsender.h", diff --git a/webrtc/api/api.gyp b/webrtc/api/api.gyp index 26720cfb6b..f63e7e4b11 100644 --- a/webrtc/api/api.gyp +++ b/webrtc/api/api.gyp @@ -135,7 +135,6 @@ 'datachannel.cc', 'datachannel.h', 'datachannelinterface.h', - 'dtlsidentitystore.cc', 'dtlsidentitystore.h', 'dtmfsender.cc', 'dtmfsender.h', diff --git a/webrtc/api/dtlsidentitystore.cc b/webrtc/api/dtlsidentitystore.cc deleted file mode 100644 index 620b942102..0000000000 --- a/webrtc/api/dtlsidentitystore.cc +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2015 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/api/dtlsidentitystore.h" - -namespace webrtc { - -// Passed to SSLIdentity::Generate, "WebRTC". Used for the certificates' -// subject and issuer name. -const char kIdentityName[] = "WebRTC"; - -} // namespace webrtc diff --git a/webrtc/api/dtlsidentitystore.h b/webrtc/api/dtlsidentitystore.h index 89644a75a3..2558e45db4 100644 --- a/webrtc/api/dtlsidentitystore.h +++ b/webrtc/api/dtlsidentitystore.h @@ -27,11 +27,6 @@ namespace webrtc { -// TODO(hbos): Remove this constant (and dtlsidentitystore.cc) after -// RTCPeerConnectionInterface.mm stops using it. -// bugs.webrtc.org/5707, bugs.webrtc.org/5708 -extern const char kIdentityName[]; - class SSLIdentity; class Thread; diff --git a/webrtc/api/peerconnectioninterface.h b/webrtc/api/peerconnectioninterface.h index 5ff8019a04..0ac37e1564 100644 --- a/webrtc/api/peerconnectioninterface.h +++ b/webrtc/api/peerconnectioninterface.h @@ -57,7 +57,6 @@ #include #include "webrtc/api/datachannelinterface.h" -#include "webrtc/api/dtlsidentitystore.h" #include "webrtc/api/dtmfsenderinterface.h" #include "webrtc/api/jsep.h" #include "webrtc/api/mediastreaminterface.h" diff --git a/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h b/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h index 7ea87148ca..f20cdc5c4a 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h +++ b/webrtc/sdk/objc/Framework/Classes/RTCConfiguration+Private.h @@ -56,6 +56,8 @@ NS_ASSUME_NONNULL_BEGIN + (NSString *)stringForCandidateNetworkPolicy:(RTCCandidateNetworkPolicy)policy; ++ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:(RTCEncryptionKeyType)keyType; + /** * RTCConfiguration struct representation of this RTCConfiguration. This is * needed to pass to the underlying C++ APIs. diff --git a/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm b/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm index c9730cf8c8..b315e5073f 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCConfiguration.mm @@ -250,16 +250,6 @@ } } -+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType: - (RTCEncryptionKeyType)keyType { - switch (keyType) { - case RTCEncryptionKeyTypeRSA: - return rtc::KT_RSA; - case RTCEncryptionKeyTypeECDSA: - return rtc::KT_ECDSA; - } -} - + (RTCTcpCandidatePolicy)tcpCandidatePolicyForNativePolicy: (webrtc::PeerConnectionInterface::TcpCandidatePolicy)nativePolicy { switch (nativePolicy) { @@ -330,4 +320,14 @@ } } ++ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType: + (RTCEncryptionKeyType)keyType { + switch (keyType) { + case RTCEncryptionKeyTypeRSA: + return rtc::KT_RSA; + case RTCEncryptionKeyTypeECDSA: + return rtc::KT_ECDSA; + } +} + @end