Skip to content

Add support for certificates in requests and responses#101

Open
wiktor-k wants to merge 4 commits intomainfrom
wiktor-k/fix-support-for-certs
Open

Add support for certificates in requests and responses#101
wiktor-k wants to merge 4 commits intomainfrom
wiktor-k/fix-support-for-certs

Conversation

@wiktor-k
Copy link
Owner

This is a replacement PR obsoleting #98 (thank for the PoC @sfriedenberg-etsy 🙏 ).

As it says, it adds support for parsing certificates and renames several fields for consistency. This should solve a long standing issue reported by @overhacked. If anyone can test it in the wild I'd be really happy. For some messages we don't have serializations (e.g. RemoveIdentity with certs) but I don't think this should block the change.

The implementation of decode_as looks ugly and should be replaced as soon as ssh-key 0.7 is released. In the meantime this should work using existing APIs.

wiktor-k and others added 4 commits March 19, 2026 12:08
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
See: #98
Co-authored-by: Sasha F <cornflake.matchbox397@icantbelieveitsnotgmail.com>
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
See: #98
Co-authored-by: Sasha F <cornflake.matchbox397@icantbelieveitsnotgmail.com>
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
Signed-off-by: Wiktor Kwapisiewicz <wiktor@metacode.biz>
@wiktor-k wiktor-k requested a review from overhacked March 19, 2026 11:11
@wiktor-k wiktor-k force-pushed the wiktor-k/fix-support-for-certs branch from 57390cb to 1f86f25 Compare March 19, 2026 11:12
Comment on lines +143 to +159
// FIXME: This needs to be rewritten using Certificate::decode_as when ssh-key 0.7.0 hits stable, see: https://github.com/wiktor-k/ssh-agent-lib/pull/85#issuecomment-3751946208
let alg = String::decode(reader)?;

let remaining_len = reader.remaining_len();
let mut buf = Vec::with_capacity(4 + alg.len() + remaining_len);
alg.encode(&mut buf)?;
let mut tail = vec![0u8; remaining_len];
reader.read(&mut tail)?;
buf.extend_from_slice(&tail);

if Algorithm::new_certificate(&alg).is_ok() {
let cert = Certificate::decode(&mut &buf[..])?;
Ok(Self::Cert(Box::new(cert)))
} else {
let key = KeyData::decode(&mut &buf[..])?;
Ok(Self::Key(key))
}
Copy link
Owner Author

@wiktor-k wiktor-k Mar 19, 2026

Choose a reason for hiding this comment

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

@baloo I have a feeling like this should belong somewhere in ssh-key itself. The detection of whether we have a cert or not and branching looks super ugly to me. It took me a while to browse Algorithm::new_certificate code to check if it will return Err on non-certificates rather than returning Other or something like this.

What do you think about it? 🤔

Edit: the problem here is that even if we first decode Algorithm it doesn't seem to have any indication if it's a certificate algorithm or not...

@wiktor-k wiktor-k requested a review from baloo March 19, 2026 11:13
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.

1 participant