# scorpiox-scorpioplayer-ssh-transport-client

**SCORPIO PLAYER 2027** engine, row 49. SSH-2 **client** transport in pure C99 —
the client twin of row 48 `scorpiox-scorpioplayer-ssh-transport-server` (`spsshs`).

## What it does

| Stage | Detail |
|---|---|
| KEX | `curve25519-sha256` (+`@libssh.org`), `diffie-hellman-group14-sha256`, `diffie-hellman-group16-sha512`; strict KEX (Terrapin) enforced both directions |
| Host key | `ssh-ed25519`, `rsa-sha2-256`, `rsa-sha2-512` (verify-only; never bare `ssh-rsa`/SHA-1). **TOFU pinning**: `spsshc_connect` takes a `SHA256:...` pin; a mismatch is the hard error `HOSTKEY_CHANGED` — the legacy Renci.SshNet usage had **no** host-key check at all |
| Ciphers | `chacha20-poly1305@openssh.com`, `aes128/256-gcm@openssh.com`, `aes128/256-ctr` + `hmac-sha2-256(-etm)` |
| Auth | `password` (with a keyboard-interactive fallback for NAS), `publickey` (OpenSSH-format ed25519 / RSA private key, unencrypted or bcrypt-pbkdf-encrypted), `keyboard-interactive`; post-auth re-auth is refused (RFC 4252) — disconnect + reconnect to re-auth |
| Channels | several concurrent `session` channels; `subsystem` (duplex handle — row 41 `sftp-file-client` plugs in here); `exec` with stdout/stderr/exit-status/exit-signal, timeout + output cap; `exec_argv` POSIX-quotes every argument so the client never builds a command string from untrusted input |
| Extras | `keepalive@openssh.com`, reconnect helper, re-key accounting, read-only op table (`spsshc_read_only()` is 1 by construction) |

Crypto is vendored Monocypher (see `THIRD_PARTY.md`). No OpenSSL, no libssh, no libssh2.

## Build

```
make                 # spsshc CLI + libscorpiox-scorpioplayer-ssh-transport-client.so
make test            # unit (42) + exports check + loopback interop (needs spsshs + sshd + dropbear)
make asan            # ASAN/UBSAN unit build
make fuzz            # libFuzzer targets
```

## CLI

```
spsshc connect <host> [port] [--pin SHA256:..] [--timeout MS]
spsshc auth password <user> <pass> | auth key <user> <keyfile> [passphrase]
spsshc exec <ch|new> "<command>" [--timeout MS] [--max-out N]
spsshc exec-argv <ch|new> <arg> [<arg>]      # POSIX single-quote quoting
spsshc subsystem <name> | write <ch> <text> | read <ch> | close <ch>
spsshc status | disconnect | selftest
spsshc run <verb> ;; <verb> ;; ...           # several verbs in one process
```

## Oracle transcript (2026-10-01, loopback, high ports only)

`results/interop.txt` — 18/18 PASS:

| Server | Negotiated | Checks |
|---|---|---|
| row-48 `spsshs` | curve25519-sha256 + ssh-ed25519 + chacha20-poly1305 both dirs | TOFU connect, correct pin, wrong pin → hard HOSTKEY_CHANGED, password auth, exec, exit-status of a missing binary |
| OpenSSH sshd **RSA-only** (Synology-style `HostKeyAlgorithms rsa-sha2-512,rsa-sha2-256`) | curve25519-sha256 + **rsa-sha2-512** + chacha20-poly1305 | connect, RSA host-key verify, password auth, exec, RSA-3072 publickey auth (OpenSSH key format) |
| OpenSSH sshd (ed25519) | curve25519-sha256 + ssh-ed25519 + chacha20-poly1305 | connect, ed25519 publickey auth, exec |
| dropbear 2020.81 | curve25519-sha256 + ssh-ed25519 + chacha20-poly1305 | connect, password auth, publickey auth |

Host-key change proof: a wrong pin is refused with `SPSSHC_E_HOSTKEY` before auth (`pinned mismatch → hard HOSTKEY_CHANGED`).

## Exports

28 `spsshc_*` exports (`exports.json` == `nm -D --defined-only`), header `include/spsshc.h`.

## Defects found and fixed during the build

- **P0**: `spsshc_disconnect()` closed the socket but left `connected=1, dead=0`; the next
  disconnect re-entered `send_raw_packet` → `poll(fd=-1)`, which POSIX *ignores* and blocks
  the full 30 s timeout — every CLI run stalled ~30 s. Fixed by marking the connection gone
  in `disconnect()` and refusing to poll a dead socket in `sock_write_all`.
- `spsshc_connect()` after an internal `disconnect()` inherited `dead=1`; fresh connects now
  clear it explicitly.
- CLI `run` mode continued the verb chain after a failure, sending pre-auth CHANNEL_OPENs
  (real sshd answers `dispatch_protocol_error type 90` and drops the connection); the chain
  now stops at the first failing verb.

## Console harness

`scorpiox-scorpioplayer-ssh-transport-client.console` — `dotnet run -- --test` covers every
export offline through the `spsshc_test_*` hooks (no network host).

## Tracker

`scorpio-player-2027-pure-c-dll-fleet-from-tplayer-uwp-and-ioslegacy-uno-code-as-spec-tracker` in the picobot repo.
