libwebsockets
Lightweight C library for HTML5 websockets
|
lws-ssh-base is a protcol plugin for libwebsockets that implements a generic, abstract, ssh server.
libwebsockets-test-sshd
providedTo maintain its small size, it implements a single "best of breed" crypto for the following functions:
Function | Crypto |
---|---|
KEX | curve 2551 9-sha 256@ libss h.or g |
Server host key | ssh-rsa (4096b) |
Encryption | chach a20- poly1 305@ opens sh.c om |
Compression | None |
lws-ssh-base is Free Software, available under libwebsockets' MIT license.
The crypto parts are available elsewhere under a BSD license. But for simplicity the whole plugin is under MIT.
will ask for a passphrase and generate the private key in mykeys
and the public key in mykeys.pub
. If you already have a suitable RSA key you use with ssh, you can just use that directly.
lws installs a test keypair in /usr[/local]/share/libwebsockets-test-server that the test apps will accept.
1) There's a working example app libwebsockets-test-sshd
included that spawns a bash shell when an ssh client authenticates. The username used on the remote ssh has no meaning, it spawns the shell under the credentials of "lws-test-sshd" was run under. It accepts the lws ssh test key which is installed into /usr[/local]/share/libwebsockets-test-server.
Start the server like this (it wants root only because the server key is stored in /etc)
Connect to it using the test private key like this
2) There's also a working example plugin lws-sshd-demo
that "subclasses" the abstract lws-ssh-base
plugin to make a protocol which can be used from, eg, lwsws. For an lwsws vhost that listens on port 2222 and responds with the lws-sshd-demo ssh server, the related config is:
For the libwebsockets-test-sshd
example, you will need CMake options LWS_WITH_CGI
, since it uses lws helpers to spawn a shell.
lws-ssh-base itself doesn't require CGI support in libwebsockets.
Include lws-plugin-ssh-base
in your app, either as a runtime plugin or by using the lws static include scheme.
To bring in the whole of the ssh-base plugin into your app in one step, statically, just include plugins/ssh-base/include/lws-plugin-sshd-static-build-includes.h
, you can see an example of this in ./test-apps/test-sshd.c
.
plugins/ssh-base/include/lws-plugin-ssh.h
defines struct lws_ssh_ops
which is used for all customization and integration of the plugin per vhost. Eg,
The ssh_ops_...()
functions are your implementations for the operations needed by the plugin for your purposes.
A pointer to your struct lws_ssh_ops is passed into the vhost instance of the protocol using per-vhost options
There are two possible pvos supported, "ops", shown above, directly passes the ops structure in using the value on the "ops" pvo.
To support other protocols that want to provide ops to lws-ssh-base themselves for a particular vhost, you can also provide a pvo "ops-from"
whose value is the name of the protocol also enabled on this vhost, whose protocol ".user" pointer points to the ops struct lws-ssh-base should use.
A worked example of using the abstract lws-ssh-base
plugin from another plugin that provides the ops struct is in ./plugins/protocol_lws_sshd_demo
.
The key points to note
lws-ssh-base
by passing a pointer to the ops struct in its lws_protocols
struct user
member.lws-ssh-base
to pick up the ops struct pointer using an "ops-from" pvo that indicates the protocol name.lws-ssh-base
, not lws-ssh-base
itself, as the protocol to be served for raw connectionsYou can have the vhost it binds to listen on a nonstandard port. The ssh commandline app cane be told to connect to a non-22 port with ssh -p portnum user@hostname