@@ -58,6 +58,7 @@ use tokio::sync::mpsc::{
5858use tokio:: sync:: oneshot;
5959
6060pub use crate :: auth:: AuthResult ;
61+ use crate :: cert:: PublicKeyOrCertificate ;
6162use crate :: channels:: {
6263 Channel , ChannelMsg , ChannelReadHalf , ChannelRef , ChannelWriteHalf , WindowSizeRef ,
6364} ;
@@ -1198,8 +1199,7 @@ impl Session {
11981199 // Keep reading the network for window adjustments, but leave
11991200 // application output in its bounded receivers while a channel is
12001201 // window-blocked.
1201- let can_receive_outbound =
1202- !self . kex . active ( ) && !self . common . has_any_pending_data ( ) ;
1202+ let can_receive_outbound = !self . kex . active ( ) && !self . common . has_any_pending_data ( ) ;
12031203 tokio:: select! {
12041204 r = & mut reading => {
12051205 let ( stream_read, mut buffer, mut opening_cipher) = match r {
@@ -1690,12 +1690,12 @@ async fn reply<H: Handler>(
16901690 // something the client was ever told to trust — asking
16911691 // about it as well would invite an implementation to
16921692 // answer yes to the wrong question.
1693- if let Some ( certificate) = & server_host_certificate {
1694- if !handler. check_server_certificate ( certificate) . await ? {
1693+ if let Some ( certificate) = server_host_certificate {
1694+ if !handler. check_server_key ( & certificate. into ( ) ) . await ? {
16951695 return Err ( crate :: Error :: UnknownKey . into ( ) ) ;
16961696 }
1697- } else if let Some ( server_host_key) = & server_host_key {
1698- let check = handler. check_server_key ( server_host_key) . await ?;
1697+ } else if let Some ( server_host_key) = server_host_key {
1698+ let check = handler. check_server_key ( & server_host_key. into ( ) ) . await ?;
16991699 if !check {
17001700 return Err ( crate :: Error :: UnknownKey . into ( ) ) ;
17011701 }
@@ -1754,7 +1754,7 @@ mod tests {
17541754 impl Handler for TestHandler {
17551755 type Error = crate :: Error ;
17561756
1757- async fn check_server_key ( & mut self , _: & ssh_key :: PublicKey ) -> Result < bool , Self :: Error > {
1757+ async fn check_server_key ( & mut self , _: & PublicKeyOrCertificate ) -> Result < bool , Self :: Error > {
17581758 Ok ( true )
17591759 }
17601760 }
@@ -2158,29 +2158,17 @@ pub trait Handler: Sized + Send {
21582158 async { Ok ( ( ) ) }
21592159 }
21602160
2161- /// Called to check the server's public key. This is a very important
2162- /// step to help prevent man-in-the-middle attacks. The default
2163- /// implementation rejects all keys.
2164- #[ allow( unused_variables) ]
2165- /// Called instead of [`Self::check_server_key`] when the server proved its
2166- /// identity with a certificate.
2161+ /// Called to check the server's public key or certificate.
2162+ /// This is a very important step to help prevent man-in-the-middle attacks.
2163+ /// The default implementation rejects all keys, and you must override it.
21672164 ///
2168- /// Defaults to refusing. A client that has not been taught which
2169- /// authorities it trusts cannot answer this question, and answering it
2170- /// wrongly accepts any machine whose operator can obtain a certificate from
2171- /// anyone at all — so silence has to mean no.
2172- #[ allow( unused_variables) ]
2173- fn check_server_certificate (
2174- & mut self ,
2175- certificate : & ssh_key:: Certificate ,
2176- ) -> impl std:: future:: Future < Output = Result < bool , Self :: Error > > + Send {
2177- async { Ok ( false ) }
2178- }
2179-
2165+ /// The library verifies the key exchange signature before this call,
2166+ /// but it's up to the implementation to decide whether the key or certificate
2167+ /// is trusted.
21802168 #[ allow( unused_variables) ]
21812169 fn check_server_key (
21822170 & mut self ,
2183- server_public_key : & ssh_key :: PublicKey ,
2171+ server_public_key : & PublicKeyOrCertificate ,
21842172 ) -> impl Future < Output = Result < bool , Self :: Error > > + Send {
21852173 async { Ok ( false ) }
21862174 }
0 commit comments