diff options
| author | 2018-10-06 02:43:09 -0400 | |
|---|---|---|
| committer | 2018-10-06 02:43:09 -0400 | |
| commit | b8b90ce6e61329ebda226b9917ed961be3b80d1f (patch) | |
| tree | 8e6b82419db7fb24eb5d8f06346a0a1228f9513c /src/core/telemetry_session.cpp | |
| parent | Merge pull request #1447 from lioncash/mutex (diff) | |
| parent | Review comments - part 5 (diff) | |
| download | yuzu-b8b90ce6e61329ebda226b9917ed961be3b80d1f.tar.gz yuzu-b8b90ce6e61329ebda226b9917ed961be3b80d1f.tar.xz yuzu-b8b90ce6e61329ebda226b9917ed961be3b80d1f.zip | |
Merge pull request #1332 from FearlessTobi/port-web-backend
Port web_service from Citra
Diffstat (limited to 'src/core/telemetry_session.cpp')
| -rw-r--r-- | src/core/telemetry_session.cpp | 52 |
1 files changed, 40 insertions, 12 deletions
diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index b0df154ca..f29fff1e7 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp | |||
| @@ -6,6 +6,8 @@ | |||
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "common/file_util.h" | 7 | #include "common/file_util.h" |
| 8 | 8 | ||
| 9 | #include <mbedtls/ctr_drbg.h> | ||
| 10 | #include <mbedtls/entropy.h> | ||
| 9 | #include "core/core.h" | 11 | #include "core/core.h" |
| 10 | #include "core/file_sys/control_metadata.h" | 12 | #include "core/file_sys/control_metadata.h" |
| 11 | #include "core/file_sys/patch_manager.h" | 13 | #include "core/file_sys/patch_manager.h" |
| @@ -13,10 +15,31 @@ | |||
| 13 | #include "core/settings.h" | 15 | #include "core/settings.h" |
| 14 | #include "core/telemetry_session.h" | 16 | #include "core/telemetry_session.h" |
| 15 | 17 | ||
| 18 | #ifdef ENABLE_WEB_SERVICE | ||
| 19 | #include "web_service/telemetry_json.h" | ||
| 20 | #include "web_service/verify_login.h" | ||
| 21 | #endif | ||
| 22 | |||
| 16 | namespace Core { | 23 | namespace Core { |
| 17 | 24 | ||
| 18 | static u64 GenerateTelemetryId() { | 25 | static u64 GenerateTelemetryId() { |
| 19 | u64 telemetry_id{}; | 26 | u64 telemetry_id{}; |
| 27 | |||
| 28 | mbedtls_entropy_context entropy; | ||
| 29 | mbedtls_entropy_init(&entropy); | ||
| 30 | mbedtls_ctr_drbg_context ctr_drbg; | ||
| 31 | std::string personalization = "yuzu Telemetry ID"; | ||
| 32 | |||
| 33 | mbedtls_ctr_drbg_init(&ctr_drbg); | ||
| 34 | ASSERT(mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, | ||
| 35 | reinterpret_cast<const unsigned char*>(personalization.c_str()), | ||
| 36 | personalization.size()) == 0); | ||
| 37 | ASSERT(mbedtls_ctr_drbg_random(&ctr_drbg, reinterpret_cast<unsigned char*>(&telemetry_id), | ||
| 38 | sizeof(u64)) == 0); | ||
| 39 | |||
| 40 | mbedtls_ctr_drbg_free(&ctr_drbg); | ||
| 41 | mbedtls_entropy_free(&entropy); | ||
| 42 | |||
| 20 | return telemetry_id; | 43 | return telemetry_id; |
| 21 | } | 44 | } |
| 22 | 45 | ||
| @@ -25,14 +48,21 @@ u64 GetTelemetryId() { | |||
| 25 | const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + | 48 | const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + |
| 26 | "telemetry_id"}; | 49 | "telemetry_id"}; |
| 27 | 50 | ||
| 28 | if (FileUtil::Exists(filename)) { | 51 | bool generate_new_id = !FileUtil::Exists(filename); |
| 52 | if (!generate_new_id) { | ||
| 29 | FileUtil::IOFile file(filename, "rb"); | 53 | FileUtil::IOFile file(filename, "rb"); |
| 30 | if (!file.IsOpen()) { | 54 | if (!file.IsOpen()) { |
| 31 | LOG_ERROR(Core, "failed to open telemetry_id: {}", filename); | 55 | LOG_ERROR(Core, "failed to open telemetry_id: {}", filename); |
| 32 | return {}; | 56 | return {}; |
| 33 | } | 57 | } |
| 34 | file.ReadBytes(&telemetry_id, sizeof(u64)); | 58 | file.ReadBytes(&telemetry_id, sizeof(u64)); |
| 35 | } else { | 59 | if (telemetry_id == 0) { |
| 60 | LOG_ERROR(Frontend, "telemetry_id is 0. Generating a new one.", telemetry_id); | ||
| 61 | generate_new_id = true; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | if (generate_new_id) { | ||
| 36 | FileUtil::IOFile file(filename, "wb"); | 66 | FileUtil::IOFile file(filename, "wb"); |
| 37 | if (!file.IsOpen()) { | 67 | if (!file.IsOpen()) { |
| 38 | LOG_ERROR(Core, "failed to open telemetry_id: {}", filename); | 68 | LOG_ERROR(Core, "failed to open telemetry_id: {}", filename); |
| @@ -59,23 +89,20 @@ u64 RegenerateTelemetryId() { | |||
| 59 | return new_telemetry_id; | 89 | return new_telemetry_id; |
| 60 | } | 90 | } |
| 61 | 91 | ||
| 62 | std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func) { | 92 | bool VerifyLogin(const std::string& username, const std::string& token) { |
| 63 | #ifdef ENABLE_WEB_SERVICE | 93 | #ifdef ENABLE_WEB_SERVICE |
| 64 | return WebService::VerifyLogin(username, token, Settings::values.verify_endpoint_url, func); | 94 | return WebService::VerifyLogin(Settings::values.web_api_url, username, token); |
| 65 | #else | 95 | #else |
| 66 | return std::async(std::launch::async, [func{std::move(func)}]() { | 96 | return false; |
| 67 | func(); | ||
| 68 | return false; | ||
| 69 | }); | ||
| 70 | #endif | 97 | #endif |
| 71 | } | 98 | } |
| 72 | 99 | ||
| 73 | TelemetrySession::TelemetrySession() { | 100 | TelemetrySession::TelemetrySession() { |
| 74 | #ifdef ENABLE_WEB_SERVICE | 101 | #ifdef ENABLE_WEB_SERVICE |
| 75 | if (Settings::values.enable_telemetry) { | 102 | if (Settings::values.enable_telemetry) { |
| 76 | backend = std::make_unique<WebService::TelemetryJson>( | 103 | backend = std::make_unique<WebService::TelemetryJson>(Settings::values.web_api_url, |
| 77 | Settings::values.telemetry_endpoint_url, Settings::values.yuzu_username, | 104 | Settings::values.yuzu_username, |
| 78 | Settings::values.yuzu_token); | 105 | Settings::values.yuzu_token); |
| 79 | } else { | 106 | } else { |
| 80 | backend = std::make_unique<Telemetry::NullVisitor>(); | 107 | backend = std::make_unique<Telemetry::NullVisitor>(); |
| 81 | } | 108 | } |
| @@ -94,7 +121,8 @@ TelemetrySession::TelemetrySession() { | |||
| 94 | u64 program_id{}; | 121 | u64 program_id{}; |
| 95 | const Loader::ResultStatus res{System::GetInstance().GetAppLoader().ReadProgramId(program_id)}; | 122 | const Loader::ResultStatus res{System::GetInstance().GetAppLoader().ReadProgramId(program_id)}; |
| 96 | if (res == Loader::ResultStatus::Success) { | 123 | if (res == Loader::ResultStatus::Success) { |
| 97 | AddField(Telemetry::FieldType::Session, "ProgramId", program_id); | 124 | const std::string formatted_program_id{fmt::format("{:016X}", program_id)}; |
| 125 | AddField(Telemetry::FieldType::Session, "ProgramId", formatted_program_id); | ||
| 98 | 126 | ||
| 99 | std::string name; | 127 | std::string name; |
| 100 | System::GetInstance().GetAppLoader().ReadTitle(name); | 128 | System::GetInstance().GetAppLoader().ReadTitle(name); |