Table of Contents

Testing and validation

An SSH library is trusted with credentials, host keys and other people's servers, so how it is tested matters as much as what it does. This page describes what is tested, against what, how intermittent failures are hunted down, and what is not covered yet.

At a glance

What How
Unit tests About 1,300 per target framework, with no network: scripted fake servers and agents over in-memory streams, and a fake clock
Known-answer vectors RFC and reference vectors, OpenSSL's Curve25519 vectors, the sntrup761 KAT, and about 6,400 Project Wycheproof edge cases
Real servers OpenSSH (from 7.x to current, Linux and Windows), Dropbear, AsyncSSH, Apache MINA SSHD, Erlang/OTP ssh, and three SFTP-only servers (ProFTPD among them), on every pull request
Network faults A proxy that cuts, stalls, slows down and fragments connections to real servers, at any point
Fuzzing Coverage-guided fuzzing of the parsers that read untrusted input, nightly; mutation fuzzing in every test run
Mutation testing Stryker.NET over the cryptography, the packet codec, compression, the configuration parsers and resolver, the agent server, the SOCKS handshake, host key verification and the log rate limiter
Stress The whole suite in a loop on every platform, with an instrumented build that checks buffer ownership and received data
Platforms Linux (x64, Arm64), Windows (x64, Arm64), macOS (Arm64), each on .NET 8, .NET 10 and .NET 11, plus a Native AOT smoke test and the ML-KEM tests on Linux with OpenSSL 3.5
Algorithm audit ssh-audit rates what the client offers, by default and in FIPS mode, on every pull request
Static analysis CodeQL, the .NET analyzers at their recommended level with warnings as errors, and tracked public API

Unit tests

The protocol stack runs over any Stream, so the unit tests need no network. Scripted fake servers (FakeSshServer, FakeSessionServer, FakeSftpServer) and a fake SSH agent play the other side over in-memory pipes. They can also misbehave on purpose: send malformed or out-of-order messages, stall, refuse, reorder SFTP replies, or answer slowly. Time comes from a TimeProvider, so keep-alives, channel timeouts, re-key intervals and keystroke timing are tested on a fake clock. Real sleeps are not used. A test that checks concurrency synchronizes on it rather than racing it: FakeSftpServer can hold the first SFTP request of a kind (a read or write, a removal, an open) unanswered until a second one has arrived, so a test that the client sends them together passes however slow the client is. The file system, the environment and Match exec sit behind small delegates.

Inputs come from the real tools wherever possible:

  • known_hosts files and KRLs made by OpenSSH
  • private keys made by ssh-keygen, in every format and with every cipher it can encrypt a key with
  • PuTTY .ppk files made by puttygen
  • the key files SshSharp writes (OpenSSH, PKCS#8, .ppk), read back by ssh-keygen, OpenSSL and puttygen; and unencrypted keys OpenSSL and puttygen make, written back byte for byte
  • ssh_config files using OpenSSH's own syntax and tokens

Cryptography

SshSharp uses the .NET libraries for every primitive they provide on both target frameworks. It implements X25519, Ed25519, ChaCha20, Poly1305, AES-CTR and sntrup761 itself (on .NET 11, X25519 comes from the platform where the OS provides it, and the managed one is the fallback; the tests run the RFC, OpenSSL and Wycheproof vectors through both). Those implementations are checked against:

  • Reference vectors: the RFCs' test vectors, OpenSSL's Curve25519 vectors, and the sntrup761 known-answer tests.

  • Project Wycheproof: about 6,400 edge cases, each of which broke a real implementation somewhere. They cover:

    • X25519 (low-order and non-canonical points) and Ed25519 (non-canonical encodings, malleable signatures)
    • ChaCha20 and Poly1305, through RFC 8439's construction
    • ECDH on P-256, P-384 and P-521 (invalid-curve attacks, points on the wrong curve), through the key exchange's own point check
    • ECDSA and RSA signature verification through the SSH signature path, RSA from 2048 to 8192 bits
    • RSA signing (rsa-sha2-256 and rsa-sha2-512), from a PEM key to the signature
    • AES-GCM, ML-KEM-768 and ML-KEM-1024 decapsulation, and HMAC-SHA-256/512, with the parameters SSH uses

    Every vector gives the expected answer. Wycheproof keeps adding vectors as new bugs are found, so the copies in the repository are checked for updates from time to time and before each release; the fixtures' README says how.

  • Differential tests: the vectorized ChaCha20 (8 and 4 blocks at once) against the scalar code, for every length up to 2,000 bytes, long buffers, and counters that cross the 2^32 and 2^64 boundaries in every lane. The tests choose the path explicitly, so every path runs on every CI platform, whatever vector width its CPU has. Poly1305 with 64-bit limbs against the 26-bit code (which 32-bit processes use) and against the definition computed with BigInteger: random keys and messages of every length up to 1,100 bytes and long ones, the largest clamped r, accumulators just below and above p and 2^130, an s that carries out of 2^128, the final reduction on its own at the edges of its limb bounds, and every RFC 8439 Poly1305 vector. Both limb sizes run on every machine.

  • Constant-time review and a timing test: see the cryptography review.

Real servers

The interop tests run against real servers on every pull request. Each server catches something the others tolerate:

Server What it checks
OpenSSH on Linux (x64 and Arm64) Keys of every type and format, host and user certificates from a test CA, ssh-agent and agent forwarding, PAM keyboard-interactive, Kerberos (a throwaway realm), every key exchange, cipher and MAC, forwarding of every kind, SFTP and SCP, re-keying every 32 KiB
OpenSSH on Alpine 3.6, 3.13, 3.19, 3.22, 3.23 and edge Releases from several eras, from ones without strict key exchange (Terrapin) to the newest (10.2p1 on 3.23, 10.6p2 on edge)
OpenSSH for Windows ConPTY terminals, Windows paths, the Windows server's own behaviour, and SCP's DoubleQuote path quoting with cmd.exe as the default shell
Dropbear (two releases) A second C implementation, with its own limits and quirks
AsyncSSH An independent implementation in Python. It found that SFTP symbolic links were sent in the wrong argument order for servers that follow the SFTP draft
Apache MINA SSHD An independent implementation in Java, the server inside Jenkins, Gerrit and Eclipse. It answers keep-alive requests, reports a killed command as an exit status, and has no pseudo-terminal. It re-keys only when the client does: with a small limit of its own, MINA 2.20.0 sometimes failed sessions while both sides re-keyed
Erlang/OTP ssh An implementation known for following the RFCs strictly: the transport with every algorithm it offers, host keys, SFTP, forwarding and network faults (no shells or commands, which run Erlang there). Its SFTP server ignores a new file size and still answers OK
atmoz/sftp and a Go pkg/sftp server Chrooted, SFTP-only servers, the kind behind many hosted file-transfer services
ProFTPD mod_sftp A chrooted, SFTP-only server that is not OpenSSH, and the one that announces check-file, so the file hash test runs against it. It found that its check-file reply leaves out the extension's name, that it answers OK to creating a directory that exists (which made SkipUnchanged uploads send everything again), and that its LSTAT follows links. Its range hashes are wrong unless the length is a multiple of its read size, and it mixes up large writes over several sessions of one connection, so the segmented upload test skips there

A key-exchange volume test can run thousands of handshakes per host key type against a server. It is off by default: it is in the Handshakes category, which CI leaves out, and runs when selected with SSHSHARP_TEST_HANDSHAKES set to the number of handshakes per host key type.

The servers re-key on their own every 32 KiB (RekeyLimit 32K in OpenSSH, Linux and Windows, and rekey_bytes in AsyncSSH), so server-initiated key re-exchanges with data in flight are tested against them. Dropbear has no such setting, and Apache MINA SSHD keeps its default limit (see its row above).

ssh-audit checks what the client offers. In client mode it listens as a server, records the key exchanges, host keys, ciphers and MACs in SshSharp's first message, and rates each one. A CI job runs it on every pull request, once with the default options and once in FIPS mode. The job fails if:

  • any rating is not one of the few explained in the checker, such as ssh-audit's opinion of the NIST curves, which OpenSSH's client also offers;
  • ssh-audit lists a CVE;
  • strict key exchange (the Terrapin countermeasure) is missing;
  • the default list does not start with a post-quantum hybrid;
  • FIPS mode offers anything outside FIPS.

A weakened default list therefore fails at once.

Network faults

A fault-injection proxy sits between the client and a real server. It can:

  • cut the connection at once, or after a chosen number of bytes in either direction (in the middle of a packet)
  • stop forwarding in both directions, as a dead route does (no FIN, no RST: only keep-alive can tell)
  • stop forwarding in one direction only, so the peer seems to stop reading while the connection looks alive
  • add latency, limit the bandwidth, or deliver the data in tiny segments

A separate test kills the server's process for one session, as an administrator or the OOM killer would.

Every fault must end promptly with an SshException, never with a hang or another exception type, and disposing a client must always finish. A sweep cuts the connection at 13 points from the first byte to well past authentication, in each direction.

Fuzzing and mutation testing

  • Coverage-guided fuzzing (SharpFuzz and libFuzzer, nightly) of the parsers that read untrusted input. The targets are packets, the server's identification line, KEXINIT, public keys and signatures, certificates, private keys (text and binary), known_hosts, ssh_config, KRLs, SFTP replies and compressed packets (zlib@openssh.com). Each parser is also mutation-fuzzed briefly in every unit test run.

  • Mutation testing (Stryker.NET, weekly and on demand) over the cryptography, the packet codec, compression and the configuration parsers. A surviving mutant is a code change no test notices. The score is reported, not enforced. Each scope compiles only the tests that can reach its files, and slow tests stay out of the scopes they cannot help. When a test runs too long during coverage capture, Stryker runs it against every mutant, so the mutants that the fast tests miss time out instead of surviving, and a timeout counts as detected. The encrypted private key fuzz test is in a file of its own for this reason. The weekly run mutates only what changed in the last eight days, so its scores cover those files alone; a run started by hand mutates everything. The workflow runs on Linux, so code for Windows only is not scored there: its mutants are annotated, and the Windows test job exercises that code. A mutant that cannot change what any caller sees (wiping a buffer, a message, an allocation size) is annotated in the code with the reason, as // Stryker disable once <mutator> : <reason>. Code that kills processes (ProcessTree) checks each process a second time, in code left unmutated, just before it kills it: a mutant that selected every process killed Stryker and the CI runner with it, and the job ended with only "the runner lost communication".

    Timeouts overstate the scores. Stryker compiles a check into every mutated expression, and in hot code those checks cost far more than the code they guard: a tight arithmetic loop ran about 50 times slower. With the runner for Microsoft.Testing.Platform (a preview in Stryker.NET 5), each check also reads the active mutant from a memory-mapped file, which made it about 225 times slower. The time limit comes from a run without the checks. The managed cryptography's tests then time out whatever the mutant does, and Stryker counts each as detected. In the full run of October 2026:

    Scope Score Killed mutants alone
    sntrup761 100% 8.6%
    public-key, bcrypt-pbkdf, key-readers, userauth 97–100% 39–47%
    key-writers, identification, ecdh-dh 100% 62–64%

    The job summary prints both. The true score lies between them: some timeouts are real loops, and some mutants would survive. Raising the time limit would push the slowest scopes past the job's 340 minutes, so these scopes wait for a fix in Stryker (stryker-net#3915 for the mapped read, stryker-net#3904 for how timeouts are judged).

Stress testing and intermittent failures

A stress workflow runs the unit tests on every platform, and the interop tests against every server, in a loop (100 iterations per job for a release). It uses an instrumented build that:

  • tracks every pooled buffer and reports a buffer returned twice, with both stacks (the earlier one with method names only: formatting file and line numbers on every return slowed the build enough to change the timing it is there to observe)
  • checksums received data when it arrives, and checks it again when it is read and when it is released, so a buffer overwritten while queued is reported where it happens
  • records a bounded trace of relays and key exchanges, which a hung test includes in its failure message, together with the step it was stuck in

Intermittent failures are treated as bugs until shown otherwise. They are not retried away, and tests are not serialised to hide a race. The rule of thumb used: no failures in N runs bounds the failure rate below about 3/N with 95% confidence, so a failure seen once in 20 runs needs about 60 clean runs before it counts as gone. A failure is closed when its cause is understood, and ideally reproduced by a test.

Before 0.6.0 this hunt (#188) found, among others:

  • A real data race: disposing a session or tunnel while another task read it could hand the reader zeroed bytes. Found by the instrumented build's checksum report, reproduced by a test, and fixed.
  • A real hang: disposing a client could wait forever when the server had stopped reading in the middle of a write. Reproduced by a test that hung, and fixed.
  • Server-side failures, avoided in tests: OpenSSH for Windows drops some accepted connections under a burst of them, and its pipe close can deadlock. Both are reported with the server's own logs as evidence.
  • Flaws in the tests themselves: fixed waits, counters read without their lock, fake servers that spun a thread. These are fixed in the tests, not tolerated.

Test categories and skips

A test that cannot run where it is (no server, no tool, a platform without the feature) skips itself and says why. A skip passes, so CI checks that every skip is one it expects.

Categories

The test classes carry a TUnit [Category], and each CI job selects its tests by category:

Category What Where it runs
(none) Unit tests: fake servers, in-memory streams, no network The unit jobs, on every OS and target framework
LocalTools Key files read back by ssh-keygen, OpenSSL and puttygen, and encrypted key files those tools make (with passphrases generated per run) read by SshSharp; no server The unit jobs and the OpenSSH runner job. CI installs PuTTY's command-line puttygen on Linux and macOS; on Windows, PuTTY's puttygen.exe has only a window, so the .ppk tests skip there
Integration Tests against a real server (SSHSHARP_TEST_SSHD and the other SSHSHARP_TEST_* variables) The interop jobs
SshAudit The client audit; also Integration, but it needs ssh-audit listening, not an SSH server The audit job
WindowsCmd SCP's DoubleQuote path quoting against OpenSSH for Windows with cmd.exe as its default shell; also Integration. It needs SSHSHARP_TEST_SERVER_SHELL=cmd The last step of the OpenSSH for Windows job, after it switches the server's default shell from Git Bash to cmd.exe
Measure Measurements, not checks (SSHSHARP_MEASURE=1) Nowhere in CI; by hand
Handshakes The key-exchange volume test against a real server; also Integration. It needs SSHSHARP_TEST_HANDSHAKES (handshakes per host key type) Nowhere in CI; by hand, when hunting an intermittent key exchange failure

The selections, as TUnit tree filters (Microsoft.Testing.Platform's --treenode-filter):

Run Filter
Unit tests /*/*/*/*[(Category!=Integration)&(Category!=Measure)]
Interop tests /*/*/*/*[(Category=Integration)&(Category!=SshAudit)&(Category!=Measure)&(Category!=Handshakes)&(Category!=WindowsCmd)]
A measurement /*/*/*/*[Category=Measure], with SSHSHARP_MEASURE=1
The key-exchange volume test /*/*/TransportInteropTests/*[Category=Handshakes], with a server and, for example, SSHSHARP_TEST_HANDSHAKES=2000

A new test class that needs a real server gets [Category("Integration")]. Without it, the class runs in the unit jobs, where it skips, and the skip check fails the job.

Running them locally

Build once, then run the test assembly with a filter (dotnet test --project tests/SshSharp.Tests -f net10.0 --treenode-filter ... takes the same filters):

dotnet build tests/SshSharp.Tests -c Release
# the unit tests
dotnet tests/SshSharp.Tests/bin/Release/net10.0/SshSharp.Tests.dll --treenode-filter "/*/*/*/*[(Category!=Integration)&(Category!=Measure)]"
# the interop tests, against a server named by SSHSHARP_TEST_SSHD, SSHSHARP_TEST_USER and so on (without one they all skip)
dotnet tests/SshSharp.Tests/bin/Release/net10.0/SshSharp.Tests.dll --treenode-filter "/*/*/*/*[(Category=Integration)&(Category!=SshAudit)&(Category!=Measure)&(Category!=Handshakes)&(Category!=WindowsCmd)]"

Without a filter everything runs, and the Integration tests skip at once when no server is configured.

Expected skips

Each CI job lists the tests it may skip, in tests/ci/skips: one file per job, such as unit-ubuntu-latest-net8.0.txt or interop-dropbear-alpine-3.22.txt, with one Class.DisplayName per line. The jobs write a TRX report (--report-trx), and tests/ci/check-skips.ps1 compares its skips with the list:

  • a skip that is not on the list fails the job, naming the test and its reason;
  • a listed test that ran, or was not in the run, gives a notice, so the list can be tightened;
  • the job summary counts the skips by reason.

The lists hold only what a job cannot run: .NET 8 without ML-KEM or gssapi-with-mic, a Linux without ML-KEM in its OpenSSL, Windows without FIFOs or Unix file modes, servers without an algorithm, an extension or a key setup, and tools too old for a check: ssh-keygen reads Ed25519 PKCS#8 keys only from OpenSSH 9.8p1 on (9.6p1 has the code, but its build never turned it on), so KeyExportInteropTests.SshKeygen_ReadsPkcs8(Ed25519, ...) skips with Ubuntu 24.04's OpenSSH 9.6p1 and OpenSSH for Windows 9.5, and runs on macOS, where CI installs Homebrew's OpenSSH. A new skip is not added to a list until it is understood. A skip can hide a regression as well as a limit of the platform. A line starting with # in a list is a comment, for the reason behind an entry.

When a runner can be set up to run a test, CI sets it up rather than list the skip. For example, macOS configures only 127.0.0.1 on its loopback interface, so the macOS unit jobs add 127.0.0.2 as an alias for the BindAddress tests.

.NET's ML-KEM on Linux needs OpenSSL 3.5, and the Ubuntu 24.04 runners have 3.0, so the ML-KEM tests skip in the Linux jobs that run there. ubuntu-latest is Ubuntu 26.04, which has ML-KEM, so the container interop jobs also generate the mlkem768x25519-sha256 handshake; the servers too old to offer it skip it as not offered, and their lists name it. While a job may still land on either image, a listed test that is not in the run is only a notice. One more job (mlkem (Alpine 3.23)) runs them where they cannot skip. It runs the tests built on the runner in .NET's Alpine 3.23 container, which has OpenSSL 3.5: the unit test classes with ML-KEM tests, and the handshakes against OpenSSH 10.0, mlkem768x25519-sha256 among them. Its lists are empty, and the job also checks that the ML-KEM cases passed. The hybrid handshake is only generated where the platform has ML-KEM, so its absence would not show as a skip.

When a job's skips change on purpose, update its list. To regenerate one from a TRX report (the coverage-<os> artifact holds the unit jobs'), run the script with -Update and review the diff before committing it. It writes the skips only, so put back any comments:

pwsh tests/ci/check-skips.ps1 -Job "unit (ubuntu-latest) net10.0" -Trx TestResults/unit-net10.0.trx -Update

The file name comes from the job's name, in lower case, with anything but letters, digits and dots replaced by -.

Coverage

The unit tests alone cover about 95% of lines and 91% of branches, merged across the platforms. Code that only the interop tests exercise (real re-keys, forwarding, SFTP against real servers) is not counted yet. The target is 95%, reported but not enforced. scripts/coverage.ps1 writes the HTML report locally.

Coverage shows that code ran, not that it is right under concurrency. The races and hangs above were in covered code. The stress runs, the instrumented build and the fault tests are what found them.

Not covered yet

  • An independent audit of the managed cryptography. None has been done, and none is planned. It is checked against the reference vectors, Wycheproof, the timing tests and mutation testing (review).
  • Interop coverage in the coverage figure.
  • Commercial negative-testing suites (thousands of malformed messages against the client). Fuzzing covers the parsers, but not every message sequence.

See also the threat model and the design notes.