diff --git a/Cargo.lock b/Cargo.lock index a6b768e..c4fc0ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -981,7 +981,7 @@ checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "isideload" -version = "0.1.16" +version = "0.1.17" dependencies = [ "hex", "idevice", diff --git a/isideload/Cargo.toml b/isideload/Cargo.toml index d6e8852..6895f00 100644 --- a/isideload/Cargo.toml +++ b/isideload/Cargo.toml @@ -3,7 +3,7 @@ name = "isideload" description = "Sideload iOS/iPadOS applications" license = "MPL-2.0" authors = ["Nicholas Sharp "] -version = "0.1.16" +version = "0.1.17" edition = "2024" repository = "https://github.com/nab138/isideload" documentation = "https://docs.rs/isideload" diff --git a/isideload/src/bundle.rs b/isideload/src/bundle.rs index 04096c0..117acfd 100644 --- a/isideload/src/bundle.rs +++ b/isideload/src/bundle.rs @@ -21,9 +21,10 @@ impl Bundle { let mut bundle_path = bundle_dir; // Remove trailing slash/backslash if let Some(path_str) = bundle_path.to_str() - && (path_str.ends_with('/') || path_str.ends_with('\\')) { - bundle_path = PathBuf::from(&path_str[..path_str.len() - 1]); - } + && (path_str.ends_with('/') || path_str.ends_with('\\')) + { + bundle_path = PathBuf::from(&path_str[..path_str.len() - 1]); + } let info_plist_path = bundle_path.join("Info.plist"); assert_bundle( @@ -158,13 +159,15 @@ fn find_dylibs(dir: &Path, bundle_root: &Path) -> Result, Error> { if file_type.is_file() { if let Some(name) = path.file_name().and_then(|n| n.to_str()) - && name.ends_with(".dylib") { - // Get relative path from bundle root - if let Ok(relative_path) = path.strip_prefix(bundle_root) - && let Some(relative_str) = relative_path.to_str() { - libraries.push(relative_str.to_string()); - } + && name.ends_with(".dylib") + { + // Get relative path from bundle root + if let Ok(relative_path) = path.strip_prefix(bundle_root) + && let Some(relative_str) = relative_path.to_str() + { + libraries.push(relative_str.to_string()); } + } } else if file_type.is_dir() { collect_dylibs(&path, bundle_root, libraries)?; } diff --git a/isideload/src/certificate.rs b/isideload/src/certificate.rs index 1cd5c8e..c8c6094 100644 --- a/isideload/src/certificate.rs +++ b/isideload/src/certificate.rs @@ -110,10 +110,11 @@ impl CertificateIdentity { { if let Ok(x509_cert) = X509::from_der(&cert.cert_content) && let Ok(cert_public_key) = x509_cert.public_key() - && let Ok(cert_public_key_der) = cert_public_key.public_key_to_der() - && cert_public_key_der == our_public_key { - return Ok(x509_cert); - } + && let Ok(cert_public_key_der) = cert_public_key.public_key_to_der() + && cert_public_key_der == our_public_key + { + return Ok(x509_cert); + } } Err(Error::Certificate( "No matching certificate found".to_string(), @@ -213,4 +214,31 @@ impl CertificateIdentity { pub fn get_private_key_file_path(&self) -> &Path { &self.key_file } + + pub fn get_serial_number(&self) -> Result { + let cert = match &self.certificate { + Some(c) => c, + None => { + return Err(Error::Certificate( + "No certificate available to get serial number".to_string(), + )); + } + }; + let num = cert + .serial_number() + .to_bn() + .map_err(|e| { + Error::Certificate(format!("Failed to convert serial number to bn: {}", e)) + })? + .to_hex_str() + .map_err(|e| { + Error::Certificate(format!( + "Failed to convert serial number to hex string: {}", + e + )) + })? + .to_string(); + + Ok(num.trim_start_matches("0").to_string()) + } } diff --git a/isideload/src/device.rs b/isideload/src/device.rs index b44d412..81a2570 100644 --- a/isideload/src/device.rs +++ b/isideload/src/device.rs @@ -83,10 +83,7 @@ fn afc_upload_dir<'a>( .write_entire(&bytes) .await .map_err(Error::IdeviceError)?; - file_handle - .close() - .await - .map_err(Error::IdeviceError)?; + file_handle.close().await.map_err(Error::IdeviceError)?; } } Ok(()) diff --git a/isideload/src/sideload.rs b/isideload/src/sideload.rs index 755ddf0..90203fc 100644 --- a/isideload/src/sideload.rs +++ b/isideload/src/sideload.rs @@ -385,37 +385,10 @@ pub async fn sideload_app( } if config.revoke_cert { - if let Some(cert) = cert.certificate { - dev_session - .revoke_development_cert( - DeveloperDeviceType::Ios, - &team, - cert.serial_number() - .to_bn() - .map_err(|e| { - Error::Certificate(format!( - "Failed to convert serial number to bn: {}", - e - )) - })? - .to_hex_str() - .map_err(|e| { - Error::Certificate(format!( - "Failed to convert serial number to hex string: {}", - e - )) - })? - .to_string() - .as_str(), - ) - .await?; - logger.log("Certificate revoked"); - } else { - return error_and_return( - logger, - Error::Certificate("No certificate to revoke".to_string()), - ); - } + dev_session + .revoke_development_cert(DeveloperDeviceType::Ios, &team, &cert.get_serial_number()?) + .await?; + logger.log("Certificate revoked"); } Ok(())