A production-grade SSH-2 client/server library for Pony.
ponyssh is alpha-level software that will change frequently. Expect breaking changes. That said, you should feel comfortable experimenting with it in your projects.
- Install corral
corral add github.com/contact-red/ponyssh.git --version 0.1.0corral fetchto fetch your dependenciesuse "ssh_server"(and/oruse "ssh_client") to include the package you need:use "ssh_client"— create outbound client sessionsuse "ssh_server"— accept inbound connectionsuse "ssh_transport"— session, notify interfaces, algorithm preferencesuse "ssh_connection"— channel multiplexing and PTY supportuse "ssh_auth"— authentication message typesuse "ssh_crypto"— cipher, MAC, and key primitivesuse "ssh_error"— error union types
corral run -- ponyc -D openssl_3.0.xto compile your application
ponyssh links against OpenSSL 3.0.x at compile time and selects the backend with the openssl_3.0.x compile-time define. You need the OpenSSL development files installed in your build environment.
sudo apt-get install -y libssl-devsudo dnf install openssl-develbrew update
brew install openssl@3A minimal echo server. See examples/echo-server for the complete, runnable version.
use "lori"
use "ssh_transport"
use "ssh_server"
actor Main
new create(env: Env) =>
let pem: Array[U8] val = MyHostKey() // your host key, PEM-encoded
// SshServerConfig validates the host key, so its constructor is partial.
// Algorithm preferences default to the implemented set; to customise them
// pass `SshAlgorithmPreferences` with named arguments and override only the
// categories you need.
let config =
try
SshServerConfig(pem, "0.0.0.0", "2222")?
else
env.out.print("invalid host key; aborting")
return
end
let auth = TCPListenAuth(env.root)
SshListener(auth, config, MyServerNotify(env))Your MyServerNotify implements SshServerNotify. Authentication and authorization deny by default: implement validate_password / validate_publickey to accept credentials, and override the channel/shell callbacks to grant access (they reject unless overridden).
A minimal client:
use "lori"
use "ssh_transport"
use "ssh_auth"
use "ssh_client"
actor Main
new create(env: Env) =>
let config = SshClientConfig("example.com", "22", "alice",
recover val [as SshAuthMethod val: SshPasswordAuth("hunter2")] end)
let auth = TCPConnectAuth(env.root)
SshConnector.connect(auth, config, MyClientNotify(env))MyClientNotify implements SshClientNotify. It must approve the server host key in ssh_verify_host_key (call session.accept_host_key() or session.reject_host_key()) and acts on the session once ssh_ready fires.