Skip to content

Advertise OpenSSH certificate support in host key algorithms#226

Open
jeffellin wants to merge 2 commits intoapple:mainfrom
jeffellin:fix/advertise-certificate-algorithms
Open

Advertise OpenSSH certificate support in host key algorithms#226
jeffellin wants to merge 2 commits intoapple:mainfrom
jeffellin:fix/advertise-certificate-algorithms

Conversation

@jeffellin
Copy link
Copy Markdown

Advertise OpenSSH certificate support in host key algorithms

Fixes #225

Summary

This PR enables NIOSSH to advertise support for OpenSSH certificates during key exchange and user authentication. While NIOSSH has always been able to parse and use OpenSSH certificates, it was not advertising the certificate algorithm names (ssh-*-cert-v01@openssh.com), causing SSH servers to reject certificate-based authentication.

Changes

Modified Files

Sources/NIOSSH/Keys And Signatures/NIOSSHPrivateKey.swift (lines 62-77)

  • Updated hostKeyAlgorithms to return both certificate and base algorithm names for each key type
  • Each key type now advertises two algorithms: certificate variant first, then base algorithm
  • Example: Ed25519 keys now advertise ["ssh-ed25519-cert-v01@openssh.com", "ssh-ed25519"]

Tests/NIOSSHTests/SSHKeyExchangeStateMachineTests.swift (lines 890, 941)

  • Updated testKeyExchangeDifferentPriorityBetweenServerAndClient to expect 4 algorithms (2 keys × 2 algorithms each)
  • Changed from .first to .last to access base algorithm name instead of certificate variant

Motivation

During SSH protocol negotiation, clients must advertise all supported public key algorithms in the SSH_MSG_KEXINIT message. NIOSSH was only advertising base algorithm names (e.g., ssh-ed25519, ecdsa-sha2-nistp256) and omitting certificate algorithm names (e.g., ssh-ed25519-cert-v01@openssh.com).

This prevented certificate-based authentication from working even though NIOSSH has full support for parsing and using OpenSSH certificates. SSH servers would reject certificate authentication because the client never advertised certificate algorithm support.

This change matches OpenSSH client behavior, which advertises both certificate and base algorithms for all supported key types.

Impact

Enables certificate authentication with:

  • Enterprise SSH servers requiring certificate authentication
  • Bastion hosts and jump boxes using certificates
  • Zero-trust architectures using short-lived certificates
  • Cloud providers requiring certificate authentication

Maintains backward compatibility:

  • Servers that don't support certificates will use base algorithm names
  • Existing non-certificate authentication continues to work unchanged
  • No API changes or breaking changes

Testing

  • All existing tests pass (320 tests)
  • Updated testKeyExchangeDifferentPriorityBetweenServerAndClient to reflect doubled algorithm count
  • Certificate authentication can be verified by connecting to SSH servers with certificate requirements

References

  • RFC 4252 Section 7: Public Key Authentication Method
  • RFC 4250 Section 4.6.1: Naming conventions for extensions
  • OpenSSH PROTOCOL.certkeys: Certificate format specification
  • Existing code: NIOSSHCertifiedPublicKey.swift lines 344-350 (defines cert algorithm names)

Motivation:

NIOSSH supports OpenSSH certificates (ssh-*-cert-v01@openssh.com) for
authentication but fails to advertise these algorithm names during key
exchange and user authentication. This causes SSH servers to reject
certificate-based authentication even though NIOSSH can correctly parse
and use certificates.

During SSH protocol negotiation, clients must advertise all supported
public key algorithms. NIOSSH was only advertising base algorithm names
(ssh-ed25519, ecdsa-sha2-nistp256, etc.) and omitting certificate
algorithm names (*-cert-v01@openssh.com), making certificate
authentication impossible.

Modifications:

- NIOSSHPrivateKey.hostKeyAlgorithms: Include both certificate and base
  algorithm names for each key type (e.g., ["ssh-ed25519-cert-v01@openssh.com",
  "ssh-ed25519"])
- Update SSHKeyExchangeStateMachineTests to account for doubled algorithm
  count (cert + base per key type)

This matches OpenSSH client behavior which advertises both certificate
and base algorithms for all supported key types.

Result:

NIOSSH can now successfully use OpenSSH certificates for authentication.
Servers that require certificate authentication will see the certificate
algorithm names advertised and accept cert-based auth. Servers that don't
support certificates will continue using base algorithms. This enables
certificate-based authentication with enterprise SSH servers, bastion
hosts, and zero-trust architectures.
@jeffellin jeffellin marked this pull request as draft February 17, 2026 18:07
Complete the certificate advertising fix by updating the client-side
host key algorithm list used during SSH key exchange negotiation.

The previous commit updated NIOSSHPrivateKey.hostKeyAlgorithms which
is used by SSH servers. However, SSH clients use a separate static
array (supportedServerHostKeyAlgorithms) during KEXINIT negotiation.

Without this fix, clients advertise only base algorithms:
  [ssh-ed25519, ecdsa-sha2-nistp256, ...]

With this fix, clients advertise both certificate and base algorithms:
  [ssh-ed25519-cert-v01@openssh.com, ssh-ed25519,
   ecdsa-sha2-nistp256-cert-v01@openssh.com, ecdsa-sha2-nistp256, ...]

This allows successful key exchange with servers that require or prefer
OpenSSH certificates for authentication.

Fixes the error:
  "no common algorithm for host key; we offered: [cert algorithms],
   peer offered: [base algorithms only]"
@jeffellin jeffellin marked this pull request as ready for review February 17, 2026 18:16
@gjcairo gjcairo added the 🔨 semver/patch No public API change. label Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NIOSSH doesn't advertise OpenSSH certificate support in public key algorithms

2 participants