use std::io::Write;
use takproto::{TakClient, TlsConfigBuilder};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<String> = std::env::args().collect();
if args.len() < 5 {
eprintln!(
"Usage: {} <server:port> <server_name> <p12_file> <password>",
args[0]
);
std::process::exit(1);
}
let server_addr = &args[1];
let server_name = &args[2];
let p12_file = &args[3];
let password = &args[4];
println!("Loading P12...");
let tls_config = TlsConfigBuilder::new()
.with_p12(p12_file, password)?
.danger_accept_invalid_certs(true)
.build()?;
println!("✓ TLS config created\n");
println!("Connecting to {}...", server_addr);
let mut client = TakClient::connect_tls(server_addr, server_name, tls_config).await?;
println!("✓ Connected - TLS handshake complete\n");
println!("Waiting a moment before protocol negotiation...");
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
println!("Starting protocol negotiation...");
std::io::stdout().flush()?;
match client.negotiate_protocol(1, 60).await {
Ok(_) => {
println!("✓ Protocol negotiation succeeded!");
}
Err(e) => {
println!("✗ Protocol negotiation failed: {:?}", e);
println!("\nThis error occurs during the negotiation process.");
println!("The TLS connection itself was successful.");
return Err(e.into());
}
}
Ok(())
}