mirror of
https://github.com/nab138/isideload.git
synced 2026-03-02 06:26:16 +01:00
Trim leading zeros in cert
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -981,7 +981,7 @@ checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
|
||||
|
||||
[[package]]
|
||||
name = "isideload"
|
||||
version = "0.1.16"
|
||||
version = "0.1.17"
|
||||
dependencies = [
|
||||
"hex",
|
||||
"idevice",
|
||||
|
||||
@@ -3,7 +3,7 @@ name = "isideload"
|
||||
description = "Sideload iOS/iPadOS applications"
|
||||
license = "MPL-2.0"
|
||||
authors = ["Nicholas Sharp <nab@nabdev.me>"]
|
||||
version = "0.1.16"
|
||||
version = "0.1.17"
|
||||
edition = "2024"
|
||||
repository = "https://github.com/nab138/isideload"
|
||||
documentation = "https://docs.rs/isideload"
|
||||
|
||||
@@ -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<Vec<String>, 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)?;
|
||||
}
|
||||
|
||||
@@ -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<String, Error> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(())
|
||||
|
||||
@@ -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(())
|
||||
|
||||
Reference in New Issue
Block a user