Play your Steam library's Windows games on a jailbroken PS5.
C++
Log each Steam sign-in step and result
Leonardo Lobato642318ddac97
diff --git a/src/homebrew/controller.cpp b/src/homebrew/controller.cppindex bfe49ba..bd4648a 100644--- a/src/homebrew/controller.cpp+++ b/src/homebrew/controller.cpp@@ -8,12 +8,13 @@ namespace playden::homebrew {Controller::Controller(Simulation& model, steam::AuthBackend& backend, SessionRepository& repository,LibraryService* library_service, app::PersistenceService* persistence_service,steam::AppDetailsService* app_details, steam::InstallService* installs,- steam::CloudService* cloud, RuntimeHost* runtime)+ steam::CloudService* cloud, RuntimeHost* runtime,+ std::function<void(const std::string&)> auth_log): model_(model), app_details_(app_details), installs_(installs), cloud_(cloud), runtime_(runtime),- library_service_(library_service) {+ library_service_(library_service), auth_log_(std::move(auth_log)) {if (model_.state().simulation_mode) return;if(library_service_) library_=std::make_unique<app::LibraryController>(model_,*library_service_);- service_ = std::make_unique<steam::SteamService>(backend,repository);+ service_ = std::make_unique<steam::SteamService>(backend,repository,auth_log_);phase_ = Phase::Restore;Update(AuthState::Restoring,{},true);if(persistence_service) persistence_=std::make_unique<app::PersistenceController>(model_,*persistence_service);@@ -1295,10 +1296,21 @@ void Controller::SubmitPrepare(GameId id, bool announce) {runtime_->Prepare(std::move(request));}void Controller::Apply(const steam::SteamEvent& event) {- if (event.generation < generation_) return;+ const auto ignore = [&](const char* reason) {+ if (auth_log_)+ auth_log_("request=" + std::to_string(event.request_id) + " event=" + steam::EventName(event.kind) ++ " ignored=" + reason + " phase=" + std::to_string(static_cast<int>(phase_)) ++ " current=" + std::to_string(request_));+ };+ if (event.generation < generation_) return ignore("old-generation");if (phase_ == Phase::SignOut) {- if (event.kind != steam::SteamEventKind::kSignedOut && event.kind != steam::SteamEventKind::kFailure) return;- } else if (phase_ == Phase::Idle || phase_==Phase::ClearLibrary || phase_==Phase::ClearOrganization || event.request_id != request_) return;+ if (event.kind != steam::SteamEventKind::kSignedOut && event.kind != steam::SteamEventKind::kFailure)+ return ignore("signing-out");+ } else if (phase_ == Phase::Idle || phase_==Phase::ClearLibrary || phase_==Phase::ClearOrganization) {+ return ignore("phase");+ } else if (event.request_id != request_) {+ return ignore("other-request");+ }generation_ = event.generation;switch (event.kind) {case steam::SteamEventKind::kChallenge:diff --git a/src/homebrew/controller.hpp b/src/homebrew/controller.hppindex 279c44c..bcdd4c7 100644--- a/src/homebrew/controller.hpp+++ b/src/homebrew/controller.hpp@@ -27,7 +27,8 @@ class Controller {Controller(Simulation& model, steam::AuthBackend& backend, SessionRepository& repository,LibraryService* library_service = nullptr, app::PersistenceService* persistence_service = nullptr,steam::AppDetailsService* app_details = nullptr, steam::InstallService* installs = nullptr,- steam::CloudService* cloud = nullptr, RuntimeHost* runtime = nullptr);+ steam::CloudService* cloud = nullptr, RuntimeHost* runtime = nullptr,+ std::function<void(const std::string&)> auth_log = {});~Controller();void Tick();// Microseconds each part of the last Tick took, for slow-frame diagnostics.@@ -200,6 +201,7 @@ class Controller {std::optional<GameId> requested_detail_;std::uint64_t requested_generation_ = 0;std::unique_ptr<steam::SteamService> service_;+ std::function<void(const std::string&)> auth_log_; // sign-in steps and results (auth.log)LibraryService* library_service_ = nullptr;std::unique_ptr<app::LibraryController> library_;std::unique_ptr<app::PersistenceController> persistence_;diff --git a/src/homebrew/host.cpp b/src/homebrew/host.cppindex 2f29a1d..f1fcf04 100644--- a/src/homebrew/host.cpp+++ b/src/homebrew/host.cpp@@ -532,7 +532,10 @@ int main(int argc, char** argv) {cloud = std::make_unique<playden::steam::CloudService>(*cloud_runner, *cloud_sessions);simulation.SetLogDirectory(options->data_directory / "logs");simulation.SetRecipeExportTarget(options->data_directory / "logs", "");- services = std::make_unique<playden::homebrew::Controller>(simulation, *auth, *sessions,library_service.get(),persistence.get(),app_details.get(),installs.get(),cloud.get());+ services = std::make_unique<playden::homebrew::Controller>(simulation, *auth, *sessions,library_service.get(),persistence.get(),app_details.get(),installs.get(),cloud.get(),+ nullptr, [log_directory](const std::string& line) {+ playden::app::AppendLogLine(log_directory, "auth.log", "sign-in " + line);+ });store_details = std::make_unique<playden::steam::StoreDetailsService>(playden::homebrew::StoreFetch(PLAYDEN_HOMEBREW_CA_BUNDLE));services->SetStoreDetails(store_details.get());}diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cppindex 3938a39..8627f7e 100644--- a/src/homebrew/ps5.cpp+++ b/src/homebrew/ps5.cpp@@ -474,7 +474,9 @@ int main() {playden::app::AppendLogLine(paths.log_root, "runtime.log", "runtime worker could not start");}playden::homebrew::Controller services(simulation, auth, sessions,&library_service,&persistence,&app_details,&installs,&cloud,- runtime_host.get());+ runtime_host.get(), [](const std::string& line) {+ playden::app::AppendLogLine(log_root, "auth.log", "sign-in " + line);+ });playden::steam::StoreDetailsService store_details(playden::homebrew::StoreFetch(paths.trust_store));services.SetStoreDetails(&store_details);services.SetSelfUpdate(&self_update);diff --git a/src/steam/service.cpp b/src/steam/service.cppindex 91fcf79..30d3b19 100644--- a/src/steam/service.cpp+++ b/src/steam/service.cpp@@ -14,10 +14,45 @@ SteamEvent Failure(AuthError error) {bool StructurallyValid(const StoredSession& session) {return session.steam_id != 0 && !session.refresh_token.empty();}+const char* ErrorName(AuthError error) {+ switch (error) {+ case AuthError::kNone: return "none";+ case AuthError::kCanceled: return "canceled";+ case AuthError::kExpired: return "expired";+ case AuthError::kRejected: return "rejected";+ case AuthError::kNetwork: return "network";+ case AuthError::kProtocol: return "protocol";+ case AuthError::kCredentialsRevoked: return "credentials-revoked";+ case AuthError::kPersistence: return "persistence";+ case AuthError::kNoSession: return "no-session";+ case AuthError::kInvalidPassword: return "invalid-password";+ case AuthError::kRateLimited: return "rate-limited";+ case AuthError::kSignInRefused: return "sign-in-refused";+ case AuthError::kSignInTimedOut: return "sign-in-timed-out";+ }+ return "unknown";+}+}++const char* EventName(SteamEventKind kind) {+ switch (kind) {+ case SteamEventKind::kChallenge: return "challenge";+ case SteamEventKind::kAwaitingApproval: return "awaiting-approval";+ case SteamEventKind::kNeedsEmailCode: return "needs-email-code";+ case SteamEventKind::kNeedsAuthenticatorCode: return "needs-authenticator-code";+ case SteamEventKind::kCodeRejected: return "code-rejected";+ case SteamEventKind::kAuthenticated: return "authenticated";+ case SteamEventKind::kOfflineSession: return "offline-session";+ case SteamEventKind::kSignedOut: return "signed-out";+ case SteamEventKind::kCanceled: return "canceled";+ case SteamEventKind::kFailure: return "failure";+ }+ return "unknown";}-SteamService::SteamService(AuthBackend& backend, SessionRepository& repository)- : backend_(backend), repository_(repository), worker_([this] { Run(); }) {}+SteamService::SteamService(AuthBackend& backend, SessionRepository& repository,+ std::function<void(const std::string&)> log)+ : backend_(backend), repository_(repository), log_(std::move(log)), worker_([this] { Run(); }) {}SteamService::~SteamService() {{@@ -90,6 +125,7 @@ void SteamService::Cancel(RequestId request) {event.generation = generation_;event.error = AuthError::kCanceled;events_.push_back(std::move(event));+ if (log_) log_("request=" + std::to_string(request) + " event=canceled by=player");}bool SteamService::Current(const Job& job) const {@@ -97,16 +133,36 @@ bool SteamService::Current(const Job& job) const {return !stopping_ && job.generation == generation_ && !job.cancel->load();}+void SteamService::Log(const Job& job, const std::string& line) const {+ if (!log_) return;+ const char* operation = job.operation == Operation::kBegin ? "qr"+ : job.operation == Operation::kRestore ? "restore"+ : job.operation == Operation::kCredentials ? "password"+ : "sign-out";+ log_("request=" + std::to_string(job.request) + " op=" + operation + " " + line);+}+void SteamService::Emit(const Job& job, SteamEvent event) {- std::lock_guard<std::mutex> lock(mutex_);- if (stopping_ || job.generation != generation_ || job.cancel->load()) return;- if (event.kind == SteamEventKind::kAuthenticated || event.kind == SteamEventKind::kOfflineSession ||- event.kind == SteamEventKind::kSignedOut || event.kind == SteamEventKind::kFailure ||- event.kind == SteamEventKind::kCanceled) active_ = false;- event.request_id = job.request;- event.generation = job.generation;- if (events_.size() == kMaxEvents) events_.pop_front();- events_.push_back(std::move(event));+ std::string line = std::string("event=") + EventName(event.kind);+ if (event.error != AuthError::kNone) line += std::string(" error=") + ErrorName(event.error);+ if (event.kind == SteamEventKind::kAwaitingApproval || event.kind == SteamEventKind::kCodeRejected)+ line += event.code_allowed ? " code_allowed=1" : " code_allowed=0";+ bool delivered = false;+ {+ std::lock_guard<std::mutex> lock(mutex_);+ if (!stopping_ && job.generation == generation_ && !job.cancel->load()) {+ if (event.kind == SteamEventKind::kAuthenticated || event.kind == SteamEventKind::kOfflineSession ||+ event.kind == SteamEventKind::kSignedOut || event.kind == SteamEventKind::kFailure ||+ event.kind == SteamEventKind::kCanceled) active_ = false;+ event.request_id = job.request;+ event.generation = job.generation;+ if (events_.size() == kMaxEvents) events_.pop_front();+ events_.push_back(std::move(event));+ delivered = true;+ }+ }+ // Undelivered: a newer command or a cancel replaced this request, so nobody waits for its result.+ Log(job, delivered ? line : line + " dropped=superseded");}std::vector<SteamEvent> SteamService::Pump(std::size_t max_events) {@@ -138,6 +194,7 @@ void SteamService::Run() {}void SteamService::Execute(const Job& job) {+ Log(job, "start");if (job.operation == Operation::kClear) {const auto cleared = repository_.Clear();if (!cleared.ok()) { Emit(job, Failure(AuthError::kPersistence)); return; }@@ -214,7 +271,10 @@ void SteamService::Execute(const Job& job) {Emit(job, std::move(event));});}- if (!Current(job)) return;+ if (!Current(job)) {+ Log(job, std::string("result=") + ErrorName(result.error) + " dropped=superseded");+ return;+ }if (result.error != AuthError::kNone) {if (job.operation == Operation::kRestore && result.error == AuthError::kNetwork) {SteamEvent event;@@ -255,6 +315,8 @@ void SteamService::Execute(const Job& job) {if (stale) {const auto cleared = repository_.Clear();if (!cleared.ok()) { std::lock_guard<std::mutex> lock(mutex_); restore_blocked_ = true; }+ Log(job, std::string("session saved=") + (saved.ok() ? "1" : "0") + " dropped=superseded cleared=" ++ (cleared.ok() ? "1" : "0"));return;}if (!saved.ok()) { Emit(job, Failure(AuthError::kPersistence)); return; }diff --git a/src/steam/service.h b/src/steam/service.hindex c447c2e..e7a8e03 100644--- a/src/steam/service.h+++ b/src/steam/service.h@@ -4,6 +4,7 @@#include <condition_variable>#include <cstdint>#include <deque>+#include <functional>#include <memory>#include <mutex>#include <thread>@@ -37,13 +38,18 @@ struct SteamEvent {bool code_allowed = false;bool code_is_email = false;};+// The event's name in auth.log ("awaiting-approval", "authenticated", ...).+const char* EventName(SteamEventKind kind);// Commands enqueue work and invalidate older results without doing storage or// network I/O on the caller. Backend and repository must outlive this service.// SignedOut is emitted only after Clear succeeds; failure is explicit.class SteamService {public:- SteamService(AuthBackend& backend, SessionRepository& repository);+ // log: optional one-line report of each sign-in step and result (auth.log). It names the step,+ // the event and the error only: never tokens, account names or email addresses.+ SteamService(AuthBackend& backend, SessionRepository& repository,+ std::function<void(const std::string&)> log = {});~SteamService();SteamService(const SteamService&) = delete;SteamService& operator=(const SteamService&) = delete;@@ -72,8 +78,10 @@ class SteamService {void Emit(const Job& job, SteamEvent event);void Run();void Execute(const Job& job);+ void Log(const Job& job, const std::string& line) const;AuthBackend& backend_;SessionRepository& repository_;+ std::function<void(const std::string&)> log_;mutable std::mutex mutex_;std::condition_variable wake_;std::deque<Job> pending_;diff --git a/tests/steam_auth_test.cpp b/tests/steam_auth_test.cppindex 010eeb5..7a9e305 100644--- a/tests/steam_auth_test.cpp+++ b/tests/steam_auth_test.cpp@@ -3,6 +3,9 @@#include <cstdlib>#include <iostream>#include <future>+#include <functional>+#include <string>+#include <vector>using namespace playden;using namespace playden::steam;@@ -105,7 +108,51 @@ SteamEvent WaitEvent(SteamService& service,SteamEventKind kind) {std::cerr<<"event deadline exceeded waiting="<<static_cast<int>(kind)<<" last="<<last_kind<<'\n';std::exit(1);}+// The service's log lines, collected from its worker.+class Lines {+ public:+ std::function<void(const std::string&)> Sink() { return [this](const std::string& line){ std::lock_guard<std::mutex> lock(m); lines.push_back(line); }; }+ bool Has(const std::string& part) const {+ std::lock_guard<std::mutex> lock(m);+ for(const auto& line:lines) if(line.find(part)!=std::string::npos) return true;+ return false;+ }+ bool WaitFor(const std::string& part) const {+ auto deadline=std::chrono::steady_clock::now()+3s;+ while(std::chrono::steady_clock::now()<deadline){ if(Has(part)) return true; std::this_thread::sleep_for(1ms); }+ return false;+ }+ private:+ mutable std::mutex m; std::vector<std::string> lines;+};int main(){+ {+ // Each step of a password sign-in is logged, without the account, password or tokens.+ Store store;Backend backend;backend.approval=true;Lines log;SteamService service(backend,store,log.Sink());+ auto id=service.BeginCredentialSignIn("fixture-account","fixture-password");+ WaitEvent(service,SteamEventKind::kAwaitingApproval);+ service.SubmitGuardCode("WRONG");WaitEvent(service,SteamEventKind::kCodeRejected);+ service.SubmitGuardCode("12345");WaitEvent(service,SteamEventKind::kAuthenticated);+ const auto prefix="request="+std::to_string(id)+" op=password ";+ Check(log.Has(prefix+"start")&&log.Has(prefix+"event=awaiting-approval code_allowed=1")&&+ log.Has(prefix+"event=code-rejected")&&log.Has(prefix+"event=authenticated"),"password sign-in steps logged");+ Check(!log.Has("fixture-account")&&!log.Has("fixture-password")&&!log.Has("fixture-refresh-secret")&&+ !log.Has("fixture-access-secret")&&!log.Has("example.invalid"),"log leaked account data");+ }+ {+ // A result that arrives after a newer command replaced its request says it was dropped.+ Store store;Backend backend;Gate gate;backend.begin_gate=&gate;Lines log;SteamService service(backend,store,log.Sink());+ auto first=service.BeginQrSignIn();gate.Wait();service.Cancel(first);gate.Release();+ WaitEvent(service,SteamEventKind::kCanceled);+ Check(log.WaitFor("request="+std::to_string(first)+" op=qr result=none dropped=superseded"),"dropped result logged");+ Check(log.Has("request="+std::to_string(first)+" event=canceled by=player"),"cancel logged");+ }+ {+ // A restore with no saved session logs why the player sees sign-in.+ Store store;Backend backend;Lines log;SteamService service(backend,store,log.Sink());+ service.RestoreSession();WaitEvent(service,SteamEventKind::kFailure);+ Check(log.WaitFor("op=restore event=failure error=no-session"),"restore failure logged");+ }{Store store;Backend backend;SteamService service(backend,store);auto id=service.BeginQrSignIn();auto e=WaitEvent(service,SteamEventKind::kAuthenticated);