Improve cert revocation prompt function

This commit is contained in:
nab138
2026-02-16 20:37:41 -05:00
parent e7263b982b
commit 92fdc72741
5 changed files with 15 additions and 18 deletions

View File

@@ -9,6 +9,7 @@ use isideload::{
teams::DeveloperTeam,
},
sideload::{SideloaderBuilder, TeamSelection, builder::MaxCertsBehavior},
util::keyring_storage::KeyringStorage,
};
use tracing::Level;
@@ -111,20 +112,21 @@ async fn main() {
Some(
selections
.into_iter()
.map(|n| certs[n - 1].clone())
.map(|n| certs[n - 1].serial_number.clone().unwrap_or_default())
.collect::<Vec<_>>(),
)
};
let mut sideloader = SideloaderBuilder::new(dev_session, apple_id.to_string())
.team_selection(TeamSelection::PromptOnce(team_selection_prompt))
.max_certs_behavior(MaxCertsBehavior::Prompt(cert_selection_prompt))
.max_certs_behavior(MaxCertsBehavior::Prompt(Box::new(cert_selection_prompt)))
.storage(Box::new(KeyringStorage::new("minimal".to_string())))
.machine_name("isideload-minimal".to_string())
.build();
let result = sideloader.install_app(&provider, app_path, true).await;
match result {
Ok(_) => println!("App installed successfully"),
Err(e) => panic!("Failed to install app: {:?}", e),
Err(e) => panic!("{}", e),
}
}

View File

@@ -27,7 +27,7 @@ pub enum SideloadError {
#[error("Invalid bundle: {0}")]
InvalidBundle(String),
#[error(transparent)]
#[error("{0}")]
IdeviceError(#[from] IdeviceError),
}

View File

@@ -40,7 +40,7 @@ pub enum MaxCertsBehavior {
/// If the maximum number of certificates is reached, return an error instead of creating a new certificate
Error,
/// If the maximum number of certificates is reached, prompt the user to select which certificates to revoke until it is possible to create a new certificate
Prompt(fn(&Vec<DevelopmentCertificate>) -> Option<Vec<DevelopmentCertificate>>),
Prompt(Box<dyn Fn(&Vec<DevelopmentCertificate>) -> Option<Vec<String>> + Send + Sync>),
}
/// The actual behavior choices for extensions (non-prompt variants)

View File

@@ -307,17 +307,12 @@ impl CertificateIdentity {
error!("User did not select any certificates to revoke");
return Err(error.into());
}
for cert in certs_to_revoke.unwrap() {
info!(
"Revoking certificate with name: {}",
cert.machine_name
.unwrap_or(cert.machine_id.unwrap_or_default())
);
let serial_number = cert.serial_number.clone();
for serial in certs_to_revoke.unwrap() {
info!("Revoking certificate with serial number: {}", serial);
developer_session
.revoke_development_cert(team, &cert.serial_number.unwrap(), None)
.revoke_development_cert(team, &serial, None)
.await?;
existing_certs.retain(|c| c.serial_number != serial_number);
existing_certs.retain(|c| c.serial_number != Some(serial.clone()));
}
Ok(())
}

View File

@@ -210,10 +210,10 @@ impl Sideloader {
.await
.context("Failed to install app on device")?;
if self.delete_app_after_install {
if let Err(e) = tokio::fs::remove_dir_all(signed_app_path).await {
tracing::warn!("Failed to remove temporary signed app file: {}", e);
};
if self.delete_app_after_install
&& let Err(e) = tokio::fs::remove_dir_all(signed_app_path).await
{
tracing::warn!("Failed to remove temporary signed app file: {}", e);
}
Ok(special_app)