Xbox Cloud Gaming app for PS5 Homebrew
C
Say why a certificate was refused: the console's clock, or interception (#45)
Rafael Abud Ferreiraf8930a256a27
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 41ef940..2ff29bd 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -100,6 +100,7 @@ void loadAutoplay() {if (opt == "friendstest") g_autoplay.friendsTest = true;if (opt == "streammenutest") g_autoplay.streamMenuTest = true;if (opt == "regiontest") g_autoplay.regionTest = true;+ if (opt == "tlscheck") g_autoplay.tlsCheck = true;if (opt == "norestart") g_autoplay.noRestart = true;if (opt.rfind("threads=", 0) == 0) g_autoplay.decodeThreads = std::atoi(opt.c_str() + 8);}diff --git a/src/app/autoplay.h b/src/app/autoplay.hindex 2bd2b6e..72265d2 100644--- a/src/app/autoplay.h+++ b/src/app/autoplay.h@@ -77,6 +77,7 @@ struct Autoplay {bool publisherTest = false; // publishertest: test publisher filter dropdown and search resultsbool friendsTest = false; // friendstest: test friends playing row and card badgebool streamMenuTest = false; // streammenutest: render StreamMenu with mic and audio route options+ bool tlsCheck = false; // tlscheck: refused certificates (badssl.com) classified and logged, nothing elsebool regionTest = false; // regiontest: the refused sign-in (region.ppm), its country list (region_picker.ppm,// closed unchanged), Settings on the sign-in country (region_settings.ppm), back// (region_back.ppm). The sign-in country is never changed.diff --git a/src/app/cli_main.cpp b/src/app/cli_main.cppindex 09afde7..776eeed 100644--- a/src/app/cli_main.cpp+++ b/src/app/cli_main.cpp@@ -606,6 +606,36 @@ int main(int argc, char** argv) {}int seconds = pos.size() > 1 ? std::atoi(pos[1]) : 30;rc = cmdStream(am, pos[0], seconds > 0 ? seconds : 30, pos.size() > 2 ? pos[2] : nullptr, res, opts, region);+ } else if (cmd == "tls-check" && argi < argc) {+ // One GET: how a refused certificate is reported (the console's+ // clock, an untrusted or misnamed certificate).+ net::Request req;+ req.url = argv[argi];+ auto r = net::perform(req);+ static const char* kProblems[] = {"none", "clock", "untrusted", "name mismatch", "other"};+ std::printf("status %d, problem: %s, date %s\nerror: %s\n", r.status,+ kProblems[static_cast<int>(net::lastTlsProblem())], net::todayText().c_str(), r.error.c_str());+ return 0;+ } else if (cmd == "ui-tls" && argi < argc) {+ // Offline: the sign-in errors for a refused certificate (the+ // console's clock, something answering for Microsoft's sites).+ ui::Fonts fonts;+ if (!fonts.load("assets/fonts")) return 1;+ ui::ImageCache images([] {});+ ui::AppUi app(fonts, images);+ ui::Canvas canvas(1920, 1080);+ if (argi + 1 < argc) ui::setLanguage(ui::languageFromCode(argv[argi + 1]));+ auto save = [&](const std::string& name) {+ app.render(canvas, 1000);+ std::string path = std::string(argv[argi]) + "/" + name + ".png";+ stbi_write_png(path.c_str(), canvas.width(), canvas.height(), 4, canvas.data(), canvas.width() * 4);+ std::printf("wrote %s\n", path.c_str());+ };+ app.showError(ui::trf(ui::Str::ClockWrong, "2021-03-01"));+ save("tls_clock");+ app.showError(ui::tr(ui::Str::ConnectionIntercepted));+ save("tls_intercepted");+ return 0;} else if (cmd == "ui-report" && argi < argc) {// Offline: #38's error screen (Triangle: report), its report's QR// code (a real link, from a made-up log), and Settings' hints.diff --git a/src/app/worker.cpp b/src/app/worker.cppindex d0eeaa7..d541ad7 100644--- a/src/app/worker.cpp+++ b/src/app/worker.cpp@@ -12,6 +12,7 @@#include "app/updater.h"#include "auth/auth_manager.h"#include "media/audio_out.h"+#include "net/http.h"#include "platform/platform.h"#include "ui/strings.h"#include "util/log.h"@@ -476,6 +477,13 @@ void signInAndLoad(auth::AuthManager& am, xcloud::GssvClient& gssv) {// subscription).g_ui->showRegionRefused(country.empty() ? ui::tr(ui::Str::RegionRefused): ui::trf(ui::Str::RegionRefusedAs, ui::loginCountryName(country)));+ } else if (net::lastTlsProblem() == net::TlsProblem::Clock) {+ // The console's clock: a certificate isn't valid at its date (the+ // log line above has the details).+ g_ui->showError(ui::trf(ui::Str::ClockWrong, net::todayText()));+ } else if (net::lastTlsProblem() == net::TlsProblem::Untrusted ||+ net::lastTlsProblem() == net::TlsProblem::NameMismatch) {+ g_ui->showError(ui::tr(ui::Str::ConnectionIntercepted));} else {g_ui->showError(ui::trf(ui::Str::SignInFailed, err));}@@ -604,6 +612,20 @@ void worker() {t.join();for (;;) platform::sleepMs(1000);}+ if (g_autoplay.tlsCheck) {+ // How refused certificates are told apart, on the console's own TLS.+ static const char* kNames[] = {"none", "clock", "untrusted", "name mismatch", "other"};+ for (const char* url : {"https://login.live.com/", "https://expired.badssl.com/", "https://self-signed.badssl.com/",+ "https://wrong.host.badssl.com/"}) {+ net::Request req;+ req.url = url;+ auto r = net::perform(req);+ XC_LOGI("tlscheck %s: status %d, problem %s; %s", url, r.status,+ kNames[static_cast<int>(net::lastTlsProblem())], r.error.c_str());+ }+ XC_LOGI("AUTOPLAY END: tls check (date %s)", net::todayText().c_str());+ return;+ }auth::AuthManager am(platform::dataDir() + "/account.json");xcloud::GssvClient gssv, home("xhome");for (;;) {diff --git a/src/net/http.cpp b/src/net/http.cppindex af8c6ce..a6a8965 100644--- a/src/net/http.cpp+++ b/src/net/http.cpp@@ -23,6 +23,8 @@#include <unistd.h>#include <algorithm>+#include <atomic>+#include <ctime>#include <cctype>#include <cerrno>#include <cstdlib>@@ -200,6 +202,19 @@ std::string g_initError;bool g_builtinCa = false;}+std::atomic<int> g_tlsProblem{0}; // TlsProblem++TlsProblem lastTlsProblem() { return static_cast<TlsProblem>(g_tlsProblem.load()); }++std::string todayText() {+ std::time_t now = std::time(nullptr);+ std::tm utc{};+ gmtime_r(&now, &utc);+ char text[16];+ std::strftime(text, sizeof text, "%Y-%m-%d", &utc);+ return text;+}+bool usingBuiltinCa() {std::lock_guard<std::mutex> lock(g.mutex);return g_builtinCa;@@ -318,9 +333,28 @@ Response performOnce(const Request& req) {mbedtls_ssl_set_bio(&ssl, &fd, bioSend, bioRecv, nullptr);while ((rc = mbedtls_ssl_handshake(&ssl)) != 0) {- if (rc != MBEDTLS_ERR_SSL_WANT_READ && rc != MBEDTLS_ERR_SSL_WANT_WRITE)+ if (rc == MBEDTLS_ERR_SSL_WANT_READ || rc == MBEDTLS_ERR_SSL_WANT_WRITE) continue;+ if (rc != MBEDTLS_ERR_X509_CERT_VERIFY_FAILED)return finish("TLS handshake with " + url.host + ": " + tlsError(rc));+ // The certificate was refused: why (a wrong clock is the usual cause+ // on a console; "Certificate verification failed" alone says nothing).+ uint32_t flags = mbedtls_ssl_get_verify_result(&ssl);+ TlsProblem problem = flags & (MBEDTLS_X509_BADCERT_EXPIRED | MBEDTLS_X509_BADCERT_FUTURE)+ ? TlsProblem::Clock+ : flags & MBEDTLS_X509_BADCERT_CN_MISMATCH ? TlsProblem::NameMismatch+ : flags & MBEDTLS_X509_BADCERT_NOT_TRUSTED ? TlsProblem::Untrusted+ : TlsProblem::Other;+ g_tlsProblem = static_cast<int>(problem);+ char info[512];+ int n = mbedtls_x509_crt_verify_info(info, sizeof info, "", flags);+ std::string why = n > 0 ? std::string(info, static_cast<size_t>(n)) : "flags " + std::to_string(flags);+ for (auto& c : why)+ if (c == '\n') c = ';';+ while (!why.empty() && (why.back() == ';' || why.back() == ' ')) why.pop_back();+ return finish("TLS handshake with " + url.host + ": certificate refused (" + why + "; console date " ++ todayText() + ") " + tlsError(rc));}+ g_tlsProblem = static_cast<int>(TlsProblem::None);tHandshake = platform::nowMs();// Request.diff --git a/src/net/http.h b/src/net/http.hindex 33bc262..22798bc 100644--- a/src/net/http.h+++ b/src/net/http.h@@ -60,6 +60,16 @@ struct Url {bool initTls(const std::string& caBundlePath);// True when initTls() fell back to the built-in copy.bool usingBuiltinCa();++// Why the last secure connection refused the server's certificate, until a+// handshake succeeds again: the console's clock (the certificate isn't valid+// at its date: expired or not yet), a certificate no trusted authority signed,+// one for another name (both: something on the network answering for the+// site), or another reason.+enum class TlsProblem { None, Clock, Untrusted, NameMismatch, Other };+TlsProblem lastTlsProblem();+// The console's date, "2026-10-14" (for the messages about its clock).+std::string todayText();// Trusts the certificates in this PEM file too (the update test's local// server); false when it holds none.bool addTrustedCa(const std::string& pemPath);diff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 8336298..ab7f5b0 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -256,6 +256,8 @@ constexpr Column kEnglish = {"South Korea", // CountryKR"Poland", // CountryPL"United States", // CountryUS+ "Secure connections were refused because the PS5's date and time look wrong (it says %s). Set them in Settings > System > Date and Time, then try again.", // ClockWrong+ "A secure connection was refused: something on the network (a DNS server, proxy or filter) is answering for Microsoft's sites. Try without it, then try again.", // ConnectionIntercepted};constexpr Column kPortugueseBR = {@@ -482,6 +484,8 @@ constexpr Column kPortugueseBR = {"Coreia do Sul","Polônia","Estados Unidos",+ "As conexões seguras foram recusadas porque a data e a hora do PS5 parecem erradas (ele diz %s). Acerte em Configurações > Sistema > Data e hora e tente de novo.",+ "Uma conexão segura foi recusada: algo na rede (um servidor DNS, proxy ou filtro) está respondendo no lugar dos sites da Microsoft. Tente sem ele e tente de novo.",};constexpr Column kSpanish = {@@ -708,6 +712,8 @@ constexpr Column kSpanish = {"Corea del Sur","Polonia","Estados Unidos",+ "Se rechazaron las conexiones seguras porque la fecha y la hora de la PS5 parecen incorrectas (indica %s). Ajústalas en Ajustes > Sistema > Fecha y hora y vuelve a intentarlo.",+ "Se rechazó una conexión segura: algo en la red (un servidor DNS, proxy o filtro) responde en lugar de los sitios de Microsoft. Prueba sin él y vuelve a intentarlo.",};constexpr Column kFrench = {@@ -934,6 +940,8 @@ constexpr Column kFrench = {"Corée du Sud","Pologne","États-Unis",+ "Les connexions sécurisées ont été refusées car la date et l'heure de la PS5 semblent fausses (elle indique %s). Réglez-les dans Paramètres > Système > Date et heure, puis réessayez.",+ "Une connexion sécurisée a été refusée : quelque chose sur le réseau (serveur DNS, proxy ou filtre) répond à la place des sites de Microsoft. Essayez sans, puis réessayez.",};constexpr Column kGerman = {@@ -1160,6 +1168,8 @@ constexpr Column kGerman = {"Südkorea","Polen","USA",+ "Sichere Verbindungen wurden abgelehnt, weil Datum und Uhrzeit der PS5 falsch zu sein scheinen (sie zeigt %s). Stelle sie unter Einstellungen > System > Datum und Uhrzeit ein und versuche es erneut.",+ "Eine sichere Verbindung wurde abgelehnt: Etwas im Netzwerk (DNS-Server, Proxy oder Filter) antwortet anstelle der Microsoft-Seiten. Versuche es ohne und dann erneut.",};constexpr Column kItalian = {@@ -1386,6 +1396,8 @@ constexpr Column kItalian = {"Corea del Sud","Polonia","Stati Uniti",+ "Le connessioni sicure sono state rifiutate perché la data e l'ora della PS5 sembrano errate (indica %s). Impostale in Impostazioni > Sistema > Data e ora, poi riprova.",+ "Una connessione sicura è stata rifiutata: qualcosa nella rete (un server DNS, proxy o filtro) risponde al posto dei siti Microsoft. Prova senza e riprova.",};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex dace723..70362c0 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -233,6 +233,8 @@ enum class Str {CountryKR,CountryPL,CountryUS,+ ClockWrong, // a certificate refused for the console's date: "%s" = that date+ ConnectionIntercepted, // a certificate refused as untrusted or for another nameCount};