summaryrefslogtreecommitdiffstats
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)
target_link_libraries(core PUBLIC common PRIVATE audio_core video_core)
target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt lz4_static mbedtls opus unicorn open_source_archives)
+if (ENABLE_WEB_SERVICE)
+ add_definitions(-DENABLE_WEB_SERVICE)
+ target_link_libraries(core PUBLIC json-headers web_service)
+endif()
if (ARCHITECTURE_x86_64)
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 {
// Debugging
bool use_gdbstub;
u16 gdbstub_port;
+
+ // WebService
+ bool enable_telemetry;
+ std::string web_api_url;
+ std::string yuzu_username;
+ std::string yuzu_token;
} extern values;
void 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 @@
#include "common/common_types.h"
#include "common/file_util.h"
+#include <mbedtls/ctr_drbg.h>
+#include <mbedtls/entropy.h>
#include "core/core.h"
#include "core/file_sys/control_metadata.h"
#include "core/file_sys/patch_manager.h"
@@ -13,10 +15,31 @@
#include "core/settings.h"
#include "core/telemetry_session.h"
+#ifdef ENABLE_WEB_SERVICE
+#include "web_service/telemetry_json.h"
+#include "web_service/verify_login.h"
+#endif
+
namespace Core {
static u64 GenerateTelemetryId() {
u64 telemetry_id{};
+
+ mbedtls_entropy_context entropy;
+ mbedtls_entropy_init(&entropy);
+ mbedtls_ctr_drbg_context ctr_drbg;
+ std::string personalization = "yuzu Telemetry ID";
+
+ mbedtls_ctr_drbg_init(&ctr_drbg);
+ ASSERT(mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
+ reinterpret_cast<const unsigned char*>(personalization.c_str()),
+ personalization.size()) == 0);
+ ASSERT(mbedtls_ctr_drbg_random(&ctr_drbg, reinterpret_cast<unsigned char*>(&telemetry_id),
+ sizeof(u64)) == 0);
+
+ mbedtls_ctr_drbg_free(&ctr_drbg);
+ mbedtls_entropy_free(&entropy);
+
return telemetry_id;
}
@@ -25,14 +48,21 @@ u64 GetTelemetryId() {
const std::string filename{FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) +
"telemetry_id"};
- if (FileUtil::Exists(filename)) {
+ bool generate_new_id = !FileUtil::Exists(filename);
+ if (!generate_new_id) {
FileUtil::IOFile file(filename, "rb");
if (!file.IsOpen()) {
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
return {};
}
file.ReadBytes(&telemetry_id, sizeof(u64));
- } else {
+ if (telemetry_id == 0) {
+ LOG_ERROR(Frontend, "telemetry_id is 0. Generating a new one.", telemetry_id);
+ generate_new_id = true;
+ }
+ }
+
+ if (generate_new_id) {
FileUtil::IOFile file(filename, "wb");
if (!file.IsOpen()) {
LOG_ERROR(Core, "failed to open telemetry_id: {}", filename);
@@ -59,23 +89,20 @@ u64 RegenerateTelemetryId() {
return new_telemetry_id;
}
-std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func) {
+bool VerifyLogin(const std::string& username, const std::string& token) {
#ifdef ENABLE_WEB_SERVICE
- return WebService::VerifyLogin(username, token, Settings::values.verify_endpoint_url, func);
+ return WebService::VerifyLogin(Settings::values.web_api_url, username, token);
#else
- return std::async(std::launch::async, [func{std::move(func)}]() {
- func();
- return false;
- });
+ return false;
#endif
}
TelemetrySession::TelemetrySession() {
#ifdef ENABLE_WEB_SERVICE
if (Settings::values.enable_telemetry) {
- backend = std::make_unique<WebService::TelemetryJson>(
- Settings::values.telemetry_endpoint_url, Settings::values.yuzu_username,
- Settings::values.yuzu_token);
+ backend = std::make_unique<WebService::TelemetryJson>(Settings::values.web_api_url,
+ Settings::values.yuzu_username,
+ Settings::values.yuzu_token);
} else {
backend = std::make_unique<Telemetry::NullVisitor>();
}
@@ -94,7 +121,8 @@ TelemetrySession::TelemetrySession() {
u64 program_id{};
const Loader::ResultStatus res{System::GetInstance().GetAppLoader().ReadProgramId(program_id)};
if (res == Loader::ResultStatus::Success) {
- AddField(Telemetry::FieldType::Session, "ProgramId", program_id);
+ const std::string formatted_program_id{fmt::format("{:016X}", program_id)};
+ AddField(Telemetry::FieldType::Session, "ProgramId", formatted_program_id);
std::string name;
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 @@
#pragma once
-#include <future>
#include <memory>
#include "common/telemetry.h"
@@ -31,6 +30,8 @@ public:
field_collection.AddField(type, name, std::move(value));
}
+ static void FinalizeAsyncJob();
+
private:
Telemetry::FieldCollection field_collection; ///< Tracks all added fields for the session
std::unique_ptr<Telemetry::VisitorInterface> backend; ///< Backend interface that logs fields
@@ -55,6 +56,6 @@ u64 RegenerateTelemetryId();
* @param func A function that gets exectued when the verification is finished
* @returns Future with bool indicating whether the verification succeeded
*/
-std::future<bool> VerifyLogin(std::string username, std::string token, std::function<void()> func);
+bool VerifyLogin(const std::string& username, const std::string& token);
} // namespace Core