summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt4
-rw-r--r--src/core/settings.h6
-rw-r--r--src/core/telemetry_session.cpp52
-rw-r--r--src/core/telemetry_session.h5
4 files changed, 53 insertions, 14 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index a98dbb9ab..e4a676e91 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -396,6 +396,10 @@ create_target_directory_groups(core)
396 396
397target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) 397target_link_libraries(core PUBLIC common PRIVATE audio_core video_core)
398target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static mbedtls opus unicorn open_source_archives) 398target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static mbedtls opus unicorn open_source_archives)
399if (ENABLE_WEB_SERVICE)
400 add_definitions(-DENABLE_WEB_SERVICE)
401 target_link_libraries(core PUBLIC json-headers web_service)
402endif()
399 403
400if (ARCHITECTURE_x86_64) 404if (ARCHITECTURE_x86_64)
401 target_sources(core PRIVATE 405 target_sources(core PRIVATE
diff --git a/src/core/settings.h b/src/core/settings.h
index 0318d019c..1808f5937 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -155,6 +155,12 @@ struct Values {
155 // Debugging 155 // Debugging
156 bool use_gdbstub; 156 bool use_gdbstub;
157 u16 gdbstub_port; 157 u16 gdbstub_port;
158
159 // WebService
160 bool enable_telemetry;
161 std::string web_api_url;
162 std::string yuzu_username;
163 std::string yuzu_token;
158} extern values; 164} extern values;
159 165
160void Apply(); 166void Apply();
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
16namespace Core { 23namespace Core {
17 24
18static u64 GenerateTelemetryId() { 25static 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
62std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func) { 92bool 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
73TelemetrySession::TelemetrySession() { 100TelemetrySession::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);
diff --git a/src/core/telemetry_session.h b/src/core/telemetry_session.h
index dbc4f8bd4..cec271df0 100644
--- a/src/core/telemetry_session.h
+++ b/src/core/telemetry_session.h
@@ -4,7 +4,6 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <future>
8#include <memory> 7#include <memory>
9#include "common/telemetry.h" 8#include "common/telemetry.h"
10 9
@@ -31,6 +30,8 @@ public:
31 field_collection.AddField(type, name, std::move(value)); 30 field_collection.AddField(type, name, std::move(value));
32 } 31 }
33 32
33 static void FinalizeAsyncJob();
34
34private: 35private:
35 Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session 36 Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session
36 std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields 37 std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
@@ -55,6 +56,6 @@ u64 RegenerateTelemetryId();
55 * @param func A function that gets exectued when the verification is finished 56 * @param func A function that gets exectued when the verification is finished
56 * @returns Future with bool indicating whether the verification succeeded 57 * @returns Future with bool indicating whether the verification succeeded
57 */ 58 */
58std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func); 59bool VerifyLogin(const std::string& username, const std::string& token);
59 60
60} // namespace Core 61} // namespace Core