An OpenSSH-compatible SSH client, server and SFTP stack written from scratch in MoonBit.
moon add riantr/moonbit_opensshThis file is the module README, and moon.mod points readme at README.mbt.md. The repository-root README.md is a symlink to it (mode 120000 in git), so the two names are one file and editing either edits both. That is deliberate: a README that can drift from the one moon.mod ships is a README that will eventually be wrong.
| field | offered |
|---|---|
| key exchange | diffie-hellman-group14-sha256 |
| host key | ssh-ed25519, rsa-sha2-512, rsa-sha2-256, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384 |
| host key, when a @cert-authority anchor exists | the above plus ssh-ed25519-cert-v01@openssh.com |
| cipher | aes128-ctr |
| MAC | hmac-sha2-256 |
| compression | none |
| layer | packages | what is proven |
|---|---|---|
| protocol rules | bpacket, kexflow, sshd | built on all four by CI; src/sshd's 23 unit tests pass on each |
| the demo | cmd/main | byte-exact on 4 targets x 2 modes; host/main.wasm is its wasm-gc build, instantiated and asserted in a browser |
| platform seams | rng, tcp, subproc, sftpserver, scp, agentpipe, keyperm | compile on all four: one file per backend, and the backend that lacks the platform says so instead of pretending |
| live native stack | khfile, cmd/sshd, cmd/ssh_live, cmd/sftp_server | native only -- files, sockets and child processes |
| live browser stack | wt, wtlive, khstore, cmd/wt_ssh | js only: extern "js", and MoonBit's async does not cover the wasm backends |
| wasm sockets | ws_socket, wt_socket | extern "wasm", so a host shim supplies send / recv / close |
# per-package unit tests
cmd /c "moon test src\knownhosts"
cmd /c "moon test src\hostkey"
cmd /c "moon test src\khfile --target native" # native-only package
# live client, and the server
cmd /c "moon build cmd\ssh_live --target native"
cmd /c "moon build cmd\sshd --target native"python ci\ci.py # env,build,gates (the default)
python ci\ci.py --tiers env,build,gates,qa # the release run
python ci\ci.py --self-check # tests the engine itself
python ci\ci.py --only loop94 --tiers gates # one gatepython ci\publish.py --check # offline: manifest + metadata
python ci\publish.py --check --next-tag v0.1.4 # ...and the version match
python ci\ci.py --tiers env,build,gates,qa --tag # tags; the tag push publishes
# one-time: give the runner the login state that `moon login` wrote
Get-Content -Raw "$env:USERPROFILE\.moon\credentials.json" |
gh secret set MOONCAKES_RIANTR_TOKENnode host\verify_loop94.mjs # 49 checks -- the server, against a real ssh.exe
node host\verify_loop93.mjs # 28 checks -- the server: KEX + publickey auth
node host\verify_loop54.mjs # 16 checks -- the TOFU write-back lands
node host\verify_loop53.mjs # 26 checks -- host certificates, both transports
node host\verify_loop52.mjs # 9 checks -- the pin survives the page going away
node host\verify_loop47.mjs # 19 checks -- a peer that lies about its host key
node host\verify_loop45.mjs # 51 checks -- fault vectors over a real socket
node host\verify_loop41.mjs # 29 checks -- byte-identical to a Python oracle
node host\verify_loop89.mjs # 81 checks -- the agent, against the REAL ssh-addpython host\loop54_mutations.py # 3 CAUGHT, 0 MISSED
python host\loop53_mutations.py
python host\loop89_mutations.py # 23 CAUGHT, 0 MISSEDsrc/
sshwire/ kexflow/ kexdh/ kexc25519/ transport and key exchange
aes/ chacha/ aead/ hmac/ poly1305/ ciphers and MACs, written here
sha256/ sha512/ bigint/ primitives, written here
ed25519/ ecdsa/ rsa/ x25519/ key types, written here
blowfish/ bcrypt_pbkdf/ the legacy cipher and the key-file KDF
hostkey/ host keys, certificates, signatures
knownhosts/ known_hosts parsing and pinning rules
khfile/ khstore/ where a TOFU write-back goes
(native file / browser IndexedDB)
sftp/ sftpserver/ sftpdrive/ scp/ SFTP both ends, and scp
bpacket/ channel/ the packet and channel layer
sshclient/ wtlive/ the two transport adapters
socket/ tcp/ ws_socket/ wt_socket/ byte-stream seams, one per target
sshd/ the server: transport, connection protocol
subproc/ child processes, three pipes, deadlines
userauth/ sshconfig/
agent/ agentserver/ agentpipe/ the SSH agent: protocol, server, pipe
keyfile/ keyperm/ the OpenSSH private key file, its perms
rng/ the platform CSPRNG, or the refusal
cmd/
ssh_live/ the native client
sshd/ the server
wt_ssh/ the browser client
ssh_agent/ ssh_add/ the agent daemon and its client
ssh_keygen/ ssh_keyscan/ make, read, rewrite, scan keys
scp/ sftp_server/ sftp_mitm/ the scp and SFTP drivers the gates use
main/ the 4-target byte-exact demo
*_test/ *_kat/ *_probe/ bench_*/ known-answer, property and bench drivers
host/ python man in the middle + the gates
ci/ the step engine, the tag gate, publishcmd /c "moon build --target wasm-gc --release cmd\main"
# then copy _build\wasm-gc\release\build\cmd\main\main.wasm to host\main.wasm
node host\browser_test.mjs # asserts its output byte for byteIt carries the module name in the name custom section behind a length
prefix, so a search-and-replace inside it corrupts the file in a way
WebAssembly.validate only sometimes reports: the renamed module
riantr/moonbit_openssh is one byte shorter than the old one, and the stale
prefix then reads one byte past the end of the string.Install
Download zipAn OpenSSH-compatible SSH client, server and SFTP stack written from scratch in MoonBit.