Crate takproto

Crate takproto 

Source
Expand description

§takproto

A Rust library for sending TAK (Team Awareness Kit) Protocol messages to TAK servers with full mTLS support.

§Features

  • TAK Protocol Version 1 - Protocol Buffer-based messaging
  • mTLS Support - Client certificate authentication
  • Protocol Negotiation - Automatic handshake with TAK servers
  • XML Mode - Legacy Protocol Version 0 support
  • Async/Await - Built on Tokio
  • Type-Safe - Generated protobuf types

§Feature Flags

  • openssl-p12 - Enable full PKCS#12 support using OpenSSL for legacy TAK server certificates

Enable in your Cargo.toml:

[dependencies]
takproto = { version = "0.2", features = ["openssl-p12"] }

Without this feature, the library uses a pure Rust P12 parser which may not support legacy formats. If you encounter P12 parsing errors, either enable this feature or extract the P12 to PEM files.

§Quick Start

use std::time::{SystemTime, UNIX_EPOCH};
use takproto::{TakClient, TlsConfig, proto::CotEvent};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Configure mTLS
    let tls_config = TlsConfig::new_with_client_cert(
        "ca.pem",
        "client.pem",
        "client-key.pem"
    )?;

    // Connect to TAK server
    let mut client = TakClient::connect_tls(
        "takserver.example.com:8089",
        "takserver.example.com",
        tls_config
    ).await?;

    // Negotiate protocol (optional)
    client.negotiate_protocol(1, 60).await?;

    // Get current time
    let now_ms = SystemTime::now()
        .duration_since(UNIX_EPOCH)?
        .as_millis() as u64;

    // Create a position report
    let event = CotEvent {
        r#type: "a-f-G-U-C".to_string(),
        uid: "RUST-TAK-1".to_string(),
        send_time: now_ms,
        start_time: now_ms,
        stale_time: now_ms + 60_000,
        how: "m-g".to_string(),
        lat: 37.7749,
        lon: -122.4194,
        hae: 10.0,
        ce: 9.9,
        le: 9.9,
        ..Default::default()
    };

    // Send the event
    client.send_cot_event(event).await?;

    Ok(())
}

§Protocol Modes

§Protobuf Mode (for high-frequency updates)

// Negotiate protocol
client.negotiate_protocol(1, 60).await?;

§XML Mode (for maximum compatibility)

// No negotiation needed - send directly as XML
client.send_cot_event_xml(event).await?;

§Helper Functions

use takproto::helpers::{url_to_uid, remarks, color, colors};

// Convert URL to clean UID
let uid = url_to_uid("https://status.example.com");  // "status.example.com"

// Create colored marker details
let xml = format!("{}\n{}",
    remarks("System Status"),
    color(colors::GREEN)
);

Re-exports§

pub use builder::CotEventBuilder;

Modules§

builder
Builder pattern for creating CotEvent messages
helpers
proto
Protocol Buffer generated types for TAK messages
xml

Structs§

TakClient
TAK Protocol client for streaming connections to TAK servers
TlsConfig
TLS configuration for TAK client connections
TlsConfigBuilder
Builder for TLS configuration with validation options

Enums§

TakError
Errors that can occur when working with TAK protocol

Type Aliases§

Result
Result type for TAK operations