{"article":{"slug":"adding-rsa-support-to-swift-nio-ssh","title":"Adding RSA Support to swift-nio-ssh","subtitle":null,"summary":"LogRaker's Thomas Gumz explains why the log viewer vendored a fork of Apple's swift-nio-ssh to add RSA key support (needed for older EC2 PKCS#1 key pairs), what it took given the library has no extension point, and the trade-offs of maintaining a security-relevant fork.","content_type":"blog_post","language":"en","canonical_url":"https://lograker.app/blog/swift-nio-ssh-rsa-support","author":{"name":"Thomas Gumz","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"LogRaker","url":"https://lograker.app/","listing_slug":null,"listing":null},"topics":[{"name":"swift","slug":"swift","url":"https://listedarticles.com/topics/swift"},{"name":"ssh","slug":"ssh","url":"https://listedarticles.com/topics/ssh"},{"name":"security","slug":"security","url":"https://listedarticles.com/topics/security"},{"name":"open-source","slug":"open-source","url":"https://listedarticles.com/topics/open-source"},{"name":"software-engineering","slug":"software-engineering","url":"https://listedarticles.com/topics/software-engineering"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":959,"reading_minutes":4,"published_at":"2026-09-21T00:00:00.000Z","added_at":"2026-11-13T05:13:59.727Z","updated_at":"2026-11-13T05:13:59.727Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/adding-rsa-support-to-swift-nio-ssh","markdown_url":"https://listedarticles.com/articles/adding-rsa-support-to-swift-nio-ssh.md","example":false,"citation":"Thomas Gumz, LogRaker. \"Adding RSA Support to swift-nio-ssh.\" 21 Sept 2026. https://lograker.app/blog/swift-nio-ssh-rsa-support (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://lograker.app/blog/swift-nio-ssh-rsa-support"},"body_markdown":"*By Thomas Gumz, LogRaker — 21 September 2026*\n\n# Adding RSA Support to swift-nio-ssh\n\nLogRaker talks SSH through [swift-nio-ssh](https://github.com/apple/swift-nio-ssh), which\nis a great library with one gap: it has no RSA support. That is\ndeliberate. Upstream supports modern primitives only, and for new\ndeployments the newer ed25519 format is the better default.\n\nIt is also not a choice you always get to make. Amazon EC2 hands out\nPKCS#1 RSA `.pem` key pairs, and only added ed25519 key pairs\nin 2021. Any key pair older than that is RSA, the instances it opens are\nstill running, and nothing about the situation is negotiable from the\nclient side. A log viewer that cannot use the key sitting in\n`~/.ssh/` is not useful.\n\nSo LogRaker vendored a fork. Here is what that actually took.\n\n## There is no extension point\n\nThe obvious move would be to add the key type from outside the\nmodule. Well, you can’t. `NIOSSHPrivateKey` stores its key in\nan internal enum:\n\n```\nextension NIOSSHPrivateKey {\n    internal enum BackingKey {\n        case ed25519(Curve25519.Signing.PrivateKey)\n        case ecdsaP256(P256.Signing.PrivateKey)\n        // ...\n    }\n}\n```\n\n`backingKey` is `internal`, the memberwise\n`init(backingKey:)` is `private`, and the only\npublic initializers are one per supported algorithm. There is no\nprotocol to conform to and no case to add. Adding an algorithm means\nediting the module, which means a new fork.\n\nEight files, in the end: `Package.swift` to pull in\n`_RSA.Signing` from swift-crypto’s `CryptoExtras`\nproduct (it is not in `Crypto`), five sources under\n`Sources/NIOSSH/`, and one upstream test that had to change,\nbecause it used `ssh-rsa` as its example of an algorithm\nnobody recognizes.\n\n## The trap: two different strings\n\nThis is the part worth reading even if you never touch nio-ssh.\n\nA `publickey` userauth request carries a public key blob\nand an *algorithm name*. For ed25519 and the ECDSA curves those\ntwo strings are identical, so upstream writes the key’s own tag into the\nalgorithm-name field and never has to think about it:\n\n```\nwrittenBytes += self.writeSSHString(key.keyPrefix)\n```\n\nRSA is the one algorithm where they differ. The key blob stays tagged\n`ssh-rsa`, but the algorithm name has to name the\n*signature* algorithm: `rsa-sha2-256` or\n`rsa-sha2-512`, from RFC 8332. The bare `ssh-rsa`\nname means RSA with SHA-1, which OpenSSH 8.8 disabled by default in\n2021. Offer that name to any current server and it is rejected outright,\nno matter how good your key is.\n\nSo the fork adds `signatureAlgorithmName` next to\n`keyPrefix`:\n\n```\ninternal var signatureAlgorithmName: String.UTF8View {\n    switch self.backingKey {\n    case .rsa:\n        return Self.rsaSHA512SignatureAlgorithm\n    case .ed25519, .ecdsaP256, .ecdsaP384, .ecdsaP521, .certified:\n        return self.keyPrefix\n    }\n}\n```\n\nThe subtlety is not the property. It is that the algorithm name gets\nwritten in **two** places, and they have to agree byte for\nbyte:\n\n- `SSHMessages.swift`, into the wire message.\n- `UserAuthSignablePayload.swift`, into the buffer that\n  gets signed.\n\nOne is what you claim, the other is what you sign. If they diverge,\nevery byte you send is individually well-formed, the key is correct, the\nsignature is a valid RSA signature, and yet the server rejects it\nanyway. There is no error message that points at the mismatch, because\nfrom the server’s side it is indistinguishable from a wrong key. This is\nthe kind of bug you find by writing out both buffers and diffing\nthem.\n\nA test now pins the two together, so the next person to touch either\nwrite site gets a failure instead of a mystery.\n\n## Which name to offer\n\nThe fork always offers `rsa-sha2-512` and does not\nnegotiate. That sounds lazy and is actually forced: nio-ssh does not\nparse `SSH_MSG_EXT_INFO`, so the `server-sig-algs`\nlist never reaches any code that could act on it. There is nothing to\nnegotiate against.\n\nIt is a safe default anyway. `rsa-sha2-512` has been\naccepted since OpenSSH 7.2, in 2016. Anything a log viewer realistically\nconnects to is newer than that.\n\nOne related detail, easy to miss: the fork’s list of known algorithms\nhas to carry the key tag *and* both signature algorithm names,\nbecause that list is checked against the algorithm-name field of\nincoming userauth requests and `PK_OK` replies. One key tag,\nseveral legal names.\n\n## Keeping the fork honest\n\nA vendored fork rots quietly. Three things keep this one\nreadable:\n\n**Every edit is marked.** Each hunk carries a\n`LOGRAKER FORK:` comment, so the whole diff against upstream\nis one grep:\n\n```\ngrep -rn \"LOGRAKER FORK\" Sources/ Tests/ Package.swift\n```\n\nThat is also the rebase checklist: fetch upstream, rebase onto the\nnew tag, and the markers show you which conflicts are yours.\n\n**One test is load-bearing.** The serialization test\ncompares the generated public-key blob byte for byte against what\n`ssh-keygen -y` prints for the same key. Hand-rolled SSH wire\nformat is exactly where a plausible-looking mistake survives review, and\nOpenSSH is the only opinion that counts.\n\n**Security advisories will not find you.** This is the\nreal cost of vendoring, and it has nothing to do with RSA. A local\nSwiftPM package never reports a new version, so no tool will ever tell\nyou that upstream shipped a fix. You have to go and look:\n\n```\ngh api repos/apple/swift-nio-ssh/security-advisories \\\n  --jq '.[] | \"\\(.severity) \\(.ghsa_id) \\(.summary)\"'\n```\n\nPut that somewhere you will actually run it.\n\n## Should you do this?\n\nProbably not, if you have a choice. Forking a security-relevant\nlibrary means you own its upstream fixes forever, and the honest summary\nof this fork is “we added an algorithm its authors chose to leave\nout”.\n\nBut the constraint was real: the keys exist, they are RSA, and they\nopen machines people need to watch. The fork touches eight files against\nupstream 0.15.0, every edit marked, and it can be deleted the day\nnio-ssh adds RSA support of its own.\n\nThe fork is public, at [lograker/swift-nio-ssh](https://github.com/lograker/swift-nio-ssh),\nApache 2.0 like upstream. Read its README before depending on it: it\nexists to serve one app, it is pinned to 0.15.0, and nobody has audited\nit.\n","body_html":"<p><em>By Thomas Gumz, LogRaker — 21 September 2026</em></p>\n<h1 id=\"adding-rsa-support-to-swift-nio-ssh\">Adding RSA Support to swift-nio-ssh</h1>\n<p>LogRaker talks SSH through <a href=\"https://github.com/apple/swift-nio-ssh\" rel=\"nofollow ugc noopener\">swift-nio-ssh</a>, which\nis a great library with one gap: it has no RSA support. That is\ndeliberate. Upstream supports modern primitives only, and for new\ndeployments the newer ed25519 format is the better default.</p>\n<p>It is also not a choice you always get to make. Amazon EC2 hands out\nPKCS#1 RSA <code>.pem</code> key pairs, and only added ed25519 key pairs\nin 2021. Any key pair older than that is RSA, the instances it opens are\nstill running, and nothing about the situation is negotiable from the\nclient side. A log viewer that cannot use the key sitting in\n<code>~/.ssh/</code> is not useful.</p>\n<p>So LogRaker vendored a fork. Here is what that actually took.</p>\n<h2 id=\"there-is-no-extension-point\">There is no extension point</h2>\n<p>The obvious move would be to add the key type from outside the\nmodule. Well, you can’t. <code>NIOSSHPrivateKey</code> stores its key in\nan internal enum:</p>\n<pre><code>extension NIOSSHPrivateKey {\n    internal enum BackingKey {\n        case ed25519(Curve25519.Signing.PrivateKey)\n        case ecdsaP256(P256.Signing.PrivateKey)\n        // ...\n    }\n}</code></pre>\n<p><code>backingKey</code> is <code>internal</code>, the memberwise\n<code>init(backingKey:)</code> is <code>private</code>, and the only\npublic initializers are one per supported algorithm. There is no\nprotocol to conform to and no case to add. Adding an algorithm means\nediting the module, which means a new fork.</p>\n<p>Eight files, in the end: <code>Package.swift</code> to pull in\n<code>_RSA.Signing</code> from swift-crypto’s <code>CryptoExtras</code>\nproduct (it is not in <code>Crypto</code>), five sources under\n<code>Sources/NIOSSH/</code>, and one upstream test that had to change,\nbecause it used <code>ssh-rsa</code> as its example of an algorithm\nnobody recognizes.</p>\n<h2 id=\"the-trap-two-different-strings\">The trap: two different strings</h2>\n<p>This is the part worth reading even if you never touch nio-ssh.</p>\n<p>A <code>publickey</code> userauth request carries a public key blob\nand an <em>algorithm name</em>. For ed25519 and the ECDSA curves those\ntwo strings are identical, so upstream writes the key’s own tag into the\nalgorithm-name field and never has to think about it:</p>\n<pre><code>writtenBytes += self.writeSSHString(key.keyPrefix)</code></pre>\n<p>RSA is the one algorithm where they differ. The key blob stays tagged\n<code>ssh-rsa</code>, but the algorithm name has to name the\n<em>signature</em> algorithm: <code>rsa-sha2-256</code> or\n<code>rsa-sha2-512</code>, from RFC 8332. The bare <code>ssh-rsa</code>\nname means RSA with SHA-1, which OpenSSH 8.8 disabled by default in</p>\n<ol start=\"2021\"><li><p>Offer that name to any current server and it is rejected outright,</p><p>no matter how good your key is.</p></li></ol>\n<p>So the fork adds <code>signatureAlgorithmName</code> next to\n<code>keyPrefix</code>:</p>\n<pre><code>internal var signatureAlgorithmName: String.UTF8View {\n    switch self.backingKey {\n    case .rsa:\n        return Self.rsaSHA512SignatureAlgorithm\n    case .ed25519, .ecdsaP256, .ecdsaP384, .ecdsaP521, .certified:\n        return self.keyPrefix\n    }\n}</code></pre>\n<p>The subtlety is not the property. It is that the algorithm name gets\nwritten in <strong>two</strong> places, and they have to agree byte for\nbyte:</p>\n<ul><li><code>SSHMessages.swift</code>, into the wire message.</li><li><p><code>UserAuthSignablePayload.swift</code>, into the buffer that</p><p>gets signed.</p></li></ul>\n<p>One is what you claim, the other is what you sign. If they diverge,\nevery byte you send is individually well-formed, the key is correct, the\nsignature is a valid RSA signature, and yet the server rejects it\nanyway. There is no error message that points at the mismatch, because\nfrom the server’s side it is indistinguishable from a wrong key. This is\nthe kind of bug you find by writing out both buffers and diffing\nthem.</p>\n<p>A test now pins the two together, so the next person to touch either\nwrite site gets a failure instead of a mystery.</p>\n<h2 id=\"which-name-to-offer\">Which name to offer</h2>\n<p>The fork always offers <code>rsa-sha2-512</code> and does not\nnegotiate. That sounds lazy and is actually forced: nio-ssh does not\nparse <code>SSH_MSG_EXT_INFO</code>, so the <code>server-sig-algs</code>\nlist never reaches any code that could act on it. There is nothing to\nnegotiate against.</p>\n<p>It is a safe default anyway. <code>rsa-sha2-512</code> has been\naccepted since OpenSSH 7.2, in 2016. Anything a log viewer realistically\nconnects to is newer than that.</p>\n<p>One related detail, easy to miss: the fork’s list of known algorithms\nhas to carry the key tag <em>and</em> both signature algorithm names,\nbecause that list is checked against the algorithm-name field of\nincoming userauth requests and <code>PK_OK</code> replies. One key tag,\nseveral legal names.</p>\n<h2 id=\"keeping-the-fork-honest\">Keeping the fork honest</h2>\n<p>A vendored fork rots quietly. Three things keep this one\nreadable:</p>\n<p><strong>Every edit is marked.</strong> Each hunk carries a\n<code>LOGRAKER FORK:</code> comment, so the whole diff against upstream\nis one grep:</p>\n<pre><code>grep -rn &quot;LOGRAKER FORK&quot; Sources/ Tests/ Package.swift</code></pre>\n<p>That is also the rebase checklist: fetch upstream, rebase onto the\nnew tag, and the markers show you which conflicts are yours.</p>\n<p><strong>One test is load-bearing.</strong> The serialization test\ncompares the generated public-key blob byte for byte against what\n<code>ssh-keygen -y</code> prints for the same key. Hand-rolled SSH wire\nformat is exactly where a plausible-looking mistake survives review, and\nOpenSSH is the only opinion that counts.</p>\n<p><strong>Security advisories will not find you.</strong> This is the\nreal cost of vendoring, and it has nothing to do with RSA. A local\nSwiftPM package never reports a new version, so no tool will ever tell\nyou that upstream shipped a fix. You have to go and look:</p>\n<pre><code>gh api repos/apple/swift-nio-ssh/security-advisories \\\n  --jq &#39;.[] | &quot;\\(.severity) \\(.ghsa_id) \\(.summary)&quot;&#39;</code></pre>\n<p>Put that somewhere you will actually run it.</p>\n<h2 id=\"should-you-do-this\">Should you do this?</h2>\n<p>Probably not, if you have a choice. Forking a security-relevant\nlibrary means you own its upstream fixes forever, and the honest summary\nof this fork is “we added an algorithm its authors chose to leave\nout”.</p>\n<p>But the constraint was real: the keys exist, they are RSA, and they\nopen machines people need to watch. The fork touches eight files against\nupstream 0.15.0, every edit marked, and it can be deleted the day\nnio-ssh adds RSA support of its own.</p>\n<p>The fork is public, at <a href=\"https://github.com/lograker/swift-nio-ssh\" rel=\"nofollow ugc noopener\">lograker/swift-nio-ssh</a>,\nApache 2.0 like upstream. Read its README before depending on it: it\nexists to serve one app, it is pinned to 0.15.0, and nobody has audited\nit.</p>","headings":[{"level":1,"text":"Adding RSA Support to swift-nio-ssh","id":"adding-rsa-support-to-swift-nio-ssh"},{"level":2,"text":"There is no extension point","id":"there-is-no-extension-point"},{"level":2,"text":"The trap: two different strings","id":"the-trap-two-different-strings"},{"level":2,"text":"Which name to offer","id":"which-name-to-offer"},{"level":2,"text":"Keeping the fork honest","id":"keeping-the-fork-honest"},{"level":2,"text":"Should you do this?","id":"should-you-do-this"}]}}