Xbox Cloud Gaming app for PS5 Homebrew
C
TLS setup: say which step failed, and where the log is
Rafael Abud Ferreira4ee7cfd91a39
diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex ae854bd..af4f20f 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -159,7 +159,8 @@ bool g_autoplayDump = false;int g_autoplayRuns = 1;bool g_autoplayIdle = false;bool g_autoplayConsolesTab = false;-bool g_autoplaySettingsTest = false; // autoplay "settingstest": open the resolution list, save settings.ppm+bool g_autoplaySettingsTest = false;+bool g_autoplayBadCa = false; // autoplay "badca": a missing CA bundle, to see the TLS setup error // autoplay "settingstest": open the resolution list, save settings.ppmbool g_autoplayConsolesEmpty = false; // with "consolestab": as if none were found // autoplay "consolestab": open My consoles, save consoles.ppmbool g_autoplayConsoles = false; // autoplay "consoles": log the account's own consoles (xhome)bool g_autoplayPad = false; // autoplay "pad": the physical pad stays in use, its buttons logged@@ -242,6 +243,7 @@ void loadAutoplay() {if (opt == "consoles") g_autoplayConsoles = true;if (opt == "consolestab") g_autoplayConsolesTab = true;if (opt == "settingstest") g_autoplaySettingsTest = true;+ if (opt == "badca") g_autoplayBadCa = true;if (opt == "consolesempty") g_autoplayConsolesTab = g_autoplayConsolesEmpty = true;if (opt == "librarytest") g_autoplayLibraryTest = true;if (opt == "imetest") g_autoplayImeTest = true;@@ -1014,9 +1016,12 @@ int main(int argc, char** argv) {}ui::Canvas canvas(display::kWidth, display::kHeight);- if (!net::initTls(platform::caBundlePath())) {- platform::notify("xCloud: could not load the TLS certificates");- g_ui->showError("Could not load " + platform::caBundlePath());+ if (!net::initTls(g_autoplayBadCa ? platform::assetDir() + "/missing.pem" : platform::caBundlePath())) {+ // The step that failed, and where the log is: what a bug report needs.+ platform::notify("PSBox: secure connections unavailable");+ g_ui->showError("Secure connections could not be set up: " + net::tlsInitError() + ". Log: " ++ platform::dataDir() + "/xcloud.log");+ if (g_autoplayBadCa) XC_LOGI("AUTOPLAY END: TLS setup error shown");} else {std::thread(worker).detach();}diff --git a/src/net/http.cpp b/src/net/http.cppindex dfb74b8..7224e0c 100644--- a/src/net/http.cpp+++ b/src/net/http.cpp@@ -154,14 +154,27 @@ bool Url::parse(const std::string& url, Url& out) {return !out.host.empty() && (out.scheme == "https" || out.scheme == "http");}+namespace {+std::string g_initError;+}++std::string tlsInitError() {+ std::lock_guard<std::mutex> lock(g.mutex);+ return g_initError;+}+bool initTls(const std::string& caBundlePath) {std::lock_guard<std::mutex> lock(g.mutex);if (g.ready) return true;-#if defined(MBEDTLS_PSA_CRYPTO_C)- if (psa_crypto_init() != PSA_SUCCESS) {- XC_LOGE("psa_crypto_init failed");+ auto fail = [](std::string why) {+ XC_LOGE("TLS setup: %s", why.c_str());+ g_initError = std::move(why);return false;- }+ };+#if defined(MBEDTLS_PSA_CRYPTO_C)+ // Gathers entropy from the system (getrandom / kern.arandom) first.+ if (psa_status_t st = psa_crypto_init(); st != PSA_SUCCESS)+ return fail("crypto init (system random source?): PSA error " + std::to_string(static_cast<int>(st)));#endifmbedtls_entropy_init(&g.entropy);mbedtls_ctr_drbg_init(&g.drbg);@@ -170,15 +183,9 @@ bool initTls(const std::string& caBundlePath) {const char* pers = "xcloud-ps5";int rc = mbedtls_ctr_drbg_seed(&g.drbg, mbedtls_entropy_func, &g.entropy,reinterpret_cast<const unsigned char*>(pers), std::strlen(pers));- if (rc != 0) {- XC_LOGE("ctr_drbg_seed: %s", tlsError(rc).c_str());- return false;- }+ if (rc != 0) return fail("random generator (system random source?): " + tlsError(rc));rc = mbedtls_x509_crt_parse_file(&g.ca, caBundlePath.c_str());- if (rc < 0) {- XC_LOGE("CA bundle %s: %s", caBundlePath.c_str(), tlsError(rc).c_str());- return false;- }+ if (rc < 0) return fail("certificates " + caBundlePath + ": " + tlsError(rc));if (rc > 0) XC_LOGW("CA bundle: %d certificates could not be parsed (ignored)", rc);g.ready = true;return true;diff --git a/src/net/http.h b/src/net/http.hindex 195be8f..49d70d8 100644--- a/src/net/http.h+++ b/src/net/http.h@@ -44,6 +44,8 @@ struct Url {// Loads trusted roots from a PEM bundle. Must be called once before any// request; returns false when the file is missing or holds no certificates.bool initTls(const std::string& caBundlePath);+// Why initTls() failed (the step and Mbed TLS's message); empty otherwise.+std::string tlsInitError();void shutdownTls();Response perform(const Request& req);