Skip to content

Commit 18598df

Browse files
author
Jiewen Tan
committed
PCM: Generate secret token and corresponding unlinkable token
https://bugs.webkit.org/show_bug.cgi?id=222019 <rdar://problem/73581412> Reviewed by John Wilander. Source/WebCore: Covered by API tests. This patch utilizes RSABSSA to generate secret token for PCM fraud prevention. * Configurations/WebCore.xcconfig: * SourcesCocoa.txt: * WebCore.xcodeproj/project.pbxproj: Paperwork to link CryptoKitCBridging. * loader/PrivateClickMeasurement.cpp: (WebCore::PrivateClickMeasurement::EphemeralSourceNonce::isValid const): (WebCore::PrivateClickMeasurement::setEphemeralSourceNonce): * loader/PrivateClickMeasurement.h: (WebCore::PrivateClickMeasurement::attributeOnSite const): (WebCore::PrivateClickMeasurement::ephemeralSourceNonce const): (WebCore::PrivateClickMeasurement::clearEphemeralSourceNonce): (WebCore::PrivateClickMeasurement::EphemeralSourceNonce::EphemeralSourceNonce): Deleted. (WebCore::PrivateClickMeasurement::EphemeralSourceNonce::isValid const): Deleted. (WebCore::PrivateClickMeasurement::setEphemeralSourceNonce): Deleted. Groups functionalities behind HAVE_RSA_BSSA. * loader/cocoa/PrivateClickMeasurementCocoa.mm: Added. (WebCore::PrivateClickMeasurement::blindedSecretJson): (WebCore::PrivateClickMeasurement::calculatePersistentBlindedToken): Introduces new methods to generate the blinded secrets and unlinkable tokens. Source/WTF: * wtf/PlatformHave.h: Adds a compile time flag for RSABSSA. Tools: * TestWebKitAPI/Tests/WebCore/PrivateClickMeasurement.cpp: (TestWebKitAPI::TEST): Add tests. Canonical link: https://commits.webkit.org/234362@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@273167 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent efbaf29 commit 18598df

19 files changed

Lines changed: 497 additions & 75 deletions

LayoutTests/http/tests/privateClickMeasurement/store-private-click-measurement-with-source-nonce-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Content type: application/json
1818
REQUEST_URI: /privateClickMeasurement/resources/signToken.php
1919
No cookies in token signing request.
2020
Request body:
21-
{"source_engagement_type":"click","source_nonce":"ABCDEFabcdef0123456789","unlinkable_token":"TODO","version":2}
21+
{}
2222

2323
Unattributed Private Click Measurements:
2424
WebCore::PrivateClickMeasurement 1

Source/WTF/ChangeLog

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
2021-02-16 Jiewen Tan <[email protected]>
2+
3+
PCM: Generate secret token and corresponding unlinkable token
4+
https://bugs.webkit.org/show_bug.cgi?id=222019
5+
<rdar://problem/73581412>
6+
7+
Reviewed by John Wilander.
8+
9+
* wtf/PlatformHave.h:
10+
Adds a compile time flag for RSABSSA.
11+
112
2021-02-19 Jer Noble <[email protected]>
213

314
[Cocoa] Enable Opus decode support by default

Source/WTF/wtf/PlatformHave.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,3 +888,8 @@
888888
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000
889889
#define HAVE_STATIC_FONT_REGISTRY 1
890890
#endif
891+
892+
#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 120000) \
893+
|| (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 150000)
894+
#define HAVE_RSA_BSSA 1
895+
#endif

Source/WebCore/ChangeLog

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
2021-02-16 Jiewen Tan <[email protected]>
2+
3+
PCM: Generate secret token and corresponding unlinkable token
4+
https://bugs.webkit.org/show_bug.cgi?id=222019
5+
<rdar://problem/73581412>
6+
7+
Reviewed by John Wilander.
8+
9+
Covered by API tests.
10+
11+
This patch utilizes RSABSSA to generate secret token for PCM fraud prevention.
12+
13+
* Configurations/WebCore.xcconfig:
14+
* SourcesCocoa.txt:
15+
* WebCore.xcodeproj/project.pbxproj:
16+
Paperwork to link CryptoKitCBridging.
17+
18+
* loader/PrivateClickMeasurement.cpp:
19+
(WebCore::PrivateClickMeasurement::EphemeralSourceNonce::isValid const):
20+
(WebCore::PrivateClickMeasurement::setEphemeralSourceNonce):
21+
* loader/PrivateClickMeasurement.h:
22+
(WebCore::PrivateClickMeasurement::attributeOnSite const):
23+
(WebCore::PrivateClickMeasurement::ephemeralSourceNonce const):
24+
(WebCore::PrivateClickMeasurement::clearEphemeralSourceNonce):
25+
(WebCore::PrivateClickMeasurement::EphemeralSourceNonce::EphemeralSourceNonce): Deleted.
26+
(WebCore::PrivateClickMeasurement::EphemeralSourceNonce::isValid const): Deleted.
27+
(WebCore::PrivateClickMeasurement::setEphemeralSourceNonce): Deleted.
28+
Groups functionalities behind HAVE_RSA_BSSA.
29+
30+
* loader/cocoa/PrivateClickMeasurementCocoa.mm: Added.
31+
(WebCore::PrivateClickMeasurement::blindedSecretJson):
32+
(WebCore::PrivateClickMeasurement::calculatePersistentBlindedToken):
33+
Introduces new methods to generate the blinded secrets and unlinkable tokens.
34+
135
2021-02-19 Devin Rousso <[email protected]>
236

337
[Payment Request] add support for Apple Pay payment method mode

Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@
138138
570AB8F920AF6E3D00B8BE87 /* NSXPCConnectionSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 570AB8F820AF6E3D00B8BE87 /* NSXPCConnectionSPI.h */; };
139139
572A107822B456F500F410C8 /* AuthKitSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 572A107722B456F500F410C8 /* AuthKitSPI.h */; };
140140
576CA9D622B854AB0030143C /* AppSSOSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 576CA9D522B854AB0030143C /* AppSSOSPI.h */; };
141+
57F1C90925DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 57F1C90725DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.h */; };
142+
57F1C90A25DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 57F1C90825DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.mm */; };
141143
57FD318A22B3593E008D0E8B /* AppSSOSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 57FD318922B3593E008D0E8B /* AppSSOSoftLink.mm */; };
142144
57FD318B22B35989008D0E8B /* AppSSOSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 57FD318822B3592F008D0E8B /* AppSSOSoftLink.h */; };
143145
5C7C787323AC3E770065F47E /* ManagedConfigurationSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 5C7C787123AC3E770065F47E /* ManagedConfigurationSoftLink.h */; };
@@ -341,6 +343,8 @@
341343
570AB8F820AF6E3D00B8BE87 /* NSXPCConnectionSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSXPCConnectionSPI.h; sourceTree = "<group>"; };
342344
572A107722B456F500F410C8 /* AuthKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AuthKitSPI.h; sourceTree = "<group>"; };
343345
576CA9D522B854AB0030143C /* AppSSOSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppSSOSPI.h; sourceTree = "<group>"; };
346+
57F1C90725DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CryptoKitCBridgingSoftLink.h; sourceTree = "<group>"; };
347+
57F1C90825DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CryptoKitCBridgingSoftLink.mm; sourceTree = "<group>"; };
344348
57FD318822B3592F008D0E8B /* AppSSOSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppSSOSoftLink.h; sourceTree = "<group>"; };
345349
57FD318922B3593E008D0E8B /* AppSSOSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AppSSOSoftLink.mm; sourceTree = "<group>"; };
346350
5C7C787123AC3E770065F47E /* ManagedConfigurationSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ManagedConfigurationSoftLink.h; sourceTree = "<group>"; };
@@ -691,6 +695,8 @@
691695
57FD318922B3593E008D0E8B /* AppSSOSoftLink.mm */,
692696
077E87B0226A460200A2AFF0 /* AVFoundationSoftLink.h */,
693697
077E87AF226A460200A2AFF0 /* AVFoundationSoftLink.mm */,
698+
57F1C90725DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.h */,
699+
57F1C90825DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.mm */,
694700
F44291661FA52705002CC93E /* FileSizeFormatterCocoa.mm */,
695701
1C022EFC22CFE8E0006DF01B /* Gunzip.cpp */,
696702
CDACB35E23873E480018D7CE /* MediaToolboxSoftLink.cpp */,
@@ -828,6 +834,7 @@
828834
1CCEE4F520D871930047B097 /* CoreUISPI.h in Headers */,
829835
0C5AF9191F43A4C7002EAC02 /* CoreUISPI.h in Headers */,
830836
1C09D0531E31C44100725F18 /* CryptoDigest.h in Headers */,
837+
57F1C90925DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.h in Headers */,
831838
0C2DA1411F3BEB4900DBC317 /* DataDetectorsCoreSPI.h in Headers */,
832839
0C77858A1F45130F00F4EBB6 /* DataDetectorsSPI.h in Headers */,
833840
0C5AF91A1F43A4C7002EAC02 /* DataDetectorsUISPI.h in Headers */,
@@ -1037,6 +1044,7 @@
10371044
0CF99CA81F738437007EE793 /* CoreMediaSoftLink.cpp in Sources */,
10381045
1C77C8C925D7972000635E0C /* CoreTextSoftLink.cpp in Sources */,
10391046
1C09D0561E31C46500725F18 /* CryptoDigestCommonCrypto.cpp in Sources */,
1047+
57F1C90A25DCF0CF00E8F6EA /* CryptoKitCBridgingSoftLink.mm in Sources */,
10401048
A1175B581F6B470500C4B9F0 /* DefaultSearchProvider.cpp in Sources */,
10411049
F44291641FA52670002CC93E /* FileSizeFormatter.cpp in Sources */,
10421050
F44291681FA52705002CC93E /* FileSizeFormatterCocoa.mm in Sources */,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2021 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#pragma once
27+
28+
#if HAVE(RSA_BSSA)
29+
30+
#import <CryptoKitCBridging/RSABSSA.h>
31+
#import <wtf/SoftLinking.h>
32+
33+
SOFT_LINK_FRAMEWORK_FOR_HEADER(PAL, CryptoKitCBridging);
34+
35+
SOFT_LINK_CLASS_FOR_HEADER(PAL, RSABSSATokenBlinder);
36+
37+
#endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C) 2021 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23+
* THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#include "config.h"
27+
28+
#if HAVE(RSA_BSSA)
29+
30+
#import <wtf/SoftLinking.h>
31+
32+
SOFT_LINK_PRIVATE_FRAMEWORK_FOR_SOURCE_WITH_EXPORT(PAL, CryptoKitCBridging, PAL_EXPORT);
33+
34+
SOFT_LINK_CLASS_FOR_SOURCE_WITH_EXPORT(PAL, CryptoKitCBridging, RSABSSATokenBlinder, PAL_EXPORT);
35+
36+
#endif

Source/WebCore/SourcesCocoa.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ inspector/mac/PageDebuggerMac.mm
169169
loader/archive/cf/LegacyWebArchive.cpp
170170
loader/archive/cf/LegacyWebArchiveMac.mm
171171
loader/cocoa/DiskCacheMonitorCocoa.mm
172+
loader/cocoa/PrivateClickMeasurementCocoa.mm
172173
loader/cocoa/SubresourceLoaderCocoa.mm
173174
loader/ios/LegacyPreviewLoader.mm
174175
loader/mac/DocumentLoaderMac.cpp

Source/WebCore/WebCore.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9421,6 +9421,7 @@
94219421
57EEAA571EA0AFBB00701124 /* CommonCryptoDERUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CommonCryptoDERUtilities.cpp; sourceTree = "<group>"; };
94229422
57EF5E5F1D20C83900171E60 /* TextCodecReplacement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextCodecReplacement.h; sourceTree = "<group>"; };
94239423
57EF5E611D20D28700171E60 /* TextCodecReplacement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextCodecReplacement.cpp; sourceTree = "<group>"; };
9424+
57F1C8E325DC6EE700E8F6EA /* PrivateClickMeasurementCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PrivateClickMeasurementCocoa.mm; sourceTree = "<group>"; };
94249425
57F827391DB72C22009D2BF4 /* RsaHashedKeyGenParams.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = RsaHashedKeyGenParams.idl; sourceTree = "<group>"; };
94259426
57FEDD3D1DB6D47F00EB96F5 /* RsaKeyGenParams.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = RsaKeyGenParams.idl; sourceTree = "<group>"; };
94269427
57FEDD3E1DB6D59200EB96F5 /* CryptoAlgorithmRsaKeyGenParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CryptoAlgorithmRsaKeyGenParams.h; sourceTree = "<group>"; };
@@ -9736,7 +9737,7 @@
97369737
6A22E8721F1042C400F546C3 /* InspectorCanvas.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorCanvas.cpp; sourceTree = "<group>"; };
97379738
6A7279881F16C29B003F39B8 /* InspectorShaderProgram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorShaderProgram.h; sourceTree = "<group>"; };
97389739
6A7279891F16C29B003F39B8 /* InspectorShaderProgram.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorShaderProgram.cpp; sourceTree = "<group>"; };
9739-
6B0A07F021FA4B5C00D57391 /* PrivateClickMeasurement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrivateClickMeasurement.h; sourceTree = "<group>"; };
9740+
6B0A07F021FA4B5C00D57391 /* PrivateClickMeasurement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrivateClickMeasurement.h; sourceTree = "<group>"; };
97409741
6B0A07F121FA4B5C00D57391 /* PrivateClickMeasurement.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PrivateClickMeasurement.cpp; sourceTree = "<group>"; };
97419742
6B1F480F22989EC400DE8B82 /* CrossSiteNavigationDataTransfer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CrossSiteNavigationDataTransfer.h; sourceTree = "<group>"; };
97429743
6B4D412B23983F88002494C2 /* LoggedInStatus.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LoggedInStatus.h; sourceTree = "<group>"; };
@@ -22973,6 +22974,7 @@
2297322974
children = (
2297422975
7EDAAFC819A2CBD10034DFD1 /* DiskCacheMonitorCocoa.h */,
2297522976
7E4DE10C198B10B60051CB02 /* DiskCacheMonitorCocoa.mm */,
22977+
57F1C8E325DC6EE700E8F6EA /* PrivateClickMeasurementCocoa.mm */,
2297622978
7E8FADC3199A95B100714968 /* SubresourceLoaderCocoa.mm */,
2297722979
);
2297822980
path = cocoa;

Source/WebCore/loader/PrivateClickMeasurement.cpp

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
namespace WebCore {
3838

3939
static const char privateClickMeasurementTriggerAttributionPath[] = "/.well-known/private-click-measurement/trigger-attribution/";
40-
static const char privateClickMeasurementTokenSignaturePath[] = "/.well-known/private-click-measurement/sign-unlinkable-token/";
40+
static const char privateClickMeasurementTokenSignaturePath[] = "/.well-known/private-click-measurement/sign-secret-token/";
4141
static const char privateClickMeasurementTokenPublicKeyPath[] = "/.well-known/private-click-measurement/get-unlinkable-token-public-key/";
4242
static const char privateClickMeasurementReportAttributionPath[] = "/.well-known/private-click-measurement/report-attribution/";
4343
const size_t privateClickMeasurementAttributionTriggerDataPathSegmentSize = 2;
@@ -116,15 +116,15 @@ bool PrivateClickMeasurement::hasHigherPriorityThan(const PrivateClickMeasuremen
116116
return m_attributionTriggerData->priority > other.m_attributionTriggerData->priority;
117117
}
118118

119-
URL PrivateClickMeasurement::tokenSignatureURL() const
119+
URL PrivateClickMeasurement::attributionReportURL() const
120120
{
121-
if (!m_ephemeralSourceNonce || !m_ephemeralSourceNonce->isValid())
121+
if (!isValid())
122122
return URL();
123123

124124
StringBuilder builder;
125125
builder.appendLiteral("https://");
126126
builder.append(m_sourceSite.registrableDomain.string());
127-
builder.appendLiteral(privateClickMeasurementTokenSignaturePath);
127+
builder.appendLiteral(privateClickMeasurementReportAttributionPath);
128128

129129
URL url { URL(), builder.toString() };
130130
if (url.isValid())
@@ -133,12 +133,51 @@ URL PrivateClickMeasurement::tokenSignatureURL() const
133133
return URL();
134134
}
135135

136-
URL PrivateClickMeasurement::tokenPublicKeyURL() const
136+
Ref<JSON::Object> PrivateClickMeasurement::attributionReportJSON() const
137+
{
138+
auto reportDetails = JSON::Object::create();
139+
if (!m_attributionTriggerData || !isValid())
140+
return reportDetails;
141+
142+
reportDetails->setString("source_engagement_type"_s, "click"_s);
143+
reportDetails->setString("source_site"_s, m_sourceSite.registrableDomain.string());
144+
reportDetails->setInteger("source_id"_s, m_sourceID.id);
145+
reportDetails->setString("attributed_on_site"_s, m_attributeOnSite.registrableDomain.string());
146+
reportDetails->setInteger("trigger_data"_s, m_attributionTriggerData->data);
147+
reportDetails->setInteger("version"_s, 1);
148+
return reportDetails;
149+
}
150+
151+
// MARK: - Fraud Prevention
152+
153+
static constexpr uint32_t EphemeralSourceNonceRequiredNumberOfBytes = 16;
154+
155+
bool PrivateClickMeasurement::EphemeralSourceNonce::isValid() const
137156
{
157+
// FIXME: Investigate if we can do with a simple length check instead of decoding.
158+
// https://bugs.webkit.org/show_bug.cgi?id=221945
159+
Vector<uint8_t> digest;
160+
if (!base64URLDecode(nonce, digest))
161+
return false;
162+
return digest.size() == EphemeralSourceNonceRequiredNumberOfBytes;
163+
}
164+
165+
void PrivateClickMeasurement::setEphemeralSourceNonce(EphemeralSourceNonce&& nonce)
166+
{
167+
if (!nonce.isValid())
168+
return;
169+
m_ephemeralSourceNonce = WTFMove(nonce);
170+
}
171+
172+
URL PrivateClickMeasurement::tokenSignatureURL() const
173+
{
174+
if (!m_ephemeralSourceNonce || !m_ephemeralSourceNonce->isValid())
175+
return URL();
176+
138177
StringBuilder builder;
139178
builder.appendLiteral("https://");
140179
builder.append(m_sourceSite.registrableDomain.string());
141-
builder.appendLiteral(privateClickMeasurementTokenPublicKeyPath);
180+
builder.appendLiteral(privateClickMeasurementTokenSignaturePath);
142181

143182
URL url { URL(), builder.toString() };
144183
if (url.isValid())
@@ -147,28 +186,12 @@ URL PrivateClickMeasurement::tokenPublicKeyURL() const
147186
return URL();
148187
}
149188

150-
Ref<JSON::Object> PrivateClickMeasurement::tokenSignatureJSON() const
151-
{
152-
auto reportDetails = JSON::Object::create();
153-
if (!m_ephemeralSourceNonce || !m_ephemeralSourceNonce->isValid())
154-
return reportDetails;
155-
156-
reportDetails->setString("source_engagement_type"_s, "click"_s);
157-
reportDetails->setString("source_nonce"_s, m_ephemeralSourceNonce->nonce);
158-
reportDetails->setString("unlinkable_token"_s, "TODO"_s);
159-
reportDetails->setInteger("version"_s, 2);
160-
return reportDetails;
161-
}
162-
163-
URL PrivateClickMeasurement::attributionReportURL() const
189+
URL PrivateClickMeasurement::tokenPublicKeyURL() const
164190
{
165-
if (!isValid())
166-
return URL();
167-
168191
StringBuilder builder;
169192
builder.appendLiteral("https://");
170193
builder.append(m_sourceSite.registrableDomain.string());
171-
builder.appendLiteral(privateClickMeasurementReportAttributionPath);
194+
builder.appendLiteral(privateClickMeasurementTokenPublicKeyPath);
172195

173196
URL url { URL(), builder.toString() };
174197
if (url.isValid())
@@ -177,19 +200,24 @@ URL PrivateClickMeasurement::attributionReportURL() const
177200
return URL();
178201
}
179202

180-
Ref<JSON::Object> PrivateClickMeasurement::attributionReportJSON() const
203+
Ref<JSON::Object> PrivateClickMeasurement::tokenSignatureJSON(const String& serverPublicKeyBase64URL)
181204
{
182205
auto reportDetails = JSON::Object::create();
183-
if (!m_attributionTriggerData || !isValid())
206+
if (!m_ephemeralSourceNonce || !m_ephemeralSourceNonce->isValid())
207+
return reportDetails;
208+
209+
String token;
210+
#if PLATFORM(COCOA)
211+
token = sourceSecretToken(serverPublicKeyBase64URL);
212+
#endif
213+
if (token.isEmpty())
184214
return reportDetails;
185215

186216
reportDetails->setString("source_engagement_type"_s, "click"_s);
187-
reportDetails->setString("source_site"_s, m_sourceSite.registrableDomain.string());
188-
reportDetails->setInteger("source_id"_s, m_sourceID.id);
189-
reportDetails->setString("attributed_on_site"_s, m_attributeOnSite.registrableDomain.string());
190-
reportDetails->setInteger("trigger_data"_s, m_attributionTriggerData->data);
191-
reportDetails->setInteger("version"_s, 1);
217+
reportDetails->setString("source_nonce"_s, m_ephemeralSourceNonce->nonce);
218+
reportDetails->setString("source_secret_token"_s, token);
219+
reportDetails->setInteger("version"_s, 2);
192220
return reportDetails;
193221
}
194222

195-
}
223+
} // namespace WebCore

0 commit comments

Comments
 (0)