Files
CydandClaude Fable 5 91640dcbf2 XP11: whole suite on net40 — Console + vPOD run on XP SP3 through Win11
The Launcher's XP11 port (8730b9b) now extends to everything: one net40
flavor across Console, vPOD, Contract, and SecureConfig (Newtonsoft.Json
everywhere; the net48/System.Text.Json legs and their #if splits are gone
since nothing consumed them).

Console (net40, single TFM like the Launcher):
- The ~31 BinaryFormatter bitmap blobs in the .resx files became raw
  embedded files under assets/icons/ (extracted byte-faithfully via a
  serialization surrogate — the animated square_throbber.gif survives),
  loaded by Properties.Resources.EmbeddedBitmap/EmbeddedIcon. Reason:
  System.Resources.Extensions' DeserializingResourceReader is net461+
  and cannot load on net40. Strings stay in the .resx.
- IReadOnlyList -> IList in AppRegistry (net45+ interface).

vPOD (net40, single TFM):
- Zip extraction now shares the Launcher's MiniZip.cs (linked source), so
  the diff-test install round-trip exercises it against ZipArchive zips.
- RPC args as JTokens; LaunchApps.json persistence via Newtonsoft;
  Thread.VolatileRead instead of Volatile.Read.

Contract/SecureConfig: net40-only; Client/** (PodManagerConnection) now
ships in the one build. The Launcher package gains
TeslaSecureConfiguration.dll as a dependency of the client half.

Tests: the net48 xunit host loads the net40 assemblies (both CLR4), so
the suite exercises exactly what ships — 106/106 green. Also verified
live: net40 console provisioned, managed, and ran a full RP mission
against net40 vPOD (beacon/passphrase/RSA, 53290 RPC, egg load,
Run/Stop Mission).

Version: 4.11.4.3 across Launcher, Console, and vPOD (vPOD joins the
suite version line; was 1.0.0). Ship the dotNetFx40 redistributable in
Launcher/assets for XP-era pods.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 21:01:34 -05:00

132 lines
6.2 KiB
C#

// =============================================================================
// Tesla.Contract — Pod RPC protocol (Console <-> Launcher Service)
// =============================================================================
// The framed, JSON-based replacement for the old OFB-encrypted BinaryFormatter
// RPC. Runs ON TOP of the same OFB-encrypted stream (NegotiateCryptoStreams is
// unchanged); only the per-message serialization changed.
//
// Wire format, after the OFB/CONF handshake:
// request : [4-byte little-endian length][UTF-8 JSON RpcRequest]
// response: [4-byte little-endian length][UTF-8 JSON RpcResponse]
// The InitiateInstallProduct out-of-band file transfer (8-byte length + raw
// bytes) is unchanged and still follows its response frame on the same stream.
//
// Dispatch is by method NAME (RpcRequest.Method) — the old serialized-MethodBase
// + SerializationBinder + MethodInfoProxy machinery is gone. Both ends share this
// one file, so the request/response shape cannot drift.
//
// Serializer: Newtonsoft.Json — System.Text.Json has no net40 target, and since
// XP11 the whole suite (Console, Launcher, vPOD) is net40. The protocol briefly
// had an STJ leg for the net48 Console era; it wrote shape-identical JSON
// (PascalCase member names, fields included, Guids as strings, ISO-8601 dates),
// so anything that captured wire traffic then still matches what this writes.
// =============================================================================
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Tesla.Net
{
/// <summary>One RPC call: a method name plus its arguments as JSON tokens.</summary>
public sealed class RpcRequest
{
public string Method { get; set; }
public List<JToken> Args { get; set; }
}
/// <summary>One RPC result: the return value as JSON, or an error message.</summary>
public sealed class RpcResponse
{
public JToken Result { get; set; } // JSON null for void / null
public string Error { get; set; } // null on success
}
/// <summary>Framing + (de)serialization shared by the Console client and the
/// Launcher Service. Synchronous to match the existing stream usage.</summary>
public static class PodRpc
{
/// <summary>Upper bound on a single JSON frame (the bulk install payload is
/// streamed out-of-band, not framed), guarding against hostile lengths.</summary>
public const int MaxFrameBytes = 16 * 1024 * 1024;
// Newtonsoft serializes public fields of the wire types by default, and
// writes ISO-8601 dates / string Guids — no special options needed.
public static readonly JsonSerializer JsonOptions = JsonSerializer.CreateDefault();
// ── Framing ──────────────────────────────────────────────────────────
public static void WriteFrame(Stream stream, byte[] payload)
{
if (payload.Length > MaxFrameBytes)
throw new IOException($"RPC frame too large ({payload.Length} bytes).");
var len = BitConverter.GetBytes(payload.Length); // little-endian on x86/x64
stream.Write(len, 0, 4);
stream.Write(payload, 0, payload.Length);
stream.Flush();
}
public static byte[] ReadFrame(Stream stream)
{
var lenBuf = ReadExact(stream, 4);
int len = BitConverter.ToInt32(lenBuf, 0);
if (len < 0 || len > MaxFrameBytes)
throw new IOException($"RPC frame length out of range ({len}).");
return ReadExact(stream, len);
}
private static byte[] ReadExact(Stream stream, int count)
{
var buf = new byte[count];
int off = 0;
while (off < count)
{
int n = stream.Read(buf, off, count - off);
if (n == 0) throw new EndOfStreamException("Connection closed mid-frame.");
off += n;
}
return buf;
}
// ── Request ──────────────────────────────────────────────────────────
public static void WriteRequest(Stream stream, string method, object[] args)
{
var req = new RpcRequest { Method = method, Args = new List<JToken>() };
if (args != null)
foreach (var a in args)
req.Args.Add(a == null ? JValue.CreateNull() : JToken.FromObject(a, JsonOptions));
WriteFrame(stream, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(req)));
}
public static RpcRequest ReadRequest(Stream stream)
=> JsonConvert.DeserializeObject<RpcRequest>(
Encoding.UTF8.GetString(ReadFrame(stream)), ReadSettings);
// Keep date-looking strings as raw strings so an echoed argument (Ping)
// goes back byte-identical instead of reformatted through DateTime.
private static readonly JsonSerializerSettings ReadSettings =
new JsonSerializerSettings { DateParseHandling = DateParseHandling.None };
// ── Response ─────────────────────────────────────────────────────────
public static void WriteResponse(Stream stream, object result, string error)
{
object payload = error == null ? result : null;
var resp = new RpcResponse
{
Result = payload == null ? JValue.CreateNull() : JToken.FromObject(payload, JsonOptions),
Error = error,
};
WriteFrame(stream, Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(resp)));
}
public static RpcResponse ReadResponse(Stream stream)
=> JsonConvert.DeserializeObject<RpcResponse>(
Encoding.UTF8.GetString(ReadFrame(stream)), ReadSettings);
}
}