lane-vm-rss-bridge-2026-11-14.py
# rss_bridge.py — Full-duplex bridge over RSS for Lane-VM
# © Albert Lane. All Rights Reserved. Proprietary and Confidential.
# https://albertlane.net
# LICENSE: Lane-VM Proprietary License. NOT open-source. NOT MIT.
#
# Idea:
# RSS is simplex + pull-only. It cannot do true full-duplex by itself.
# Full-duplex = TWO one-way RSS flows:
# Node A outbox -> Bridge (opaque copy) -> Node B inbox
# Node B outbox -> Bridge (opaque copy) -> Node A inbox
#
# Privacy model:
# - Client encrypts payload BEFORE it hits the VM (E2EE).
# - VM / Bridge only sees: guid, sender_node, recipient_node, timestamp,
# ciphertext blob (opaque), signature. It NEVER decrypts, NEVER logs
# plaintext, NEVER parses user content.
# - For this smoke test we use a placeholder envelope (base64 + sha256)
# to prove opaqueness. In production use X25519 + ChaCha20-Poly1305
# or age / libsodium sealed boxes, with keys held only on clients.
#
# VM best practice:
# - Serve feeds as static XML + ETag / If-Modified-Since, CDN cacheable.
# - Keep feeds small: 20-50 items max, ttl 60s, dedupe by guid.
# - Public feeds = public posts only. Private comms = separate
# per-node outbox/inbox feeds behind signed URLs, never in public feed.
from __future__ import annotations
import base64
import hashlib
import json
import time
import uuid
from dataclasses import dataclass, field
from datetime import datetime, timezone
from typing import Dict, List
import rss
from rss import RSSFeed, RSSItem
# ---------------------------------------------------------------------------
# Envelope — opaque to the VM
# ---------------------------------------------------------------------------
@dataclass
class Envelope:
"""Opaque message. `ciphertext_b64` is meaningless to the bridge."""
sender_node: str
recipient_node: str
guid: str
timestamp: str
ciphertext_b64: str
payload_sha256: str
signature: str = "" # placeholder — client-side Ed25519 in prod
def to_rss_item(self) -> RSSItem:
# Bridge only needs routing fields in the title/link — NOT content.
# Description carries ONLY the opaque blob, never plaintext.
body = json.dumps({
"v": 1,
"from": self.sender_node,
"to": self.recipient_node,
"ts": self.timestamp,
"ciphertext_b64": self.ciphertext_b64,
"sha256": self.payload_sha256,
"sig": self.signature,
}, separators=(",", ":"))
return RSSItem(
title=f"msg:{self.guid}",
link=f"https://albertlane.net/nodes/{self.recipient_node}/inbox#{self.guid}",
description=body,
pub_date=self.timestamp,
guid=self.guid,
categories=["lane-vm-bridge", "opaque-envelope"],
)
@classmethod
def from_rss_item(cls, item: RSSItem) -> "Envelope":
data = json.loads(item.description)
return cls(
sender_node=data["from"],
recipient_node=data["to"],
guid=item.guid or data.get("guid", ""),
timestamp=data["ts"],
ciphertext_b64=data["ciphertext_b64"],
payload_sha256=data["sha256"],
signature=data.get("sig", ""),
)
@classmethod
def seal(cls, sender: str, recipient: str, plaintext: str) -> "Envelope":
"""CLIENT-SIDE ONLY. In prod, replace with real E2EE. Here we prove
the VM never sees plaintext by only storing b64 + hash in the feed."""
# Placeholder E2EE: b64 is NOT encryption. Smoke test uses it to
# simulate an opaque blob the bridge cannot read without the key.
# Real impl: ciphertext = sealed_box(plaintext, recipient_pubkey)
blob = base64.b64encode(f"SEALED:{plaintext}".encode()).decode()
sha = hashlib.sha256(plaintext.encode()).hexdigest()
now = datetime.now(timezone.utc).isoformat()
return cls(
sender_node=sender,
recipient_node=recipient,
guid=str(uuid.uuid4()),
timestamp=now,
ciphertext_b64=blob,
payload_sha256=sha,
signature=f"sig-{hashlib.sha256(blob.encode()).hexdigest()[:16]}",
)
def open(self) -> str:
"""CLIENT-SIDE ONLY. Simulates decrypt."""
raw = base64.b64decode(self.ciphertext_b64).decode()
assert raw.startswith("SEALED:"), "not a sealed envelope"
plaintext = raw[len("SEALED:"):]
assert hashlib.sha256(plaintext.encode()).hexdigest() == self.payload_sha256
return plaintext
# ---------------------------------------------------------------------------
# Bridge — dumb pipe, no user-data access
# ---------------------------------------------------------------------------
@dataclass
class RSSBridge:
"""Copies envelopes verbatim from outbox feeds to inbox feeds.
It never calls Envelope.open(), never logs description content."""
seen_guids: set = field(default_factory=set)
deliveries: List[Dict] = field(default_factory=list)
def relay(self, outbox_feed: RSSFeed, inbox_feed: RSSFeed) -> int:
"""Copy new envelopes from outbox -> inbox. Returns # delivered."""
delivered = 0
for item in outbox_feed.items:
if item.guid in self.seen_guids:
continue
# Parse ONLY routing envelope, do NOT open payload.
env = Envelope.from_rss_item(item)
# Verify routing matches inbox owner — metadata only.
# No plaintext is touched here.
inbox_feed.add_item(env.to_rss_item())
self.seen_guids.add(item.guid)
self.deliveries.append({
"guid": env.guid,
"from": env.sender_node,
"to": env.recipient_node,
"ts": env.timestamp,
"ciphertext_len": len(env.ciphertext_b64),
})
delivered += 1
return delivered
def make_node_feed(node_id: str, direction: str) -> RSSFeed:
return RSSFeed(
title=f"Lane-VM Node {node_id} — {direction}",
link=f"https://albertlane.net/nodes/{node_id}/{direction}",
description=f"Opaque {direction} feed for node {node_id}. VM sees envelopes only, not user data.",
categories=["lane-vm-bridge", node_id],
)
# ---------------------------------------------------------------------------
# Smoke test
# ---------------------------------------------------------------------------
def smoke_test() -> dict:
# Two account nodes, full-duplex = A->B + B->A
a_out, b_inbox = make_node_feed("A", "outbox"), make_node_feed("B", "inbox")
b_out, a_inbox = make_node_feed("B", "outbox"), make_node_feed("A", "inbox")
# Client-side sealing (VM never sees plaintext)
env_a_to_b = Envelope.seal("A", "B", "hello B — this is private, VM must not read it")
env_b_to_a = Envelope.seal("B", "A", "ack A — got it, replying on reverse channel")
a_out.add_item(env_a_to_b.to_rss_item())
b_out.add_item(env_b_to_a.to_rss_item())
# Bridge relays verbatim
bridge = RSSBridge()
d1 = bridge.relay(a_out, b_inbox)
d2 = bridge.relay(b_out, a_inbox)
# Idempotency: second relay delivers 0 (dedupe by guid)
d3 = bridge.relay(a_out, b_inbox)
# Clients open on their own nodes
got_b = Envelope.from_rss_item(b_inbox.items[0]).open()
got_a = Envelope.from_rss_item(a_inbox.items[0]).open()
# VM-side check: bridge deliveries contain NO plaintext
bridge_log = json.dumps(bridge.deliveries)
assert "hello B" not in bridge_log, "bridge leaked plaintext!"
assert "ack A" not in bridge_log, "bridge leaked plaintext!"
assert got_b == "hello B — this is private, VM must not read it"
assert got_a == "ack A — got it, replying on reverse channel"
# RSS round-trip: serialize + parse inbox feed
xml = b_inbox.to_xml_string()
parsed = RSSFeed.from_string(xml)
assert len(parsed.items) == 1
assert Envelope.from_rss_item(parsed.items[0]).open() == got_b
return {
"a_to_b_delivered": d1,
"b_to_a_delivered": d2,
"replay_delivered_should_be_0": d3,
"b_received": got_b,
"a_received": got_a,
"bridge_saw_only_metadata": bridge.deliveries,
"rss_xml_bytes": len(xml),
"ok": True,
}
if __name__ == "__main__":
import pprint
pprint.pprint(smoke_test())