takproto 0.4.2

Rust library for TAK (Team Awareness Kit) Protocol - send CoT messages to TAK servers with mTLS support
Documentation
//! Test client certificate with invalid server cert - XML mode only
//!
//! This bypasses protocol negotiation to test if the issue is specific
//! to the negotiation process or a general TLS issue.

use takproto::helpers::contact;
use takproto::{CotEventBuilder, 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!("===================================================");
    println!("Testing: Client Auth + Invalid Cert (XML MODE)");
    println!("===================================================");
    println!("Server: {}", server_addr);
    println!("P12 File: {}", p12_file);
    println!("\n⚠️  Accepting invalid server certificates (testing only!)");
    println!("✓ Staying in XML mode - no protocol negotiation\n");

    println!("Loading P12 and configuring TLS...");
    let tls_config = TlsConfigBuilder::new()
        .with_p12(p12_file, password)?
        .danger_accept_invalid_certs(true)
        .build()?;
    println!("✓ TLS configuration created\n");

    println!("Connecting to {}...", server_addr);
    let mut client = TakClient::connect_tls(server_addr, server_name, tls_config).await?;
    println!("✓ Connected!\n");

    println!("⚠️  Skipping protocol negotiation - staying in XML mode\n");

    println!("Sending test event (XML)...");
    let event = CotEventBuilder::new()
        .uid("CLIENT-CERT-XML-TEST")
        .cot_type("a-f-G-U-C")
        .lat_lon(39.377445, -76.832160)
        .hae(10.0)
        .ce_le(9.9, 9.9)
        .how("m-g")
        .stale_minutes(5)
        .with_contact(contact("ClientCertXML", None))
        .build()?;

    client.send_cot_event_xml(event).await?;
    println!("✓ Event sent successfully!\n");

    println!("===================================================");
    println!("✅ SUCCESS in XML mode!");
    println!("===================================================");
    println!("If this works but protobuf negotiation doesn't,");
    println!("the issue is with protocol negotiation, not TLS.");
    println!("\nCheck your TAK client for 'CLIENT-CERT-XML-TEST'.");

    Ok(())
}