Skip to content

Restrict agent signing path#128

Merged
kruton merged 2 commits into
mainfrom
feature/agent-restrict
Apr 29, 2026
Merged

Restrict agent signing path#128
kruton merged 2 commits into
mainfrom
feature/agent-restrict

Conversation

@kruton
Copy link
Copy Markdown
Member

@kruton kruton commented Apr 29, 2026

No description provided.

kruton added 2 commits April 20, 2026 07:33
Implements OpenSSH 8.9+ agent restriction protocol per
https://www.openssh.org/agent-restrict.html

Add support for publickey-hostbound-v00@openssh.com as well as agent key
use constraints.

Start advertising "ext-info-c" in the kex.
Parse server-sig-algs from SSH_MSG_EXT_INFO and use it to select the best
RSA signing algorithm (rsa-sha2-512 > rsa-sha2-256 > ssh-rsa) when the server
advertises the extension. Falls back to the key's default when server-sig-algs
is absent, preserving current behavior for non-EXT_INFO servers.
Copilot AI review requested due to automatic review settings April 29, 2026 07:14
@kruton kruton force-pushed the feature/agent-restrict branch from 763687a to 9da4156 Compare April 29, 2026 07:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for OpenSSH agent destination constraints / host-bound publickey auth and strengthens key-material lifecycle management to better restrict where agent signatures can be used.

Changes:

  • Add parsing/handling for SSH_MSG_EXT_INFO (server-sig-algs, publickey-hostbound@openssh.com) and negotiate RSA signature algorithm accordingly.
  • Implement agent-side destination constraint enforcement and session-bind verification plumbing, with new unit/integration tests.
  • Add zeroization/destroy hooks across KEX + packet crypto and wipe transient key material after use.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
sshlib/src/test/resources/openssh-server/Dockerfile Expands OpenSSH test server config to permit ssh-rsa pubkeys for compatibility testing.
sshlib/src/test/kotlin/org/connectbot/sshlib/crypto/AlgorithmsTest.kt Adds unit tests for RSA signature algorithm negotiation.
sshlib/src/test/kotlin/org/connectbot/sshlib/client/SshClientIntegrationTest.kt Adds integration coverage for ssh-rsa-only servers and default rsa-sha2 negotiation.
sshlib/src/test/kotlin/org/connectbot/sshlib/HostBoundSignatureDataTest.kt Adds tests for host-bound signature-data encoding/parsing.
sshlib/src/test/kotlin/org/connectbot/sshlib/ExtInfoProcessingTest.kt Adds tests for EXT_INFO parsing of host-bound + server-sig-algs.
sshlib/src/test/kotlin/org/connectbot/sshlib/AgentProtocolTest.kt Updates agent protocol tests to cover bind verification + forwarding bind behavior.
sshlib/src/test/kotlin/org/connectbot/sshlib/AgentDestinationConstraintTest.kt Adds tests for restrict-destination constraint enforcement and identity visibility.
sshlib/src/main/kotlin/org/connectbot/sshlib/transport/PacketIO.kt Destroys old cipher/MAC/AEAD instances when switching encryption modes.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/RsaSignatureAlgorithm.kt Correctly maps ssh-rsa to SHA1withRSA and centralizes mapping logic.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/PacketMac.kt Makes MACs destroyable for key zeroization.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/PacketCipher.kt Makes ciphers destroyable for key zeroization.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/PacketAead.kt Makes AEADs destroyable for key zeroization.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/MlKemHybridKeyExchange.kt Adds private key zeroization.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/KeyDerivation.kt Adds key/IV zeroization and clears intermediate digest material.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/KexAlgorithm.kt Adds zeroize() contract for KEX implementations.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/HmacSha512.kt Zeroizes MAC key on destroy.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/HmacSha256.kt Zeroizes MAC key on destroy.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/HmacSha1.kt Zeroizes MAC key on destroy.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/EcdhKeyExchange.kt Destroys private key material after KEX.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/DiffieHellmanGroupExchange.kt Clears DH-GEX private parameters and adds zeroize().
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/DiffieHellman.kt Clears DH private key and adds zeroize().
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/Curve25519KeyExchange.kt Adds private key zeroization.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/ChaCha20Poly1305Cipher.kt Stores key for destroy-time wiping and implements destroy().
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/Algorithms.kt Adds ext-info-c to default KEX list and RSA signature negotiation helper.
sshlib/src/main/kotlin/org/connectbot/sshlib/crypto/AesGcmCipher.kt Stores key material for destroy-time wiping and implements destroy().
sshlib/src/main/kotlin/org/connectbot/sshlib/client/SshConnection.kt Adds EXT_INFO parsing, host-bound auth request support, RSA algorithm negotiation, and post-KEX zeroization.
sshlib/src/main/kotlin/org/connectbot/sshlib/client/AgentProtocolHandler.kt Implements destination constraint filtering/enforcement and session-bind verification hooks.
sshlib/src/main/kotlin/org/connectbot/sshlib/AgentProvider.kt Extends agent identity API to carry destination constraints and adds constraint model types.
sshlib/api.txt Updates public API surface for new AgentIdentity parameter + new model types.
protocol/src/main/resources/kaitai/userauth_request_publickey_hostbound.ksy Adds Kaitai schema for host-bound publickey auth request fields.
protocol/src/main/resources/kaitai/userauth_publickey_signature_data_any.ksy Adds Kaitai schema to parse both standard and host-bound signature data.
protocol/src/main/resources/kaitai/userauth_publickey_hostbound_signature_data.ksy Adds Kaitai schema for host-bound signature data construction/parsing.
protocol/src/main/resources/kaitai/ssh_msg_userauth_request.ksy Adds method switch case for host-bound publickey auth.
protocol/src/main/resources/kaitai/restrict_destination_constraint.ksy Adds Kaitai schema for restrict-destination agent key constraints.
.gitignore Ignores .worktrees/.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sshlib/src/main/kotlin/org/connectbot/sshlib/AgentProvider.kt

import io.kaitai.struct.ByteBufferKaitaiStream
import org.connectbot.sshlib.protocol.UserauthPublickeyHostboundSignatureData
import org.connectbot.sshlib.protocol.createAsciiString
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import: createAsciiString is imported but never used. This will fail ktlint/spotless checks (no-unused-imports). Remove the unused import.

Suggested change
import org.connectbot.sshlib.protocol.createAsciiString

Copilot uses AI. Check for mistakes.
@kruton kruton merged commit 0622ca7 into main Apr 29, 2026
8 checks passed
@kruton kruton deleted the feature/agent-restrict branch April 29, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants