Skip to content

Commit

Permalink
Change canvas maximum farbling to match balanced farbling
Browse files Browse the repository at this point in the history
lint

rename internal function
  • Loading branch information
pilgrim-brave committed Aug 4, 2020
1 parent 52b5109 commit b0c3cbb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 40 deletions.
42 changes: 8 additions & 34 deletions chromium_src/third_party/blink/renderer/core/dom/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ namespace {
// are disconnect, remote or local to the top level frame.
std::string TopETLDPlusOneForDoc(const Document& doc) {
const auto host = doc.TopFrameOrigin()->Host();
return blink::network_utils::GetDomainAndRegistry(host,
blink::network_utils::kIncludePrivateRegistries).Utf8();
return blink::network_utils::GetDomainAndRegistry(
host, blink::network_utils::kIncludePrivateRegistries)
.Utf8();
}

const uint64_t zero = 0;
Expand Down Expand Up @@ -117,7 +118,7 @@ AudioFarblingCallback BraveSessionCache::GetAudioFarblingCallback(
}
case BraveFarblingLevel::MAXIMUM: {
uint64_t seed = *reinterpret_cast<uint64_t*>(domain_key_);
return base::BindRepeating(&PseudoRandomSequence, seed);
return base::BindRepeating(&PseudoRandomSequence, seed);
}
}
}
Expand All @@ -133,12 +134,9 @@ scoped_refptr<blink::StaticBitmapImage> BraveSessionCache::PerturbPixels(
switch (frame->GetContentSettingsClient()->GetBraveFarblingLevel()) {
case BraveFarblingLevel::OFF:
break;
case BraveFarblingLevel::BALANCED: {
image_bitmap = PerturbBalanced(image_bitmap);
break;
}
case BraveFarblingLevel::BALANCED:
case BraveFarblingLevel::MAXIMUM: {
image_bitmap = PerturbMax(image_bitmap);
image_bitmap = PerturbPixelsInternal(image_bitmap);
break;
}
default:
Expand All @@ -147,7 +145,8 @@ scoped_refptr<blink::StaticBitmapImage> BraveSessionCache::PerturbPixels(
return image_bitmap;
}

scoped_refptr<blink::StaticBitmapImage> BraveSessionCache::PerturbBalanced(
scoped_refptr<blink::StaticBitmapImage>
BraveSessionCache::PerturbPixelsInternal(
scoped_refptr<blink::StaticBitmapImage> image_bitmap) {
DCHECK(image_bitmap);
if (image_bitmap->IsNull())
Expand Down Expand Up @@ -197,31 +196,6 @@ scoped_refptr<blink::StaticBitmapImage> BraveSessionCache::PerturbBalanced(
return perturbed_bitmap;
}

scoped_refptr<blink::StaticBitmapImage> BraveSessionCache::PerturbMax(
scoped_refptr<blink::StaticBitmapImage> image_bitmap) {
DCHECK(image_bitmap);
if (image_bitmap->IsNull())
return image_bitmap;
// convert to an ImageDataBuffer to normalize the pixel data to RGBA, 4 bytes
// per pixel
std::unique_ptr<blink::ImageDataBuffer> data_buffer =
blink::ImageDataBuffer::Create(image_bitmap);
uint8_t* pixels = const_cast<uint8_t*>(data_buffer->Pixels());
const uint64_t count = 4 * data_buffer->Width() * data_buffer->Height();
// initial seed based on domain key
uint64_t v = *reinterpret_cast<uint64_t*>(domain_key_);
// iterate through pixel data and overwrite with next value in PRNG sequence
for (uint64_t i = 0; i < count; i++) {
pixels[i] = v % 256;
v = lfsr_next(v);
}
// convert back to a StaticBitmapImage to return to the caller
scoped_refptr<blink::StaticBitmapImage> perturbed_bitmap =
blink::UnacceleratedStaticBitmapImage::Create(
data_buffer->RetainedImage());
return perturbed_bitmap;
}

WTF::String BraveSessionCache::GenerateRandomString(std::string seed,
wtf_size_t length) {
uint8_t key[32];
Expand Down
7 changes: 2 additions & 5 deletions chromium_src/third_party/blink/renderer/core/dom/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class CORE_EXPORT BraveSessionCache final

static BraveSessionCache& From(Document&);

AudioFarblingCallback GetAudioFarblingCallback(
blink::LocalFrame* frame);
AudioFarblingCallback GetAudioFarblingCallback(blink::LocalFrame* frame);
scoped_refptr<blink::StaticBitmapImage> PerturbPixels(
blink::LocalFrame* frame,
scoped_refptr<blink::StaticBitmapImage> image_bitmap);
Expand All @@ -55,9 +54,7 @@ class CORE_EXPORT BraveSessionCache final
uint64_t session_key_;
uint8_t domain_key_[32];

scoped_refptr<blink::StaticBitmapImage> PerturbBalanced(
scoped_refptr<blink::StaticBitmapImage> image_bitmap);
scoped_refptr<blink::StaticBitmapImage> PerturbMax(
scoped_refptr<blink::StaticBitmapImage> PerturbPixelsInternal(
scoped_refptr<blink::StaticBitmapImage> image_bitmap);
};
} // namespace brave
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ const char kGetImageDataScript[] =

const int kExpectedImageDataHashFarblingBalanced = 85;
const int kExpectedImageDataHashFarblingOff = 0;
const int kExpectedImageDataHashFarblingMaximum = 127574;
const int kExpectedImageDataHashFarblingMaximum =
kExpectedImageDataHashFarblingBalanced;

const char kEmptyCookie[] = "";

Expand Down

0 comments on commit b0c3cbb

Please sign in to comment.