Skip to content

Commit f86245b

Browse files
committed
Fix parsing RestrictDestination constraint
Signed-off-by: Wiktor Kwapisiewicz <[email protected]>
1 parent 6c400d6 commit f86245b

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

examples/key_storage.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use sha1::Sha1;
1111
#[cfg(windows)]
1212
use ssh_agent_lib::agent::NamedPipeListener as Listener;
1313
use ssh_agent_lib::agent::{Agent, Session};
14-
use ssh_agent_lib::proto::extension::SessionBind;
14+
use ssh_agent_lib::proto::extension::{RestrictDestination, SessionBind};
1515
use ssh_agent_lib::proto::message::{self, Credential, Message, SignRequest};
1616
use ssh_agent_lib::proto::{signature, AddIdentityConstrained, KeyConstraint};
1717
use ssh_key::{
@@ -144,9 +144,10 @@ impl KeyStorage {
144144
for constraint in constraints {
145145
if let KeyConstraint::Extension(name, mut details) = constraint {
146146
if name == "[email protected]" {
147-
if let Ok(destination_constraint) = details.parse::<SessionBind>() {
148-
eprintln!("Destination constraint: {destination_constraint:?}");
149-
}
147+
let destination_constraint = details
148+
.parse::<RestrictDestination>()
149+
.expect("to parse destination constraint");
150+
eprintln!("Destination constraint: {destination_constraint:?}");
150151
}
151152
}
152153
}

src/proto/extension.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ mod tests {
205205
[0, 0, 0, 0], // reserved, not in the spec, authfd.c:495
206206
);
207207

208+
let destination_constraint = RestrictDestination::decode(&mut buffer)?;
209+
eprintln!("Destination constraint: {destination_constraint:?}");
210+
211+
let mut buffer: &[u8] = &[
212+
0, 0, 0, 102, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 78, 0, 0, 0, 0,
213+
0, 0, 0, 10, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 0, 0, 0, 0, 0, 0, 0, 51, 0,
214+
0, 0, 11, 115, 115, 104, 45, 101, 100, 50, 53, 53, 49, 57, 0, 0, 0, 32, 227, 42, 170,
215+
121, 21, 206, 185, 180, 73, 209, 186, 80, 234, 42, 40, 187, 26, 110, 1, 249, 11, 218,
216+
36, 90, 45, 29, 135, 105, 125, 24, 162, 101, 0, 0, 0, 0, 0,
217+
];
208218
let destination_constraint = RestrictDestination::decode(&mut buffer)?;
209219
eprintln!("Destination constraint: {destination_constraint:?}");
210220
Ok(())

tests/known_hosts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl

tests/sign-and-verify.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ echo | ssh-keygen -f ca_user_key
4040
ssh-keygen -t rsa -f id_rsa -N ""
4141
echo | ssh-keygen -s ca_user_key -I darren -n darren -V +1h -z 1 id_rsa.pub
4242
# Add the key with the cert
43-
ssh-add -t 2 id_rsa
44-
43+
if [ $(ssh-add -h 2>&1 | grep -ic hostkey_file) -eq 1 ]; then
44+
# has support for RestrictDestination constraint (ubuntu)
45+
ssh-add -t 2 -H tests/known_hosts -h github.com id_rsa
46+
else
47+
# does not support RestrictDestination constraint (macos)
48+
ssh-add -t 2 id_rsa
49+
fi
50+
4551
# clean up the only leftover
4652
rm -rf id_rsa id_rsa.pub id_rsa-cert.pub ca_user_key ca_user_key.pub

0 commit comments

Comments
 (0)