ws: Fix up mock-sshd to handle retrying non-blocking writes

There were corner cases in our testing where we would expect
all data to be written out. In reality not all data is expected
to be written during a write() or ssh_channel_write() so,
buffer it appropriately and only write when we are ready for it.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Add --broken-auth argument to mock-sshd

This lets us start mock-sshd in a way that ssh authentication should
always fail. We don't have host-based auth or public key auth, so
use those as our way of forcing failure.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Don't mix stderr and stdout in mock-sshd

In fact for testing purposes, just leave it connected to our normal
stderr so we can see failures.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Send exit termination signals from children of mock-sshd

We'll want to test these cases, even though we don't currently
do that.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Fix race closing down mock-sshd session/connection

Avoid printing an unnecessary warning in this case

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
common: Make cockpit_pipe_get_pid() more useful

It now returns TRUE if a pid was ever set or expected. The actual
pid is returned as an argument.

This lets us handle cases where callers want to behave differetnly
if a pipe was a process or not

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Add CockpitSshTransport which uses libssh

We'll migrate from our current sshpass + openssh client based
approach to libssh.

This doesn't use libgssh. libgssh unfortunately doesn't have a
pollable model (such as GPollableOutputStream and friends) which
is what we need to implement a CockpitTransport.

In addition the mechanism that it uses to do async work with
libssh (ie: eagain non-blocing based async) doesn't work well with
libssh 0.6.x upstream. Certain functions to make the corner cases
work are completely missing.

Lastly we need to authenticate in a thread, so we can support
kerberos (ie: GSSAPI). So implemented it this way in
CockpitSshTransport.

Part of fix for #69

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Use CockpitSshTransport for connecting to other hosts

Uses libssh instead of the openssh client for connecting to other
hosts.

We also remove some complexity from cockpit_pipe_transport_spawn()
which can no longer fail immedediately, but will close if failure.

Note that although the tests pass with this commit, running actual
webservice requires that you put known_hosts in the standard
format in the following file, for any hosts that you want to connect to:

  /var/lib/cockpit/known_hosts

This commit removes sshpass dependency.

Fixes #69

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Explicitly connect to 127.0.0.1 when testing

Some machines have 'localhost' in /etc/hosts that resolves to
an IPv6 address. While we support IPv6, our mock-sshd doesn't
support listening on both IPv4 and IPv6 localhost addresses. It
would be too complicated.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Expose host key for CockpitSshTransport

This allows us to look at the host key that the server offered,
regardless of whether verification succeeded or failed. Via
cockpit_ssh_transport_get_host_key() and the 'host-key' property.

In addition we want to be able to tell CockpitSshTransport to
explicitly expect a certain key and ignore other host verification
via the known-hosts file. This happens via 'host-key' construct
property.

Signed-off-by: Marius Vollmer <mvollmer@redhat.com>
 * No warning when host key is empty
ws: Modernize how test-webservice uses test fixtures

Use a struct for the fixture so we can extend them. In addition use
TestCase for the test struct, so we can be less confused.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Expose the host-key in the close channel message

If a channel closes with reason "unknown-hostkey" try to include
the host-key and host-fingerprint in the message so it can be
acted on by the caller.

I tried to come up with a better way to do this, such as allow
us to discover the host key for successfully opened channels. The
alternatives were complex and had all sorts of corner cases.

This solves the immediate need. The concept of having more
close fields is also used in the upcoming spawn-channel code
to relay exit codes and exit signals. So this bit is sound.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Add a channel open 'host-key' field for expecting a key

If we know which key to expect (such as after the user has
approved it) we can expect just that host-key when opening
a channel to a remote machine.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
web: Expose the error details in DBusClient

After closing due to an unknown-hostkey failure we want the details
of the host-key and host-fingerprint to be accessible on the
DBusClient.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
daemon: Make Machines object testable and add basic test

Simplify the periphery and around Machines and Machine objects
and decouple them from Daemon. This allows us to start writing
tests for this stuff. In addition construct properties don't
need to be getable if that's not necessary functionality.

Add a single test of a basic 'Add' call to Machines. This is
not meant to be comprehensive, but just get us started.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
daemon: Implement support for host keys when adding machine

Add a new host_key parameter to Machines.Add(). If non-empty the
key there gets added to our known_hosts file.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
web: Fix 'Login with my current credentials' checkbox

This checkbox had no effect.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Use display MD5 ssh key fingerprints as ssh client does

Use the standard MD5 fingerprints for display, just like the
openssh ssh client does.

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
ws: Quiet down mock-ssh a bit when it gets killed

Reviewed-by: Marius Vollmer <mvollmer@redhat.com>
web: Display fingerprints in initial setup and add to known_hosts

Show real host fingerprint in initial setup and add to known_hosts
so that we can later connect to the host without problems.

We refactor the connectting to another server in PageSetupServer a
bit since we need to reconnect at various stages with different
credentials and keys.

Closes #468

Signed-off-by: Marius Vollmer <mvollmer@redhat.com>
 * Reworked the code in cockpit-setup.js