Crate thrussh_keys [−] [src]
This crate contains methods to deal with SSH keys, as defined in crate Thrussh. This includes in particular various functions for opening key files, deciphering encrypted keys, and dealing with agents.
The following example shows how to do all these in a single
example: start and SSH agent server, connect to it with a client,
decipher an encrypted private key (the password is b"blabla"
),
send it to the agent, and ask the agent to sign a piece of data
(`b"I'd like this to be signed", below).
extern crate thrussh_keys; extern crate futures; extern crate tempdir; extern crate tokio_uds; extern crate tokio_core; use thrussh_keys::agent; use futures::Future; fn main() { let dir = tempdir::TempDir::new("thrussh").unwrap(); let agent_path = dir.path().join("agent"); let pkcs8_encrypted = "-----BEGIN ENCRYPTED PRIVATE KEY----- MIIFLTBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQITo1O0b8YrS0CAggA MAwGCCqGSIb3DQIJBQAwHQYJYIZIAWUDBAEqBBBtLH4T1KOfo1GGr7salhR8BIIE 0KN9ednYwcTGSX3hg7fROhTw7JAJ1D4IdT1fsoGeNu2BFuIgF3cthGHe6S5zceI2 MpkfwvHbsOlDFWMUIAb/VY8/iYxhNmd5J6NStMYRC9NC0fVzOmrJqE1wITqxtORx IkzqkgFUbaaiFFQPepsh5CvQfAgGEWV329SsTOKIgyTj97RxfZIKA+TR5J5g2dJY j346SvHhSxJ4Jc0asccgMb0HGh9UUDzDSql0OIdbnZW5KzYJPOx+aDqnpbz7UzY/ P8N0w/pEiGmkdkNyvGsdttcjFpOWlLnLDhtLx8dDwi/sbEYHtpMzsYC9jPn3hnds TcotqjoSZ31O6rJD4z18FOQb4iZs3MohwEdDd9XKblTfYKM62aQJWH6cVQcg+1C7 jX9l2wmyK26Tkkl5Qg/qSfzrCveke5muZgZkFwL0GCcgPJ8RixSB4GOdSMa/hAMU kvFAtoV2GluIgmSe1pG5cNMhurxM1dPPf4WnD+9hkFFSsMkTAuxDZIdDk3FA8zof Yhv0ZTfvT6V+vgH3Hv7Tqcxomy5Qr3tj5vvAqqDU6k7fC4FvkxDh2mG5ovWvc4Nb Xv8sed0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PTED PRIVATE KEY-----"; let mut core = tokio_core::reactor::Core::new().unwrap(); let h = core.handle(); let listener = tokio_uds::UnixListener::bind(&agent_path, &h).unwrap().incoming(); h.spawn(agent::server::AgentServer::new(listener, core.handle(), ()).map_err(|e| eprintln!("{:?}", e))); let key = thrussh_keys::decode_secret_key(pkcs8_encrypted, Some(b"blabla")).unwrap(); let public = key.clone_public_key(); let h = core.handle(); let stream = tokio_uds::UnixStream::connect(&agent_path, &h).unwrap(); core.run( agent::client::AgentClient::connect(stream) .add_identity(&key, &[agent::Constraint::KeyLifetime { seconds: 60 }]).and_then(|(client, _)| { client.request_identities().and_then(|(client, _id)| { client.sign_request(&public, b"I'd like this to be signed").and_then(|(_, sig)| { sig.unwrap(); futures::finished(()) }) }) }) ).unwrap(); }
Modules
agent |
A module to write SSH agent. |
Structs
Error |
The Error type. |
Enums
Encryption |
AES encryption key. |
ErrorKind |
The kind of an error. |
Traits
ResultExt |
Additional methods for |
Functions
check_known_hosts |
Check whether the host is known, from its standard location. |
check_known_hosts_path |
Check that a server key matches the one recorded in file |
decode_openssh |
Decode a secret key given in the OpenSSH format, deciphering it if needed using the supplied password. |
decode_pkcs5 |
Decode a secret key in the PKCS#5 format, possible deciphering it using the supplied password. |
decode_pkcs8 |
Decode a PKCS#8-encoded private key. |
decode_secret_key |
Decode a secret key, possibly deciphering it with the supplied password. |
encode_pkcs8 |
Encode a Decode a PKCS#8-encoded private key. |
encode_pkcs8_encrypted |
Encode a password-protected PKCS#8-encoded private key. |
learn_known_hosts |
Record a host's public key into the user's known_hosts file. |
learn_known_hosts_path |
Record a host's public key into a nonstandard location. |
load_public_key |
Load a public key from a file. Ed25519 and RSA keys are supported. |
load_secret_key |
Load a secret key, deciphering it with the supplied password if necessary. |
parse_public_key_base64 |
Reads a public key from the standard encoding. In some cases, the
encoding is prefixed with a key type identifier and a space (such
as |
write_public_key_base64 |
Write a public key onto the provided |
Type Definitions
Result |
Convenient wrapper around |