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)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
fn verify_known_hosts(sess: &Session) -> SshResult<()> {
let key = sess
.get_server_public_key()?
.get_public_key_hash_hexa(PublicKeyHashType::Sha256)?;
match sess.is_known_server()? {
KnownHosts::Ok => Ok(()),
KnownHosts::NotFound | KnownHosts::Unknown => {
eprintln!("The server is not a known host. Do you trust the host key?");
eprintln!("Public key hash: {}", key);
let input = prompt_stdin("Enter yes to trust the key: ")?;
if input == "yes" {
sess.update_known_hosts_file()
} else {
Err(Error::Fatal("untrusted server".to_string()))
}
}
KnownHosts::Changed => {
eprintln!("The key for the server has changed. It is now:");
eprintln!("{}", key);
Err(Error::Fatal("host key changed".to_string()))
}
KnownHosts::Other => {
eprintln!("The host key for this server was not found, but another");
eprintln!("type of key exists. An attacker might change the default");
eprintln!("server key to confuse your client into thinking the key");
eprintln!("does not exist");
Err(Error::Fatal("host key has wrong type".to_string()))
}
}
}
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 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