diff --git a/idevice/src/pairing_file.rs b/idevice/src/pairing_file.rs index fdd6d50..9997da2 100644 --- a/idevice/src/pairing_file.rs +++ b/idevice/src/pairing_file.rs @@ -72,6 +72,14 @@ impl PairingFile { let p = raw.try_into()?; Ok(p) } + + pub fn serialize(self) -> Result, crate::IdeviceError> { + let raw = RawPairingFile::try_from(self)?; + + let mut buf = Vec::new(); + plist::to_writer_xml(&mut buf, &raw)?; + Ok(buf) + } } impl TryFrom for PairingFile { @@ -96,3 +104,35 @@ impl TryFrom for PairingFile { }) } } + +impl TryFrom for RawPairingFile { + type Error = openssl::error::ErrorStack; + + fn try_from(value: PairingFile) -> Result { + Ok(Self { + device_certificate: Data::new(value.device_certificate.to_pem()?), + host_private_key: Data::new(value.host_private_key.private_key_to_pem_pkcs8()?), + host_certificate: Data::new(value.host_certificate.to_pem()?), + root_private_key: Data::new(value.root_private_key.private_key_to_pem_pkcs8()?), + root_certificate: Data::new(value.root_certificate.to_pem()?), + system_buid: value.system_buid, + host_id: value.host_id.clone(), + escrow_bag: Data::new(value.escrow_bag), + wifi_mac_address: value.wifi_mac_address, + udid: value.udid, + }) + } +} + +#[test] +fn f1() { + let f = std::fs::read("/var/lib/lockdown/test.plist").unwrap(); + + println!("{}", String::from_utf8_lossy(&f)); + + let input = PairingFile::from_bytes(&f).unwrap(); + let output = input.serialize().unwrap(); + println!("{}", String::from_utf8_lossy(&output)); + + assert_eq!(f[..output.len()], output); +}