@@ -11,7 +11,7 @@ use sha1::Sha1;
11
11
use ssh_agent_lib:: agent:: NamedPipeListener as Listener ;
12
12
use ssh_agent_lib:: agent:: Session ;
13
13
use ssh_agent_lib:: error:: AgentError ;
14
- use ssh_agent_lib:: proto:: extension:: SessionBind ;
14
+ use ssh_agent_lib:: proto:: extension:: { QueryResponse , RestrictDestination , SessionBind } ;
15
15
use ssh_agent_lib:: proto:: {
16
16
message, signature, AddIdentity , AddIdentityConstrained , AddSmartcardKeyConstrained ,
17
17
Credential , Extension , KeyConstraint , RemoveIdentity , SignRequest , SmartcardKey ,
@@ -151,12 +151,13 @@ impl Session for KeyStorage {
151
151
} = identity;
152
152
info ! ( "Would use these constraints: {constraints:#?}" ) ;
153
153
for constraint in constraints {
154
- if let KeyConstraint :: Extension ( name , mut details ) = constraint {
155
- if name == "restrict- destination-v00@openssh.com" {
156
- if let Ok ( destination_constraint ) = details . parse :: < SessionBind > ( ) {
157
- info ! ( "Destination constraint: {destination_constraint:?}" ) ;
158
- }
154
+ if let KeyConstraint :: Extension ( mut extension ) = constraint {
155
+ if let Some ( destination) =
156
+ extension . parse_key_constraint :: < RestrictDestination > ( ) ?
157
+ {
158
+ info ! ( "Destination constraint: {destination:?}" ) ;
159
159
}
160
+
160
161
if let Credential :: Key { privkey, comment } = identity. credential . clone ( ) {
161
162
let privkey = PrivateKey :: try_from ( privkey) . map_err ( AgentError :: other) ?;
162
163
self . identity_add ( Identity {
@@ -199,13 +200,28 @@ impl Session for KeyStorage {
199
200
Ok ( ( ) )
200
201
}
201
202
202
- async fn extension ( & mut self , mut extension : Extension ) -> Result < ( ) , AgentError > {
203
+ async fn extension (
204
+ & mut self ,
205
+ mut extension : Extension ,
206
+ ) -> Result < Option < Extension > , AgentError > {
203
207
info ! ( "Extension: {extension:?}" ) ;
204
- if extension. name == "session-bind@openssh.com" {
205
- let bind = extension. details . parse :: < SessionBind > ( ) ?;
206
- info ! ( "Bind: {bind:?}" ) ;
208
+
209
+ match extension. name . as_str ( ) {
210
+ "query" => {
211
+ let response = Extension :: new_message ( QueryResponse {
212
+ extensions : vec ! [ "query" . into( ) , "session-bind@openssh.com" . into( ) ] ,
213
+ } ) ?;
214
+ Ok ( Some ( response) )
215
+ }
216
+ "session-bind@openssh.com" => match extension. parse_message :: < SessionBind > ( ) ? {
217
+ Some ( bind) => {
218
+ info ! ( "Bind: {bind:?}" ) ;
219
+ Ok ( None )
220
+ }
221
+ None => Err ( AgentError :: Failure ) ,
222
+ } ,
223
+ _ => Err ( AgentError :: Failure ) ,
207
224
}
208
- Ok ( ( ) )
209
225
}
210
226
}
211
227
0 commit comments