#[tokio::main]
async fn main() {
let socket = tokio::net::TcpStream::connect(("localhost", 2222)).await
.expect("Could not open a TCP socket");
let config = makiko::ClientConfig::default();
let (client, mut client_rx, client_fut) = makiko::Client::open(socket, config)
.expect("Could not open client");
tokio::task::spawn(async move {
client_fut.await.expect("Error in client future");
});
tokio::task::spawn(async move {
loop {
let event = client_rx.recv().await
.expect("Error while receiving client event");
let Some(event) = event else {
break
};
match event {
makiko::ClientEvent::ServerPubkey(pubkey, accept) => {
println!("Server pubkey type {}, fingerprint {}", pubkey.type_str(), pubkey.fingerprint());
accept.accept();
},
_ => {},
}
}
});
let auth_res = client.auth_password("alice".into(), "alicealice".into()).await
.expect("Error when trying to authenticate");
match auth_res {
makiko::AuthPasswordResult::Success => {
println!("We have successfully authenticated using a password");
},
makiko::AuthPasswordResult::ChangePassword(prompt) => {
panic!("The server asks us to change password: {:?}", prompt);
},
makiko::AuthPasswordResult::Failure(failure) => {
panic!("The server rejected authentication: {:?}", failure);
}
}
}