summaryrefslogtreecommitdiffstats
path: root/src/core/telemetry_session.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/telemetry_session.cpp')
-rw-r--r--src/core/telemetry_session.cpp52
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 @@
#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);