tr064 0.1.0

Vendor-neutral client for the TR-064 (UPnP/SOAP) device management protocol
Documentation

tr064

Vendor-neutral async Rust client for TR-064, the UPnP/SOAP protocol many routers, modems and gateways use for device management.

  • Reads the device description and the service descriptions (SCPD), so every service and action of a device is available at runtime, vendor extensions included
  • Calls actions over SOAP and reports UPnP errors with their codes
  • HTTP Digest authentication (MD5 and SHA-256). Reuses the nonce and never retries rejected credentials, so a wrong password does not lock the account
  • TLS with a pinned certificate fingerprint for devices with self-signed certificates, and a helper to fetch the fingerprint on first use
  • rustls only, no OpenSSL

Example

use tr064::{Client, SecretString, Url};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = Client::builder(Url::parse("http://192.168.178.1:49000")?)
        .credentials("user", SecretString::from("password"))
        .build()?;

    let description = client.description().await?;
    let device_info = description.service("DeviceInfo1")?;
    let out = client.call(device_info, "GetInfo", &[]).await?;
    for (name, value) in out.iter() {
        println!("{name} = {value}");
    }
    Ok(())
}

For https, pin the device's certificate:

let url = Url::parse("https://192.168.178.1:49443")?;
let fingerprint = tr064::fetch_fingerprint(&url, Duration::from_secs(5)).await?;
// Confirm the fingerprint once, store it, and pin it from then on.
let client = Client::builder(url).pin(fingerprint).build()?;

The examples list the services of a device and call any action:

TR064_URL=http://192.168.178.1:49000 cargo run -p tr064 --example services
TR064_USERNAME=user TR064_PASSWORD=secret cargo run -p tr064 --example call -- DeviceInfo1 GetInfo

Scope

The crate knows the protocol, not any particular device. Vendor-specific meaning, such as what a vendor's error codes stand for, belongs to the application. Values are passed and returned as strings. The SCPD names each argument's UPnP data type.

License

Apache-2.0