Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Unified Diff: content/renderer/media/rtc_peer_connection_handler.cc

Issue 1972853003: content::RTCCertificateGenerator and WebRTC-EnableWebRtcEcdsa update. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/rtc_peer_connection_handler.cc
diff --git a/content/renderer/media/rtc_peer_connection_handler.cc b/content/renderer/media/rtc_peer_connection_handler.cc
index d11ba1b0cee4b820674c298e853e262db5620f16..3287f9758df74a05d0323d13bb937d4eef10686b 100644
--- a/content/renderer/media/rtc_peer_connection_handler.cc
+++ b/content/renderer/media/rtc_peer_connection_handler.cc
@@ -28,6 +28,7 @@
#include "content/renderer/media/peer_connection_tracker.h"
#include "content/renderer/media/remote_media_stream_impl.h"
#include "content/renderer/media/rtc_certificate.h"
+#include "content/renderer/media/rtc_certificate_generator.h"
#include "content/renderer/media/rtc_data_channel_handler.h"
#include "content/renderer/media/rtc_dtmf_sender_handler.h"
#include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
@@ -724,6 +725,30 @@ void ConvertConstraintsToWebrtcOfferOptions(
base::LazyInstance<std::set<RTCPeerConnectionHandler*> >::Leaky
g_peer_connection_handlers = LAZY_INSTANCE_INITIALIZER;
+void OverrideDefaultCertificateBasedOnExperiment(
+ webrtc::PeerConnectionInterface::RTCConfiguration* config) {
+ if (!config->certificates.empty())
+ return; // A certificate has already been set up to override the default.
+ rtc::KeyType key_type;
+ if (base::FeatureList::IsEnabled(features::kWebRtcEcdsaDefault)) {
+ key_type = rtc::KT_ECDSA;
+ } else {
+ key_type = rtc::KT_RSA;
+ }
+ if (key_type != rtc::KT_DEFAULT) {
+ scoped_refptr<rtc::RTCCertificate> certificate =
+ RTCCertificateGenerator::generateCertificateAndWait(
+ rtc::KeyParams(key_type), rtc::Optional<uint64_t>());
+ if (!certificate) {
+ // This should not happen, but if it does it is better than crashing.
+ LOG(WARNING) << "Failed to generate certificate, will rely on default "
+ "instead.";
+ } else {
+ config->certificates.push_back(certificate.get());
+ }
+ }
+}
+
} // namespace
// Implementation of LocalRTCStatsRequest.
@@ -954,14 +979,7 @@ bool RTCPeerConnectionHandler::initialize(
webrtc::PeerConnectionInterface::RTCConfiguration config;
GetNativeRtcConfiguration(server_configuration, &config);
-
- if (base::FeatureList::IsEnabled(features::kWebRtcEcdsaDefault)) {
- if (config.certificates.empty()) {
- rtc::scoped_refptr<rtc::RTCCertificate> certificate =
- PeerConnectionDependencyFactory::GenerateDefaultCertificate();
- config.certificates.push_back(certificate);
- }
- }
+ OverrideDefaultCertificateBasedOnExperiment(&config);
// Choose between RTC smoothness algorithm and prerenderer smoothing.
// Prerenderer smoothing is turned on if RTC smoothness is turned off.
@@ -998,14 +1016,7 @@ bool RTCPeerConnectionHandler::InitializeForTest(
DCHECK(thread_checker_.CalledOnValidThread());
webrtc::PeerConnectionInterface::RTCConfiguration config;
GetNativeRtcConfiguration(server_configuration, &config);
-
- if (base::FeatureList::IsEnabled(features::kWebRtcEcdsaDefault)) {
- if (config.certificates.empty()) {
- rtc::scoped_refptr<rtc::RTCCertificate> certificate =
- PeerConnectionDependencyFactory::GenerateDefaultCertificate();
- config.certificates.push_back(certificate);
- }
- }
+ OverrideDefaultCertificateBasedOnExperiment(&config);
peer_connection_observer_ = new Observer(weak_factory_.GetWeakPtr());
CopyConstraintsIntoRtcConfiguration(options, &config);

Powered by Google App Engine
This is Rietveld 408576698