Skip to main content

LockdownClient

Struct LockdownClient 

Source
pub struct LockdownClient {
    pub idevice: Idevice,
    pub session_id: Option<String>,
}
Expand description

Client for interacting with the iOS lockdown service

This is the primary service for device management and provides:

  • Access to device information and settings
  • Service discovery and port allocation
  • Session management and security

Fields§

§idevice: Idevice

The underlying device connection with established lockdown service

§session_id: Option<String>

Implementations§

Source§

impl LockdownClient

Source

pub const LOCKDOWND_PORT: u16 = 62078

The default TCP port for the lockdown service

Source

pub fn new(idevice: Idevice) -> Self

Creates a new lockdown client from an existing device connection

§Arguments
  • idevice - Pre-established device connection
Source

pub async fn get_value( &mut self, key: Option<&str>, domain: Option<&str>, ) -> Result<Value, IdeviceError>

Retrieves a specific value from the device

§Arguments
  • value - The name of the value to retrieve (e.g., “DeviceName”)
§Returns

The requested value as a plist Value

§Errors

Returns IdeviceError if:

  • Communication fails
  • The requested value doesn’t exist
  • The response is malformed
§Example
let device_name = client.get_value("DeviceName").await?;
println!("Device name: {:?}", device_name);
Source

pub async fn set_value( &mut self, key: impl Into<String>, value: Value, domain: Option<&str>, ) -> Result<(), IdeviceError>

Sets a value on the device

§Arguments
  • key - The key to set
  • value - The plist value to set
  • domain - An optional domain to set by
§Errors

Returns IdeviceError if:

  • Communication fails
  • The response is malformed
§Example
client.set_value("EnableWifiDebugging", true.into(), Some("com.apple.mobile.wireless_lockdown".to_string())).await?;
Source

pub async fn remove_value( &mut self, key: impl Into<String>, domain: Option<&str>, ) -> Result<(), IdeviceError>

Removes a value on the device

Sends a lockdown RemoveValue request. Wire format matches Apple’s AMDeviceRemoveValue: { "Request": "RemoveValue", "Domain"?: domain, "Key": key }.

§Arguments
  • key - The key to remove
  • domain - An optional domain to remove from
§Errors

Returns IdeviceError if communication fails or the device replies with an Error

Source

pub async fn unpair( &mut self, host_id: impl Into<String>, ) -> Result<(), IdeviceError>

Unpairs the host from the device

Sends a lockdown Unpair request carrying the host pair-record identity.

Note this only removes the pairing from the device side. The host-side pairing record (stored by usbmuxd) should be removed separately via crate::usbmuxd::UsbmuxdConnection::delete_pair_record.

§Arguments
§Errors

Returns IdeviceError if communication fails or the device replies with an Error.

Source

pub async fn start_session( &mut self, pairing_file: &PairingFile, ) -> Result<bool, IdeviceError>

Starts a secure TLS session with the device

§Arguments
  • pairing_file - Contains the device’s identity and certificates
§Returns

Ok(legacy) on successful session establishment, where legacy indicates whether the device is running iOS < 5 and requires legacy TLS settings

§Errors

Returns IdeviceError if:

  • No connection is established
  • The session request is denied
  • TLS handshake fails
Source

pub async fn stop_session(&mut self) -> Result<(), IdeviceError>

Stops the secure lockdown session previously started with start_session.

Sends a lockdown StopSession request carrying the SessionID the device returned when the session was started. Note this does NOT tear down the TLS socket in place, the caller is expected to drop the connection.

§Errors

Returns IdeviceError if communication fails or the device replies with an Error.

Source

pub async fn start_service( &mut self, identifier: impl Into<String>, ) -> Result<(u16, bool), IdeviceError>

Requests to start a service on the device

§Arguments
  • identifier - The service identifier (e.g., “com.apple.debugserver”)
§Returns

A tuple containing:

  • The port number where the service is available
  • A boolean indicating whether SSL should be used
§Errors

Returns IdeviceError if:

  • The service cannot be started
  • The response is malformed
  • The requested service doesn’t exist
Source

pub async fn start_service_with_escrow( &mut self, identifier: impl Into<String>, escrow_bag: Option<Vec<u8>>, ) -> Result<(u16, bool), IdeviceError>

Requests to start a service, optionally presenting an escrow keybag so the device unlocks its data protection for the service session.

This mirrors Apple’s AMDeviceSecureStartService with UnlockEscrowBag = true: the StartService lockdown request gains an EscrowBag key. Without it the device leaves data protection locked, so a service that must write protection-class files (mobilebackup2 restore of an encrypted backup, house_arrest) fails device-side with “setting protection class (device locked?)” (MBErrorDomain 208). Non-protected data is unaffected, which is why a non-encrypted restore succeeds without the escrow bag.

§Arguments
  • identifier - The service identifier (e.g., “com.apple.mobilebackup2”)
  • escrow_bag - The device’s escrow keybag from the pairing record; None behaves exactly like start_service.
Source

pub async fn pair( &mut self, host_id: impl Into<String>, system_buid: impl Into<String>, host_name: Option<&str>, ) -> Result<PairingFile, IdeviceError>

Generates a pairing file and sends it to the device for trusting. Note that this does NOT save the file to usbmuxd’s cache. That’s a responsibility of the caller. Note that this function is computationally heavy in a debug build.

§Arguments
  • host_id - The host ID, in the form of a UUID. Typically generated from the host name
  • system_buid - UUID fetched from usbmuxd. Doesn’t appear to affect function.
§Returns

The newly generated pairing record

§Errors

Returns IdeviceError

Source

pub async fn pair_once( &mut self, host_id: impl Into<String>, system_buid: impl Into<String>, host_name: Option<&str>, ) -> Result<PairingFile, IdeviceError>

Attempts to pair with the device exactly ONCE, without looping or sleeping.

Unlike LockdownClient::pair, this does NOT block on IdeviceError::PairingDialogResponsePending: the pending/denied/password-protected errors are propagated directly to the caller so it can drive its own retry/UI flow (e.g. showing a “Trust This Computer” prompt). The lockdown “Error” field is mapped to the corresponding IdeviceError variant by read_plist.

Note that this does NOT save the file to usbmuxd’s cache. That’s a responsibility of the caller.

§Arguments
  • host_id - The host ID, in the form of a UUID. Typically generated from the host name
  • system_buid - UUID fetched from usbmuxd. Doesn’t appear to affect function.
§Returns

The newly generated pairing record on success.

§Errors

Returns IdeviceError, including PairingDialogResponsePending, UserDeniedPairing, and PasswordProtected surfaced directly from the device.

Source

pub async fn enter_recovery(&mut self) -> Result<(), IdeviceError>

Tell the device to enter recovery mode

Trait Implementations§

Source§

impl Debug for LockdownClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Idevice> for LockdownClient

Source§

fn from(value: Idevice) -> Self

Converts an existing device connection into a lockdown client

Source§

impl IdeviceService for LockdownClient

Source§

fn service_name() -> Cow<'static, str>

Returns the lockdown service name as registered with the device

Source§

async fn connect(provider: &dyn IdeviceProvider) -> Result<Self, IdeviceError>

Establishes a connection to the lockdown service

§Arguments
  • provider - Device connection provider
§Returns

A connected LockdownClient instance

§Errors

Returns IdeviceError if connection fails

Source§

async fn from_stream(idevice: Idevice) -> Result<Self, IdeviceError>

Source§

impl RsdService for LockdownClient

Available on crate feature rsd only.
Source§

fn rsd_service_name() -> Cow<'static, str>

Source§

async fn from_stream(stream: Box<dyn ReadWrite>) -> Result<Self, IdeviceError>

Source§

fn connect_rsd( provider: &mut impl RsdProvider, handshake: &mut RsdHandshake, ) -> impl Future<Output = Result<Self, IdeviceError>>
where Self: RsdService,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more