Commit f8d545d6 authored by Harald Alvestrand's avatar Harald Alvestrand Committed by Commit Bot

Generate UKM metric for notable WebRTC usage patterns

This is part of an effort to characterize RTCPeerConnection usage.

UKM metric review document: https://docs.google.com/document/d/1Pq6Xxv8Mf10cgRFDCYPgIPD-US7uHyxQ31hdZT6uu4Y/edit

Bug: chromium:866792
Change-Id: I38e0d7ee406e6246d8d013d7f96ad50f51b96a78
Reviewed-on: https://chromium-review.googlesource.com/1150539
Commit-Queue: Harald Alvestrand <hta@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarHenrik Boström <hbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580760}
parent cd7b545a
...@@ -47,6 +47,7 @@ class MockWebRTCPeerConnectionHandlerClient ...@@ -47,6 +47,7 @@ class MockWebRTCPeerConnectionHandlerClient
DidModifyTransceiversForMock(&web_transceivers, is_remote_description); DidModifyTransceiversForMock(&web_transceivers, is_remote_description);
} }
MOCK_METHOD1(DidAddRemoteDataChannel, void(blink::WebRTCDataChannelHandler*)); MOCK_METHOD1(DidAddRemoteDataChannel, void(blink::WebRTCDataChannelHandler*));
MOCK_METHOD1(DidNoteInterestingUsage, void(int));
MOCK_METHOD0(ReleasePeerConnectionHandler, void()); MOCK_METHOD0(ReleasePeerConnectionHandler, void());
// Move-only arguments do not play nicely with MOCK, the workaround is to // Move-only arguments do not play nicely with MOCK, the workaround is to
......
...@@ -1021,6 +1021,21 @@ class RTCPeerConnectionHandler::Observer ...@@ -1021,6 +1021,21 @@ class RTCPeerConnectionHandler::Observer
} }
} }
void OnInterestingUsage(int usage_pattern) override {
main_thread_->PostTask(
FROM_HERE,
base::BindOnce(
&RTCPeerConnectionHandler::Observer::OnInterestingUsageImpl, this,
usage_pattern));
}
void OnInterestingUsageImpl(int usage_pattern) {
DCHECK(main_thread_->BelongsToCurrentThread());
if (handler_) {
handler_->OnInterestingUsage(usage_pattern);
}
}
private: private:
const base::WeakPtr<RTCPeerConnectionHandler> handler_; const base::WeakPtr<RTCPeerConnectionHandler> handler_;
const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; const scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
...@@ -2175,6 +2190,10 @@ void RTCPeerConnectionHandler::OnIceCandidate( ...@@ -2175,6 +2190,10 @@ void RTCPeerConnectionHandler::OnIceCandidate(
client_->DidGenerateICECandidate(std::move(web_candidate)); client_->DidGenerateICECandidate(std::move(web_candidate));
} }
void RTCPeerConnectionHandler::OnInterestingUsage(int usage_pattern) {
client_->DidNoteInterestingUsage(usage_pattern);
}
webrtc::SessionDescriptionInterface* webrtc::SessionDescriptionInterface*
RTCPeerConnectionHandler::CreateNativeSessionDescription( RTCPeerConnectionHandler::CreateNativeSessionDescription(
const std::string& sdp, const std::string& type, const std::string& sdp, const std::string& type,
......
...@@ -217,6 +217,7 @@ class CONTENT_EXPORT RTCPeerConnectionHandler ...@@ -217,6 +217,7 @@ class CONTENT_EXPORT RTCPeerConnectionHandler
int sdp_mline_index, int sdp_mline_index,
int component, int component,
int address_family); int address_family);
void OnInterestingUsage(int usage_pattern);
private: private:
// Record info about the first SessionDescription from the local and // Record info about the first SessionDescription from the local and
......
<!DOCTYPE html>
<html>
<head>
<title>RTCPeerConnection address harvesting</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<script>
promise_test(async function() {
let pc = new RTCPeerConnection();
pc.createDataChannel('foo');
let candidates = [];
pc.onicecandidate = function(event) {
if (event.candidate) {
candidates.push(event.candidate);
}
}
let gatheringDone = new Promise(function(resolve, reject) {
pc.onicegatheringstatechange = function() {
if (pc.iceGatheringState == 'complete') {
resolve();
}
}
});
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
await gatheringDone;
assert_true(candidates.length > 0);
pc.close();
}, 'Test that address harvesting does not cause crash');
</script>
</body>
</html>
...@@ -79,6 +79,7 @@ class BLINK_PLATFORM_EXPORT WebRTCPeerConnectionHandlerClient { ...@@ -79,6 +79,7 @@ class BLINK_PLATFORM_EXPORT WebRTCPeerConnectionHandlerClient {
std::vector<std::unique_ptr<WebRTCRtpTransceiver>>, std::vector<std::unique_ptr<WebRTCRtpTransceiver>>,
bool is_remote_description) = 0; bool is_remote_description) = 0;
virtual void DidAddRemoteDataChannel(WebRTCDataChannelHandler*) = 0; virtual void DidAddRemoteDataChannel(WebRTCDataChannelHandler*) = 0;
virtual void DidNoteInterestingUsage(int usage_pattern) = 0;
virtual void ReleasePeerConnectionHandler() = 0; virtual void ReleasePeerConnectionHandler() = 0;
virtual void ClosePeerConnection(); virtual void ClosePeerConnection();
}; };
......
include_rules = [ include_rules = [
"+services/metrics/public/cpp/ukm_builders.h",
"-third_party/blink/renderer/modules", "-third_party/blink/renderer/modules",
"+third_party/blink/renderer/modules/crypto", "+third_party/blink/renderer/modules/crypto",
"+third_party/blink/renderer/modules/event_modules.h", "+third_party/blink/renderer/modules/event_modules.h",
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/optional.h" #include "base/optional.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "third_party/blink/public/platform/platform.h" #include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/task_type.h" #include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/public/platform/web_crypto_algorithm_params.h" #include "third_party/blink/public/platform/web_crypto_algorithm_params.h"
...@@ -2191,6 +2192,14 @@ void RTCPeerConnection::DidAddRemoteDataChannel( ...@@ -2191,6 +2192,14 @@ void RTCPeerConnection::DidAddRemoteDataChannel(
has_data_channels_ = true; has_data_channels_ = true;
} }
void RTCPeerConnection::DidNoteInterestingUsage(int usage_pattern) {
Document* document = ToDocument(GetExecutionContext());
ukm::SourceId source_id = document->UkmSourceID();
ukm::builders::WebRTC_AddressHarvesting(source_id)
.SetUsagePattern(usage_pattern)
.Record(document->UkmRecorder());
}
void RTCPeerConnection::ReleasePeerConnectionHandler() { void RTCPeerConnection::ReleasePeerConnectionHandler() {
if (stopped_) if (stopped_)
return; return;
......
...@@ -234,6 +234,7 @@ class MODULES_EXPORT RTCPeerConnection final ...@@ -234,6 +234,7 @@ class MODULES_EXPORT RTCPeerConnection final
void DidModifyTransceivers(std::vector<std::unique_ptr<WebRTCRtpTransceiver>>, void DidModifyTransceivers(std::vector<std::unique_ptr<WebRTCRtpTransceiver>>,
bool is_remote_description) override; bool is_remote_description) override;
void DidAddRemoteDataChannel(WebRTCDataChannelHandler*) override; void DidAddRemoteDataChannel(WebRTCDataChannelHandler*) override;
void DidNoteInterestingUsage(int usage_pattern) override;
void ReleasePeerConnectionHandler() override; void ReleasePeerConnectionHandler() override;
void ClosePeerConnection() override; void ClosePeerConnection() override;
......
...@@ -4624,4 +4624,21 @@ be describing additional metrics about the same event. ...@@ -4624,4 +4624,21 @@ be describing additional metrics about the same event.
</metric> </metric>
</event> </event>
<event name="WebRTC.AddressHarvesting">
<owner>hta@chromium.org</owner>
<summary>
Collects usage patterns that may indicate attempts to gather users' IP
addresses. A heuristic in the webrtc library tries to detect usages that may
indicate attempts to gather users' IP addresses rather than setting up
communication via WebRTC, and reports possible attempts.
</summary>
<metric name="UsagePattern">
<summary>
The usage pattern detected (an int encoding bit values). The bits are
defined in third_party/webrtc/pc/peerconnection.h, in the
&quot;PeerConnection::UsageEvent&quot; enum.
</summary>
</metric>
</event>
</ukm-configuration> </ukm-configuration>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment