Files
moon-i2p/README.md
T
nandiandClaude Opus 5.5 b803e79199
Rolling Release / Test (MoonBit, Extension, Scripts) (push) Successful in 19s
Rolling Release / Build & Publish Rolling Release (push) Successful in 2m22s
docs: showcase the AppImage in the README
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 22:43:53 -08:00

190 lines
13 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# moon-i2p
A clean, zero-dependency, pure-[MoonBit](https://www.moonbitlang.com/) implementation of the modern **I2P (Invisible Internet Project)** protocol suite and native router core, with pure protocol packages targeting `wasm`, `wasm-gc`, `js`, and `native`.
## Moon I2P Browser (Linux AppImage)
One file, no setup: the AppImage bundles Firefox ESR, the native `moon-i2p` router, and the torrent extension. Run it, wait a minute or two for tunnels, and browse `.i2p` sites. No Java, no separate I2P install, no proxy settings.
**[⬇ Download MoonI2P-Browser-x86_64.AppImage](https://git.site.latha.org/experiments/moon-i2p/releases/download/rolling/MoonI2P-Browser-x86_64.AppImage)** (about 109 MiB, rebuilt on every push to `main`)
![Moon I2P Start Page showing active tunnels, NetDB peers, and built-in .i2p destinations](docs/images/appimage-start-page.png)
```bash
base=https://git.site.latha.org/experiments/moon-i2p/releases/download/rolling
curl -fLO "$base/MoonI2P-Browser-x86_64.AppImage"
curl -fLO "$base/SHA256SUMS.txt"
sha256sum -c --ignore-missing SHA256SUMS.txt
chmod +x MoonI2P-Browser-x86_64.AppImage
./MoonI2P-Browser-x86_64.AppImage
```
<details>
<summary>Browsing <code>stats.i2p</code> over the bundled router</summary>
![stats.i2p loaded in the Moon I2P Browser](docs/images/appimage-eepsite.png)
</details>
What you get:
- **Live router status:** the Start Page shows tunnels, NetDB peers, DHT nodes, and torrents, with a bar for `.i2p` names, `.b32.i2p` addresses, and magnet links.
- **Built-in destinations:** `notbob.i2p`, `tracker2.postman.i2p`, `insulaocculta.i2p`, `stats.i2p`, and `zzz.i2p` open without an addressbook.
- **Torrents over I2P:** click a magnet or `.torrent` link on an eepsite to download it over I2P; files go to `~/Downloads/moon-i2p`.
- **Separate profile:** data lives in `~/.local/share/moon-i2p-browser`, apart from your everyday Firefox. The router stops when you close the browser.
- **Port fallback:** if `4444`, `4445`, or `7656` is taken, it picks a free port.
Good to know:
- **Only `.i2p` traffic goes through I2P.** Other sites load over your normal connection, so this is not a clearnet anonymity tool.
- On the very first launch, Firefox shows its own terms notice and its standard New Tab. Open a new tab to reach the Moon I2P Start Page; later launches open it directly.
- Needs x86_64 Linux with a desktop session, Bash, and Python 3 (extension-to-router control and port fallback). If FUSE is unavailable, add `--appimage-extract-and-run`.
- The router log is `~/.local/share/moon-i2p-browser/router.log`. To relocate data, set `MOON_I2P_DATA_DIR` or `MOON_I2P_DOWNLOAD_DIR`.
Build it yourself with `just appimage` (needs `moon`, a C compiler, `mksquashfs`, and `rsvg-convert` or ImageMagick); the result is `dist/MoonI2P-Browser-x86_64.AppImage`.
## Architecture & Implemented Modules
```
moon-i2p/
├── encoding/ # I2P Base64 (-/~), Base32 (.b32.i2p), DEFLATE/gzip/I2CP-gzip/ZIP, big-endian Reader/Writer, UTF-8, Hex
├── crypto/ # Pure-MoonBit SHA-256, SHA-512, HMAC/HKDF-SHA256, ChaCha20-Poly1305, AES-256-CBC, X25519, Elligator2, Ed25519, SipHash-2-4
├── common/ # Hash, KeyTypes, Certificate/KeyCertificate, Mapping, Destination, RouterIdentity, OfflineSignature, .su3 reseed, signed RouterInfo & LeaseSet2
├── i2np/ # 16-byte standard & 9-byte NTCP2 short headers, SHA-256 checksums, encrypted DatabaseLookup & core I2NP messages
├── noise/ # Noise_XK_25519_ChaChaPoly_SHA256 handshake/transport + NTCP2 SipHash-2-4 length masking
├── ntcp2/ # Pure-MoonBit NTCP2 (Noise_XKaesobfse+hs2+hs3, AES-256-CBC obfuscation, SipHash KDF, replay/clock checks, data-phase blocks)
├── ntcp2_net/ # Native POSIX non-blocking TCP dial/accept/frame transport, OS CSPRNG/clock, reseed HTTP/dir helpers
├── netdb/ # Pure-MoonBit NetDB & Floodfill Kademlia DHT (XOR distance, daily routing keys, gunzip type 0 RI, Ed25519-verified store)
├── tunnel/ # Pure-MoonBit Proposal 157 ShortTunnelBuild (218B records), 1024B TunnelData AES-256-CBC layer crypto, fragmentation & out-of-order relay
├── ratchet/ # Pure-MoonBit Proposal 144 ECIES-X25519-AEAD-Ratchet (Noise_IKelg2+hs2, NS/NSR/ES, DH ratchet, Garlic cloves, ECIES DSM replies)
├── streaming/ # Pure-MoonBit Ed25519-signed I2P Streaming (SYN/ACK/NACK/CLOSE/RESET, RTO retransmit, sliding window) & Repliable/Raw Datagrams
├── sam/ # SAMv3 text protocol parser, serializer, PING/PONG, and command builders
├── sam_client/ # Native POSIX TCP SAMv3 client with PING/PONG, --dest support, and modern I2P defaults
├── router/ # Native MoonBit I2P Router Core with NTCP2 peer pool, floodfill NetDB crawl, Proposal 157 transit tunnels, Garlic/Streaming, HTTP proxy & SAMv3 bridge
├── cmd/main/ # Pure protocol demo CLI entrypoint
├── cmd/router/ # Native MoonBit I2P router daemon (`--public`, `--http-proxy`, `--hops`, `--hosts`, `--debug`, `--sam`, `--ntcp2-port`, `--peer`, `--peer-dir`, `--su3`, `--reseed`, `--floodfill`)
├── cmd/client/ # Native SAMv3 CLI (`keygen`, `lookup`, `http-get`, `dial`, `listen`, `--sam`, `--dest`)
└── scripts/ # Loopback SAMv3 bridge (`mock_sam.py`), multi-router `demo.py`, and end-to-end test (`e2e_test.py`)
```
### Verified Test Vectors & Interop
Every cryptographic primitive in `crypto/` is verified against official standards:
- **SHA-256 & SHA-512**: FIPS 180-4 / NIST test vectors
- **HMAC-SHA256**: RFC 4231 test cases 1 & 2
- **HKDF-SHA256**: RFC 5869 test case 1
- **ChaCha20-Poly1305 AEAD**: RFC 8439 Section 2.8.2
- **AES-256 & AES-256-CBC**: NIST FIPS-197 Appendix C.3 & SP 800-38A F.2.5/F.2.6
- **X25519**: RFC 7748 Sections 5.2 & 6.1
- **Ed25519**: RFC 8032 Section 7.1 test vectors 1–3 (+ non-canonical `S >= L` & tamper rejection)
- **SipHash-2-4**: Official SipHash reference test vector
- **Live Public I2P Network Interop**:
- Live `.su3` HTTPS reseed import & Ed25519 verification (`User-Agent: Wget/1.11.4`).
- Live firewalled (`LU`) NTCP2 outbound handshakes and data-phase transport with public I2P routers.
- Live 1-hop & 2-hop Proposal 157 `ShortTunnelBuild` Inbound and Outbound tunnels (including OBEP ECIES `RGarlicKeyAndTag` replies).
- Live tunnel-routed Proposal 154 ECIES `DatabaseLookup` + iterative `DatabaseSearchReply` RI crawl resolving real public eepsite `LeaseSet2`s.
- Live end-to-end `client.exe http-get` over Proposal 144 ECIES Garlic (`NS`/`NSR`/`ES`) + Ed25519 I2P Streaming (including `OFFLINE_SIGNATURE` transient keys) against live public `.b32.i2p` eepsites (`stats.i2p`, `zzz.i2p`, `tracker2.postman.i2p`).
## Joining the Public I2P Network
```bash
# Build native router and SAMv3 client
moon build --target native cmd/router
moon build --target native cmd/client
# Join the live public I2P network behind NAT (auto-reseeds, connects NTCP2 peers, builds tunnels)
# Add --http-proxy 127.0.0.1:4444 to also run the native I2P browser HTTP proxy on port 4444:
./_build/native/debug/build/cmd/router/router.exe --public --hops 1 --http-proxy 127.0.0.1:4444
# Or via just:
just proxy
# Optional flags:
# --http-proxy [host:port] Enable HTTP-over-I2P proxy (default: 127.0.0.1:4444)
# --torrent-api [host:port] Enable BitTorrent + I2P DHT HTTP API (default: 127.0.0.1:4445)
# --download-dir <dir> Download directory for I2P torrents (default: ~/Downloads/moon-i2p)
# --hops <1..4> Tunnel length (e.g. --hops 2 for 2-hop Inbound & Outbound tunnels)
# --hosts <hosts.txt> Load hostname=base64dest (or .b32.i2p) entries from a local I2P hosts.txt
# --debug Log peer dials, tunnel builds, NetDB lookups, and Garlic/Streaming state
# Or launch via just (starts --public --http-proxy 127.0.0.1:4444 --torrent-api 127.0.0.1:4445):
just proxy
# Build a standalone zero-setup Android APK (arm64-v8a + x86_64, built-in Moon I2P Start Page):
just apk
# Install dist/MoonI2P-Browser-android.apk via `adb install -r dist/MoonI2P-Browser-android.apk`
# Firefox WebExtension + I2P DHT Torrent Manager:
# Installs native messaging host (~/.mozilla & ~/.config/mozilla) and packs .xpi:
just extension
# Load `extensions/firefox-i2p-torrent/manifest.json` temporarily in Firefox (`about:debugging`)
# or install `extensions/firefox-i2p-torrent.xpi`.
# Once tunnels are up (`tunnels=in:2/out:2`), browse .i2p / .b32.i2p eepsites via the HTTP proxy:
# Point your browser's HTTP Proxy to 127.0.0.1:4444 (or test with curl):
curl -x http://127.0.0.1:4444 http://stats.i2p/
curl -x http://127.0.0.1:4444 http://zzz.i2p/
# Note: Non-.i2p clearnet requests are blocked (403 Forbidden), CONNECT/https:// are rejected (501),
# User-Agent is normalized to MYOB/6.66 (AN/ON) for anti-fingerprinting compatibility,
# built-in aliases cover well-known public eepsites (stats.i2p, zzz.i2p, tracker2.postman.i2p,
# notbob.i2p, insulaocculta.i2p, tracker.insulaocculta.i2p, tracker.queke.i2p, opentracker.dg2.i2p),
# and ?i2paddresshelper=<dest> jump links register aliases on the fly.
# Or resolve and fetch directly via SAMv3 with cmd/client:
./_build/native/debug/build/cmd/client/client.exe lookup kqypgjpjwrphnzebod5ev3ts2vtii6e5tntrg4rnfijqc7rypldq.b32.i2p
./_build/native/debug/build/cmd/client/client.exe http-get kqypgjpjwrphnzebod5ev3ts2vtii6e5tntrg4rnfijqc7rypldq.b32.i2p /
```
## Rolling Releases (CI)
Every push to `main` runs Gitea Actions ([rolling-release.yml](.gitea/workflows/rolling-release.yml)) to test and publish/update the `rolling` release at <https://git.site.latha.org/experiments/moon-i2p/releases/tag/rolling>:
- `MoonI2P-Browser-x86_64.AppImage` — standalone Linux x86_64 Firefox ESR + native `moon-i2p` router bundle
- `MoonI2P-Browser-android.apk` — standalone Android (`arm64-v8a` + `x86_64`) WebView browser + bundled router
- `moon-i2p-firefox-extension.xpi` — standalone Firefox WebExtension
- `SHA256SUMS.txt` & `version.json` — checksums and build metadata
## Running the Local MoonBit Router & SAMv3 Client
```bash
# Build the native router and client binaries
moon build --target native cmd/router
moon build --target native cmd/client
# Start the MoonBit router (transient keys, NTCP2 listener + embedded SAMv3 bridge on 127.0.0.1:7656)
./_build/native/debug/build/cmd/router/router.exe --sam 127.0.0.1:7656 --ntcp2-port 14568
# In another terminal, talk to our MoonBit router with cmd/client:
./_build/native/debug/build/cmd/client/client.exe keygen
./_build/native/debug/build/cmd/client/client.exe listen "hello back"
./_build/native/debug/build/cmd/client/client.exe lookup <listener.b32.i2p>
./_build/native/debug/build/cmd/client/client.exe dial <listener.b32.i2p> "hello over i2p"
```
Default SAMv3 client settings:
- **Bridge:** `127.0.0.1:7656` (override with `--sam <host:port>` or `I2P_SAM_HOST` / `I2P_SAM_PORT`)
- **Protocol:** SAM `3.1`–`3.3`
- **Keys:** `TRANSIENT` destination, `SIGNATURE_TYPE=7` (`EdDSA_SHA512_Ed25519`)
- **I2CP Tunnel Defaults:** `i2cp.leaseSetEncType=4,0` (ECIES-X25519 preferred), 3-hop / 3-tunnel inbound & outbound pools
## Running Checks & Tests
```bash
moon test --target wasm
moon test --target js
moon test --target native
moon build --target native cmd/router && moon build --target native cmd/client
python3 scripts/e2e_test.py
```
## Roadmap
- [x] **Phase 1–2:** Core encoding, pure-MoonBit modern crypto, I2P Common Structures, I2NP messages, `Noise_XK_25519_ChaChaPoly_SHA256`, SAMv3 codec, and native SAMv3 TCP client + CLI (`sam_client/`, `cmd/client/`).
- [x] **Phase 3 (Signatures & Block Crypto):** Pure-MoonBit **SHA-512**, **Ed25519** (RFC 8032), **AES-256-CBC** (FIPS-197 / SP 800-38A), and Ed25519-signed `RouterInfo` & `LeaseSet2` (Proposal 123).
- [x] **Phase 4 (Direct Transport):** Full **NTCP2** protocol (`ntcp2/`) + native POSIX TCP transport (`ntcp2_net/`), verified live against public I2P floodfill routers.
- [x] **Phase 5 (Router Core):** Pure-MoonBit **NetDB** & Floodfill Kademlia DHT (`netdb/`), Proposal 157 **ShortTunnelBuild** & 1024-byte `TunnelData` layer crypto/relay (`tunnel/`), and native **Router Core** + embedded SAMv3 bridge (`router/`, `cmd/router/`).
- [x] **Phase 6 (Full End-to-End I2P Network Tunneling):**
- **ECIES-X25519-AEAD-Ratchet** (Proposal 144) with Elligator2, Bound/Unbound NS/NSR/ES, DH `NextKey` ratchet, Garlic cloves, and Proposal 154 ECIES `DatabaseLookup` replies (`ratchet/`).
- Active floodfill NetDB lookup/publish over NTCP2, `DatabaseSearchReply` iterative crawl, `.su3` reseed ZIP extraction, and gzip decompression for `DatabaseStore` type 0 (`netdb/`, `common/su3.mbt`, `router/`).
- Ed25519-signed **I2P Streaming** (SYN/ACK/NACK/CLOSE/RESET, sliding window & retransmit), **Repliable/Raw Datagrams** (`streaming/`), and multi-hop Proposal 157 **ShortTunnelBuild** + fragmented `TunnelData` transit relay (`tunnel/`, `router/`).
> **Note / Current Scope:** Transport is NTCP2 over TCP (`ntcp2/` / `ntcp2_net/`); SSU2 UDP transport and RSA-4096 certificate signature verification of `.su3` signer certificates are currently out of scope (all contained `RouterInfo` Ed25519 signatures inside `.su3` ZIP archives are verified before NetDB import).