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}
This commit is contained in:
@ -211,8 +211,12 @@ class RTCStatsObserver : public StatsObserver {
|
||||
}
|
||||
|
||||
- (BOOL)setConfiguration:(RTCConfiguration *)configuration {
|
||||
return self.peerConnection->SetConfiguration(
|
||||
configuration.nativeConfiguration);
|
||||
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
|
||||
[configuration createNativeConfiguration]);
|
||||
if (!config) {
|
||||
return NO;
|
||||
}
|
||||
return self.peerConnection->SetConfiguration(*config);
|
||||
}
|
||||
|
||||
- (RTCSessionDescription*)localDescription {
|
||||
|
||||
@ -99,8 +99,13 @@
|
||||
- (RTCPeerConnection *)peerConnectionWithConfiguration:(RTCConfiguration *)configuration
|
||||
constraints:(RTCMediaConstraints *)constraints
|
||||
delegate:(id<RTCPeerConnectionDelegate>)delegate {
|
||||
std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration> config(
|
||||
[configuration createNativeConfiguration]);
|
||||
if (!config) {
|
||||
return nil;
|
||||
}
|
||||
return [[RTCPeerConnection alloc] initWithFactory:self.nativeFactory.get()
|
||||
config:configuration.nativeConfiguration
|
||||
config:*config
|
||||
constraints:constraints.constraints
|
||||
delegate:delegate];
|
||||
}
|
||||
|
||||
@ -31,7 +31,9 @@
|
||||
|
||||
@interface RTCConfiguration ()
|
||||
|
||||
@property(nonatomic, readonly)
|
||||
webrtc::PeerConnectionInterface::RTCConfiguration nativeConfiguration;
|
||||
+ (rtc::KeyType)nativeEncryptionKeyTypeForKeyType:(RTCEncryptionKeyType)keyType;
|
||||
|
||||
- (webrtc::PeerConnectionInterface::RTCConfiguration *)
|
||||
createNativeConfiguration;
|
||||
|
||||
@end
|
||||
|
||||
@ -33,6 +33,8 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#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<webrtc::PeerConnectionInterface::RTCConfiguration>
|
||||
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<rtc::SSLIdentity> 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<rtc::RTCCertificate> certificate =
|
||||
rtc::RTCCertificateGenerator::GenerateCertificate(
|
||||
rtc::KeyParams(keyType), rtc::Optional<uint64_t>());
|
||||
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
|
||||
|
||||
@ -34,7 +34,6 @@ source_set("libjingle_peerconnection") {
|
||||
"datachannel.cc",
|
||||
"datachannel.h",
|
||||
"datachannelinterface.h",
|
||||
"dtlsidentitystore.cc",
|
||||
"dtlsidentitystore.h",
|
||||
"dtmfsender.cc",
|
||||
"dtmfsender.h",
|
||||
|
||||
@ -135,7 +135,6 @@
|
||||
'datachannel.cc',
|
||||
'datachannel.h',
|
||||
'datachannelinterface.h',
|
||||
'dtlsidentitystore.cc',
|
||||
'dtlsidentitystore.h',
|
||||
'dtmfsender.cc',
|
||||
'dtmfsender.h',
|
||||
|
||||
@ -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
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -57,7 +57,6 @@
|
||||
#include <vector>
|
||||
|
||||
#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"
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user