mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 14:36:16 +01:00
Implement misagent
This commit is contained in:
@@ -294,6 +294,10 @@ pub enum IdeviceError {
|
|||||||
#[error("image not mounted")]
|
#[error("image not mounted")]
|
||||||
ImageNotMounted,
|
ImageNotMounted,
|
||||||
|
|
||||||
|
#[cfg(feature = "misagent")]
|
||||||
|
#[error("misagent operation failed")]
|
||||||
|
MisagentFailure,
|
||||||
|
|
||||||
#[cfg(any(feature = "tss", feature = "tunneld"))]
|
#[cfg(any(feature = "tss", feature = "tunneld"))]
|
||||||
#[error("http reqwest error")]
|
#[error("http reqwest error")]
|
||||||
Reqwest(#[from] reqwest::Error),
|
Reqwest(#[from] reqwest::Error),
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// Incomplete implementation for installation_proxy
|
// Incomplete implementation for installation_proxy
|
||||||
|
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use plist::{Dictionary, Value};
|
use plist::Dictionary;
|
||||||
|
|
||||||
use crate::{lockdownd::LockdowndClient, Idevice, IdeviceError, IdeviceService};
|
use crate::{lockdownd::LockdowndClient, Idevice, IdeviceError, IdeviceService};
|
||||||
|
|
||||||
@@ -45,39 +45,6 @@ impl MisagentClient {
|
|||||||
req.insert("MessageType".into(), "Install".into());
|
req.insert("MessageType".into(), "Install".into());
|
||||||
req.insert("Profile".into(), plist::Value::Data(profile));
|
req.insert("Profile".into(), plist::Value::Data(profile));
|
||||||
|
|
||||||
// TODO: Determine if there are other types of profiles we can install
|
|
||||||
req.insert("ProfileType".into(), "Provisioning".into());
|
|
||||||
|
|
||||||
self.idevice
|
|
||||||
.send_plist(plist::Value::Dictionary(req))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let res = self.idevice.read_plist().await?;
|
|
||||||
|
|
||||||
todo!();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn remove(&mut self, id: &str) -> Result<(), IdeviceError> {
|
|
||||||
let mut req = Dictionary::new();
|
|
||||||
req.insert("MessageType".into(), "Remove".into());
|
|
||||||
req.insert("ProfileID".into(), id.into());
|
|
||||||
|
|
||||||
// TODO: Determine if there are other types of profiles we can install
|
|
||||||
req.insert("ProfileType".into(), "Provisioning".into());
|
|
||||||
|
|
||||||
self.idevice
|
|
||||||
.send_plist(plist::Value::Dictionary(req))
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let res = self.idevice.read_plist().await?;
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn copy_all(&mut self) -> Result<Vec<Value>, IdeviceError> {
|
|
||||||
let mut req = Dictionary::new();
|
|
||||||
req.insert("MessageType".into(), "CopyAll".into());
|
|
||||||
|
|
||||||
// TODO: Determine if there are other types of profiles we can install
|
|
||||||
req.insert("ProfileType".into(), "Provisioning".into());
|
req.insert("ProfileType".into(), "Provisioning".into());
|
||||||
|
|
||||||
self.idevice
|
self.idevice
|
||||||
@@ -85,13 +52,88 @@ impl MisagentClient {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut res = self.idevice.read_plist().await?;
|
let mut res = self.idevice.read_plist().await?;
|
||||||
Ok(match res.remove("Payload") {
|
|
||||||
// TODO: Determine if this is actually an array
|
match res.remove("Status") {
|
||||||
Some(plist::Value::Array(a)) => a,
|
Some(plist::Value::Integer(status)) => {
|
||||||
|
if let Some(status) = status.as_unsigned() {
|
||||||
|
if status == 1 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(IdeviceError::MisagentFailure)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn!("Misagent return status wasn't unsigned");
|
||||||
|
Err(IdeviceError::UnexpectedResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
warn!("Did not get integer status response");
|
||||||
|
Err(IdeviceError::UnexpectedResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn remove(&mut self, id: &str) -> Result<(), IdeviceError> {
|
||||||
|
let mut req = Dictionary::new();
|
||||||
|
req.insert("MessageType".into(), "Remove".into());
|
||||||
|
req.insert("ProfileID".into(), id.into());
|
||||||
|
|
||||||
|
req.insert("ProfileType".into(), "Provisioning".into());
|
||||||
|
|
||||||
|
self.idevice
|
||||||
|
.send_plist(plist::Value::Dictionary(req))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut res = self.idevice.read_plist().await?;
|
||||||
|
|
||||||
|
match res.remove("Status") {
|
||||||
|
Some(plist::Value::Integer(status)) => {
|
||||||
|
if let Some(status) = status.as_unsigned() {
|
||||||
|
if status == 1 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(IdeviceError::MisagentFailure)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn!("Misagent return status wasn't unsigned");
|
||||||
|
Err(IdeviceError::UnexpectedResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
warn!("Did not get integer status response");
|
||||||
|
Err(IdeviceError::UnexpectedResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn copy_all(&mut self) -> Result<Vec<Vec<u8>>, IdeviceError> {
|
||||||
|
let mut req = Dictionary::new();
|
||||||
|
req.insert("MessageType".into(), "CopyAll".into());
|
||||||
|
|
||||||
|
req.insert("ProfileType".into(), "Provisioning".into());
|
||||||
|
|
||||||
|
self.idevice
|
||||||
|
.send_plist(plist::Value::Dictionary(req))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut res = self.idevice.read_plist().await?;
|
||||||
|
match res.remove("Payload") {
|
||||||
|
Some(plist::Value::Array(a)) => {
|
||||||
|
let mut res = Vec::new();
|
||||||
|
for profile in a {
|
||||||
|
if let Some(profile) = profile.as_data() {
|
||||||
|
res.push(profile.to_vec());
|
||||||
|
} else {
|
||||||
|
warn!("Misagent CopyAll did not return data plists");
|
||||||
|
return Err(IdeviceError::UnexpectedResponse);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(res)
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
warn!("Did not get a payload of provisioning profiles as an array");
|
warn!("Did not get a payload of provisioning profiles as an array");
|
||||||
return Err(IdeviceError::UnexpectedResponse);
|
Err(IdeviceError::UnexpectedResponse)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ async fn main() {
|
|||||||
|
|
||||||
let mut interval = 15;
|
let mut interval = 15;
|
||||||
loop {
|
loop {
|
||||||
interval = heartbeat_client.get_marco(interval).await.unwrap();
|
interval = heartbeat_client.get_marco(1000).await.unwrap();
|
||||||
heartbeat_client.send_polo().await.unwrap();
|
heartbeat_client.send_polo().await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
// Jackson Coxson
|
// Jackson Coxson
|
||||||
|
|
||||||
use clap::{Arg, Command};
|
use std::path::PathBuf;
|
||||||
use idevice::{misagent::MisagentClient, pretty_print_plist, IdeviceService};
|
|
||||||
|
use clap::{arg, value_parser, Arg, Command};
|
||||||
|
use idevice::{misagent::MisagentClient, IdeviceService};
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
@@ -26,8 +28,7 @@ async fn main() {
|
|||||||
.arg(
|
.arg(
|
||||||
Arg::new("udid")
|
Arg::new("udid")
|
||||||
.value_name("UDID")
|
.value_name("UDID")
|
||||||
.help("UDID of the device (overrides host/pairing file)")
|
.help("UDID of the device (overrides host/pairing file)"),
|
||||||
.index(1),
|
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("about")
|
Arg::new("about")
|
||||||
@@ -35,7 +36,19 @@ async fn main() {
|
|||||||
.help("Show about information")
|
.help("Show about information")
|
||||||
.action(clap::ArgAction::SetTrue),
|
.action(clap::ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.subcommand(Command::new("list").about("Lists the images mounted on the device"))
|
.subcommand(
|
||||||
|
Command::new("list")
|
||||||
|
.about("Lists the images mounted on the device")
|
||||||
|
.arg(
|
||||||
|
arg!(-s --save <FOLDER> "the folder to save the profiles to")
|
||||||
|
.value_parser(value_parser!(PathBuf)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
Command::new("remove")
|
||||||
|
.about("Remove a provisioning profile")
|
||||||
|
.arg(Arg::new("id").required(true).index(1)),
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
if matches.get_flag("about") {
|
if matches.get_flag("about") {
|
||||||
@@ -59,14 +72,29 @@ async fn main() {
|
|||||||
.await
|
.await
|
||||||
.expect("Unable to connect to misagent");
|
.expect("Unable to connect to misagent");
|
||||||
|
|
||||||
if matches.subcommand_matches("list").is_some() {
|
if let Some(matches) = matches.subcommand_matches("list") {
|
||||||
let images = misagent_client
|
let images = misagent_client
|
||||||
.copy_all()
|
.copy_all()
|
||||||
.await
|
.await
|
||||||
.expect("Unable to get images");
|
.expect("Unable to get images");
|
||||||
for i in images {
|
for i in &images {
|
||||||
println!("{}", pretty_print_plist(&i));
|
// println!("{:?}", i);
|
||||||
}
|
}
|
||||||
|
if let Some(path) = matches.get_one::<PathBuf>("save") {
|
||||||
|
tokio::fs::create_dir_all(path)
|
||||||
|
.await
|
||||||
|
.expect("Unable to create save DIR");
|
||||||
|
|
||||||
|
for (index, image) in images.iter().enumerate() {
|
||||||
|
let f = path.join(format!("{index}.pem"));
|
||||||
|
tokio::fs::write(f, image)
|
||||||
|
.await
|
||||||
|
.expect("Failed to write image");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let Some(matches) = matches.subcommand_matches("remove") {
|
||||||
|
let id = matches.get_one::<String>("id").expect("No ID passed");
|
||||||
|
misagent_client.remove(id).await.expect("Failed to remove");
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Invalid usage, pass -h for help");
|
eprintln!("Invalid usage, pass -h for help");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user