From ca07b0046b417baaa67f3c46130a9b81ceab7c66 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Mon, 2 Oct 2017 12:40:29 -0700 Subject: [PATCH] Provide an entropy source to the Dart engine (flutter/engine#4161) This is required by the _CryptoUtils class used by the recently repackaged Dart HTTP libraries --- engine/src/flutter/lib/io/BUILD.gn | 4 ++++ engine/src/flutter/lib/io/dart_io.cc | 5 +++++ engine/src/flutter/lib/io/dart_io.h | 3 +++ engine/src/flutter/runtime/dart_init.cc | 1 + 4 files changed, 13 insertions(+) diff --git a/engine/src/flutter/lib/io/BUILD.gn b/engine/src/flutter/lib/io/BUILD.gn index 9b5bb25de6..914cc90584 100644 --- a/engine/src/flutter/lib/io/BUILD.gn +++ b/engine/src/flutter/lib/io/BUILD.gn @@ -14,4 +14,8 @@ source_set("io") { "//garnet/public/lib/fxl", "//topaz/lib/tonic/converter", ] + + configs += [ + "//dart/runtime:dart_config", + ] } diff --git a/engine/src/flutter/lib/io/dart_io.cc b/engine/src/flutter/lib/io/dart_io.cc index ffd7f1d528..1820f6dacc 100644 --- a/engine/src/flutter/lib/io/dart_io.cc +++ b/engine/src/flutter/lib/io/dart_io.cc @@ -4,6 +4,7 @@ #include "flutter/lib/io/dart_io.h" +#include "dart/runtime/bin/crypto.h" #include "dart/runtime/bin/io_natives.h" #include "dart/runtime/include/dart_api.h" #include "lib/tonic/converter/dart_converter.h" @@ -18,4 +19,8 @@ void DartIO::InitForIsolate() { dart::bin::IONativeSymbol)); } +bool DartIO::EntropySource(uint8_t* buffer, intptr_t length) { + return dart::bin::Crypto::GetRandomBytes(length, buffer); +} + } // namespace blink diff --git a/engine/src/flutter/lib/io/dart_io.h b/engine/src/flutter/lib/io/dart_io.h index c239b0a1ea..b2bf89f85d 100644 --- a/engine/src/flutter/lib/io/dart_io.h +++ b/engine/src/flutter/lib/io/dart_io.h @@ -5,6 +5,8 @@ #ifndef FLUTTER_LIB_IO_DART_IO_H_ #define FLUTTER_LIB_IO_DART_IO_H_ +#include + #include "lib/fxl/macros.h" namespace blink { @@ -12,6 +14,7 @@ namespace blink { class DartIO { public: static void InitForIsolate(); + static bool EntropySource(uint8_t* buffer, intptr_t length); private: FXL_DISALLOW_IMPLICIT_CONSTRUCTORS(DartIO); diff --git a/engine/src/flutter/runtime/dart_init.cc b/engine/src/flutter/runtime/dart_init.cc index 874fad3c98..5cbed3ed28 100644 --- a/engine/src/flutter/runtime/dart_init.cc +++ b/engine/src/flutter/runtime/dart_init.cc @@ -565,6 +565,7 @@ void InitDartVM(const uint8_t* vm_snapshot_data, params.shutdown = IsolateShutdownCallback; params.thread_exit = ThreadExitCallback; params.get_service_assets = GetVMServiceAssetsArchiveCallback; + params.entropy_source = DartIO::EntropySource; char* init_error = Dart_Initialize(¶ms); if (init_error != nullptr) FXL_LOG(FATAL) << "Error while initializing the Dart VM: " << init_error;