|
libsshpp v0.1.7
Modern C++17 wrapper for libssh
|
A modern C++17 wrapper around libssh, packaged with CMake and Conan 2.
Status: M0 through M3 implemented, plus most of the remaining design (with a few documented scope trims).
Library, error handling,Session,SessionOptions, authenticators,Key/PKI,KnownHosts,HostKeyVerifierpolicies,Channel,Exec,Shell(incl.try_interact()and console prompt helpers underLIBSSHPP_WITH_CONSOLE), the SFTP module (sftp::Sftp/File/Directory, transfer helpers with path-traversal hardening, pipelinedFile::ReadAhead/WriteBehind), SCP (scp::Reader/Writer+try_upload/try_download), TCP/UNIX-socket port forwarding (open_direct,LocalForward,RemoteForward,X11Forwarder,SocksProxy,Connector/BidirectionalPump), and both server styles - message-pull (server::Bind/Session/Message) and event-driven callbacks (SessionHandler/ChannelHandler,SimpleAuthHandler,CommandHandler,SftpSubsystemHandler,server::TestServer) - are implemented and tested against a realsshd(and, for the server module, againstlibsshpp's own client) — see tests/, examples/01_exec.cpp.Relative to the full design, the following are not implemented: the forwarding module still serves one connection at a time per forwarder with a poll-based pump (
BidirectionalPumpincluded) rather than driving everything throughssh_connectorviaEvent; the callback-style server has no keyboard-interactive auth or tcpip-forward/direct-tcpip channel handling (the libssh version this targets has no callback slots for them - use the message style for those) and noOptions::faultsfault-injection inTestServer; there is no pcap module. The design documents in `docs/design/` remain the normative reference — code that contradicts them is a bug in one or the other.
Channel can never outlive the ssh_session it belongs to.ssh_get_error() text, and SFTP SSH_FX_* status codes all land in std::error_code-compatible categories.try_-prefixed form returning Result<T>. Pick one; no API is exception-only.ssh_options_set(s, SSH_OPTIONS_PORT, &port) void* guessing.Same thing without exceptions:
The full documentation site (design docs + generated API reference) is published at slightlabs.github.io/libsshpp on every tagged release.
| Document | Contents |
|---|---|
| API reference (Doxygen) | Generated from include/sshpp/ on every tagged release |
| Design index | Start here |
| 01 Goals and scope | Requirements, non-goals, platforms, licensing |
| 02 Architecture | Layering, lifetime model, threading, layout, ADRs |
| 03 Error handling | errc, ErrorInfo, Result<T>, exception hierarchy |
| 04 Core API | Library, Session, options, auth, keys, known hosts |
| 05 Channels | Channel, Exec, Shell, PTY, Event |
| 06 SFTP and SCP | File/dir APIs, transfers, attributes |
| 07 Forwarding | -L, -R, -D, X11, byte pumps |
| 08 Server | Bind, handlers, message loop, TestServer |
| 09 Build and packaging | CMake, Conan, install/export, header-only |
| 10 Testing and CI | Test pyramid, fuzzing, sanitizers, CI matrix |
| 11 Versioning and roadmap | SemVer/ABI policy, milestones |
| Option | Default | Effect |
|---|---|---|
LIBSSHPP_HEADER_ONLY | OFF | Build as an INTERFACE library, per 09 §9.3 |
LIBSSHPP_WITH_SFTP | ON | SFTP module |
LIBSSHPP_WITH_SCP | ON | SCP module |
LIBSSHPP_WITH_SERVER | ON | Server module: message-style and event-driven callback style, TestServer |
LIBSSHPP_WITH_FORWARDING | ON | Port forwarding: open_direct, LocalForward, RemoteForward, X11Forwarder, SocksProxy |
LIBSSHPP_WITH_CONSOLE | OFF | tty helpers: Shell::try_interact(), auth::console_*_prompt(), KeyboardInteractive::console_handler(), Chain::interactive_default() |
LIBSSHPP_BUILD_TESTS | top-level only | Catch2 test suite |
LIBSSHPP_SANITIZERS | "" | e.g. address;undefined |
Full list in 09 §9.2. Note: LIBSSHPP_WITH_CONSOLE defaults to OFF since a library embedded in a server has no business putting a terminal in raw mode or installing a SIGWINCH handler; opt in for CLI-style clients.
LIBSSHPP_SYSTEM_TESTS=ON builds an integration test that spins up a throwaway, unprivileged sshd (ephemeral host/client keys, temp known_hosts, high port) and exercises connect → verify host key → authenticate → exec end-to-end; see tests/integration/run_with_sshd.sh.
libsshpp is LGPL-2.1-or-later, matching libssh (see [LICENSE](LICENSE) and THIRD_PARTY_NOTICES.md).
Linking libsshpp statically (or using header-only mode) into a proprietary application propagates the LGPL's relinking obligations. The Conan recipe therefore defaults to libssh/*:shared=True. If you need different terms, obtain them from the libssh project — a wrapper cannot grant what it does not own. See 01 §1.7.
Host-key verification is a mandatory, explicit step: Session::connect() does not verify, and using a channel before verify_host_key() fails. Use StrictHostKeyPolicy or PinnedHostKeyPolicy in production; AcceptAnyHostKeyPolicy requires an i_understand_this_is_insecure() tag to construct.
When building remote commands from untrusted input, use the argv overload of Exec::run (or sshpp::shell_quote) — the std::string_view overload passes the command to the remote shell verbatim.
Report vulnerabilities privately per SECURITY.md.
See 10 §10.10 for the definition of done. Design changes go through a PR against docs/design/ first.