Files
DroidDeck/tools/xbox/droiddeck-credential-fallback.patch
T
The412Banner 81e238b92e feat(xbox): Nexus backend 0.2.15, Nexus runtime 11.0-20261102 and DLC mounting (#2696)
Nexus moved its Xodus changes from patch files in xodus-nexus into a backend
fork (domsvoboda/nexus-backend, GPL-3.0). prepare.py now fetches that fork at
backend-v0.2.15 (e7884a27, same Xodus base 53ea781d, same Rust 1.99.0) and
applies the DroidDeck patches, rebased onto it:
- droiddeck-credentials, -launch-view, -library-subscriptions: same rebase as
  Bannerlator's 0.2.15 update (identical patches before and after).
- droiddeck-credential-fallback, -credential-diagnostics: applied unchanged.
- droiddeck-cloud-token: session::prepare now also returns the account
  snapshot; the ticket checks it like upstream's profile/social commands.
- droiddeck-licensing-device-ticket: upstream 0.2.15 already formats
  delegation-compact device tickets for Store license tokens (27c335e), so only
  the content licensing path is patched. Upstream now writes compact JWE
  delegation tickets as t=, so the d= prefix check is replaced by the token
  type, the same rule as upstream's store_license.rs.
droiddeck-xbox-ticket.patch is dropped: upstream sends compact JWE delegation
tickets to Xbox Live sign-in in a form it accepts, with tests.

Runtime: domsvoboda/nexus-runtime runtime-11.0-20261102-g76c6dd13 (was
xodus-nexus runtime-11.0-20261018). Same six modules at the same path;
xgameruntime.dll is the C++ implementation (nexus-xgameruntime 455b1ba9).
Archive sha512 from the release's .sha512sum, source sha256 from its
candidate.json, module sha256 from the extracted files. The PlayFab Game Saves
proxy is a newer build at the same path and still passes droiddeck-xbox's
export checks; its license moved to share/doc/nexus-runtime/.

DLC mounting: the C++ runtime mounts downloadable content only inside a
host-managed workspace named by XODUS_MOUNT_ROOT (src/System/Package/Mount.h
returns E_NOTIMPL without it). DroidDeck starts Wine itself
(droiddeck:prepare), so droiddeck-dlc-mount.patch (ported from Bannerlator)
creates the workspace in the launch directory for the prepare session and
reports it as mountRoot; XboxRuntime passes it in the xbox-prepare reply and
droiddeck-xbox sets XODUS_MOUNT_ROOT to its Z: path. XODUS_CONTENT_ROOTS is
unchanged and still read by the runtime.

Upstream fixes since the old pins include sign-in for some accounts, offline
play, cloud-save conflict handling, DLC mounting, duplicate token requests and
per-game fixes (Ori, AoE, MSFS, Forza Motorsport).
2026-11-15 20:55:42 -05:00

113 lines
5.1 KiB
Diff

diff --git a/crates/xodus/src/tokens/backend/keychain.rs b/crates/xodus/src/tokens/backend/keychain.rs
index e6717e1..98aa6db 100644
--- a/crates/xodus/src/tokens/backend/keychain.rs
+++ b/crates/xodus/src/tokens/backend/keychain.rs
@@ -1,20 +1,45 @@
use crate::tokens::store::{TokenBackend, TokenStoreError};
use serde_json::{Value, json};
use std::io::{BufRead, Read, Write};
+use std::net::{Ipv4Addr, SocketAddrV4, TcpStream};
use std::os::linux::net::SocketAddrExt;
use std::os::unix::net::{SocketAddr, UnixStream};
+use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;
pub struct KeychainBackend;
-fn request(value: Value) -> Result<Value, TokenStoreError> {
- let name = std::env::var("DROIDDECK_XBOX_CREDENTIAL_SOCKET")
- .map_err(|_| std::io::Error::other("Android credential host is unavailable"))?;
- let address = SocketAddr::from_abstract_name(name)?;
- let mut stream = UnixStream::connect_addr(&address)?;
- stream.set_read_timeout(Some(Duration::from_secs(10)))?;
- stream.set_write_timeout(Some(Duration::from_secs(10)))?;
- serde_json::to_writer(&mut stream, &value)?;
+// keyed loopback port the app also listens on is used for the rest of the process.
+static LOOPBACK: AtomicBool = AtomicBool::new(false);
+static REPORTED: AtomicBool = AtomicBool::new(false);
+
+/// Letters and dashes only: the app passes `NEXUS_CREDENTIAL_ERROR_V1 [a-z-]{1,48}` lines to its log.
+fn reason(error: &std::io::Error) -> &'static str {
+ match error.raw_os_error() {
+ Some(111) => "refused",
+ Some(13) => "denied",
+ Some(1) => "not-permitted",
+ Some(2) => "missing",
+ Some(110) => "timed-out",
+ Some(38) => "unsupported",
+ Some(97) => "family-unsupported",
+ Some(22) => "invalid",
+ Some(104) => "reset",
+ Some(32) => "broken-pipe",
+ _ => match error.kind() {
+ std::io::ErrorKind::TimedOut | std::io::ErrorKind::WouldBlock => "timed-out",
+ std::io::ErrorKind::UnexpectedEof => "closed",
+ _ => "other",
+ },
+ }
+}
+
+fn exchange<S: Read + Write>(mut stream: S, prefix: Option<&str>, value: &Value) -> Result<Value, TokenStoreError> {
+ if let Some(key) = prefix {
+ stream.write_all(key.as_bytes())?;
+ stream.write_all(b"\n")?;
+ }
+ serde_json::to_writer(&mut stream, value)?;
stream.write_all(b"\n")?;
let mut bytes = Vec::new();
std::io::BufReader::new(stream).take(2_097_153).read_until(b'\n', &mut bytes)?;
@@ -22,10 +47,52 @@ fn request(value: Value) -> Result<Value, TokenStoreError> {
return Err(std::io::Error::other("Invalid Android credential response").into());
}
let response: Value = serde_json::from_slice(&bytes)?;
- if response["ok"] != true { return Err(std::io::Error::other("Android credential storage unavailable").into()); }
+ if response["ok"] != true {
+ eprintln!("NEXUS_CREDENTIAL_ERROR_V1 host-refused");
+ return Err(std::io::Error::other("Android credential storage unavailable").into());
+ }
Ok(response)
}
+fn loopback(value: &Value) -> Result<Value, TokenStoreError> {
+ let port: u16 = std::env::var("DROIDDECK_XBOX_CREDENTIAL_PORT").ok().and_then(|v| v.parse().ok())
+ .ok_or_else(|| std::io::Error::other("Android credential port is unavailable"))?;
+ let key = std::env::var("DROIDDECK_XBOX_CREDENTIAL_KEY")
+ .map_err(|_| std::io::Error::other("Android credential key is unavailable"))?;
+ let address = SocketAddrV4::new(Ipv4Addr::LOCALHOST, port).into();
+ let stream = TcpStream::connect_timeout(&address, Duration::from_secs(5)).inspect_err(|error| {
+ eprintln!("NEXUS_CREDENTIAL_ERROR_V1 loopback-{}", reason(error));
+ })?;
+ stream.set_read_timeout(Some(Duration::from_secs(10)))?;
+ stream.set_write_timeout(Some(Duration::from_secs(10)))?;
+ exchange(stream, Some(&key), value)
+}
+
+fn request(value: Value) -> Result<Value, TokenStoreError> {
+ if LOOPBACK.load(Ordering::Relaxed) { return loopback(&value); }
+ let name = std::env::var("DROIDDECK_XBOX_CREDENTIAL_SOCKET")
+ .map_err(|_| std::io::Error::other("Android credential host is unavailable"))?;
+ let address = SocketAddr::from_abstract_name(name)?;
+ match UnixStream::connect_addr(&address) {
+ Ok(stream) => {
+ stream.set_read_timeout(Some(Duration::from_secs(10)))?;
+ stream.set_write_timeout(Some(Duration::from_secs(10)))?;
+ exchange(stream, None, &value)
+ }
+ Err(error) => {
+ if !REPORTED.swap(true, Ordering::Relaxed) {
+ eprintln!("NEXUS_CREDENTIAL_ERROR_V1 socket-{}", reason(&error));
+ }
+ let result = loopback(&value);
+ if result.is_ok() {
+ LOOPBACK.store(true, Ordering::Relaxed);
+ eprintln!("NEXUS_CREDENTIAL_ERROR_V1 loopback-in-use");
+ }
+ result
+ }
+ }
+}
+
impl TokenBackend for KeychainBackend {
#[cfg(unix)]
fn mutation_lock(&self) -> Result<Box<dyn crate::tokens::store::TokenMutationGuard + '_>, TokenStoreError> {