libadb 0.9.0

Low-level ADB protocol library for direct TCP and USB communication
Documentation
//! ADB over TLS: wireless debugging on Android 11+.
//!
//! A device with "Wireless debugging" on answers the handshake with
//! [`Command::StartTls`](crate::protocol::command::Command::StartTls)
//! instead of CNXN or AUTH, and speaks nothing but TLS 1.3 afterwards.
//! [`Connection::connect_tls`](crate::Connection::connect_tls) takes it
//! up on that. This module holds the certificate and the `rustls`
//! profile the host presents; the transport that runs TLS is
//! [`MaybeTls`](crate::transport::tls::MaybeTls).
//!
//! # Connecting
//!
//! ```ignore
//! use libadb::keys::rsa::rand_core::OsRng;
//! use libadb::transport::tls::MaybeTls;
//! use libadb::{
//!     Connection, ConnectionConfig, Feature, HostBanner, TlsClientConfig, TlsIdentity, TokioTcp,
//! };
//!
//! // Once per key: building the identity signs a certificate.
//! let identity = TlsIdentity::from_key(&key, &mut OsRng)?;
//! let tls = TlsClientConfig::adb(&identity)?;
//!
//! let tcp = tokio::net::TcpStream::connect(addr).await?;
//! let transport = MaybeTls::plain(TokioTcp::new(tcp));
//! let conn = Connection::connect_tls(
//!     transport,
//!     key,
//!     HostBanner::Features(&[Feature::ShellV2]),
//!     ConnectionConfig::new(),
//!     &tls,
//! )
//! .await?;
//! ```
//!
//! # What authenticates whom
//!
//! The device authenticates the host by the public key inside the
//! client certificate, checked against the same trusted-key store a USB
//! authorisation prompt fills. A key that was confirmed over USB is
//! therefore accepted here with no pairing at all.
//!
//! The host does not authenticate the device. Its certificate is
//! self-signed and belongs to no chain, and `adb` accepts whatever it
//! is handed; [`TlsClientConfig::adb`] does the same. What stands in
//! for it is the device's position on the network and the ADB layer
//! above. If that is not enough for you, build your own verifier and
//! pass it through [`TlsClientConfig::from_rustls`].
//!
//! # Elsewhere, and not covered
//!
//! * `adb pair`, which puts a *new* key on a device, lives in
//!   `crate::pairing` behind the `pairing` feature. A key the device
//!   already trusts does not need it.
//! * Finding the port. Wireless debugging picks a fresh one every time
//!   it is switched on and announces it over DNS-SD; this crate does no
//!   service discovery, so the caller supplies host and port.
//! * TLS over USB: adbd never offers STLS there. `connect_tls` still
//!   serves a USB transport, through the plain handshake.

mod config;
mod identity;

pub use config::{TlsClientConfig, TlsConfigError};
pub use identity::{TlsIdentity, TlsIdentityError};

pub use rustls;