pub struct SshKey { /* private fields */ }
Expand description
Represents the public key provided by the remote host
Implementations§
Source§impl SshKey
impl SshKey
Sourcepub fn get_public_key_hash(
&self,
hash_type: PublicKeyHashType,
) -> SshResult<Vec<u8>>
pub fn get_public_key_hash( &self, hash_type: PublicKeyHashType, ) -> SshResult<Vec<u8>>
Returns the public key hash in the requested format. The hash is returned as binary bytes. Consider using get_public_key_hash_hexa to return it in a more human readable format.
Sourcepub fn get_public_key_hash_hexa(
&self,
hash_type: PublicKeyHashType,
) -> SshResult<String>
pub fn get_public_key_hash_hexa( &self, hash_type: PublicKeyHashType, ) -> SshResult<String>
Returns the public key hash in a human readable form
Examples found in repository?
examples/whoami.rs (line 7)
4fn verify_known_hosts(sess: &Session) -> SshResult<()> {
5 let key = sess
6 .get_server_public_key()?
7 .get_public_key_hash_hexa(PublicKeyHashType::Sha256)?;
8
9 match sess.is_known_server()? {
10 KnownHosts::Ok => Ok(()),
11 KnownHosts::NotFound | KnownHosts::Unknown => {
12 eprintln!("The server is not a known host. Do you trust the host key?");
13 eprintln!("Public key hash: {}", key);
14
15 let input = prompt_stdin("Enter yes to trust the key: ")?;
16 if input == "yes" {
17 sess.update_known_hosts_file()
18 } else {
19 Err(Error::Fatal("untrusted server".to_string()))
20 }
21 }
22 KnownHosts::Changed => {
23 eprintln!("The key for the server has changed. It is now:");
24 eprintln!("{}", key);
25 Err(Error::Fatal("host key changed".to_string()))
26 }
27 KnownHosts::Other => {
28 eprintln!("The host key for this server was not found, but another");
29 eprintln!("type of key exists. An attacker might change the default");
30 eprintln!("server key to confuse your client into thinking the key");
31 eprintln!("does not exist");
32 Err(Error::Fatal("host key has wrong type".to_string()))
33 }
34 }
35}
pub fn from_privkey_base64( b64_key: &str, passphrase: Option<&str>, ) -> SshResult<SshKey>
pub fn from_privkey_file( filename: &str, passphrase: Option<&str>, ) -> SshResult<SshKey>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SshKey
impl RefUnwindSafe for SshKey
impl !Send for SshKey
impl !Sync for SshKey
impl Unpin for SshKey
impl UnwindSafe for SshKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more