Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

Commit

Permalink
Improve altool error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvartan committed Apr 15, 2021
1 parent 4e7e9af commit 6197aa5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xcnotary"
version = "0.4.6"
version = "0.4.7"
authors = ["David Vartan <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
Expand Down
40 changes: 19 additions & 21 deletions src/notarize/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,9 @@ impl NotarizeOp {
let output = self.run_altool(AltoolArgs::NotarizeApp {
path: &input_path.path,
bundle_id: &self.bundle_id,
});

if !output.status.success() {
return Err(OperationError::detail(
"Notarization upload failed",
&String::from_utf8(output.stderr).unwrap(),
));
}
})?;

let upload = plist::notarization_upload_response(&output.stdout);
let upload = plist::notarization_upload_response(output.as_bytes());

Ok(upload.details.request_uuid)
}
Expand All @@ -162,16 +155,9 @@ impl NotarizeOp {
fn get_status(&self, request_id: &str) -> Result<NotarizationInfo, OperationError> {
let output = self.run_altool(AltoolArgs::NotarizationInfo {
request_id: request_id.clone(),
});

if !output.status.success() {
return Err(OperationError::detail(
"Notarization status check failed",
&String::from_utf8(output.stderr).unwrap(),
));
}
})?;

let info = plist::notarization_status_response(&output.stdout);
let info = plist::notarization_status_response(output.as_bytes());

if !info
.success_message
Expand Down Expand Up @@ -201,7 +187,7 @@ impl NotarizeOp {
Ok(())
}

fn run_altool(&self, args: AltoolArgs) -> std::process::Output {
fn run_altool(&self, args: AltoolArgs) -> Result<String, OperationError> {
let args = match args {
AltoolArgs::NotarizationInfo { request_id } => vec!["--notarization-info", &request_id],
AltoolArgs::NotarizeApp { path, bundle_id } => vec![
Expand All @@ -218,7 +204,7 @@ impl NotarizeOp {
.as_ref()
.map_or(vec![], |p| vec!["--asc-provider", &p]);

Command::new("/usr/bin/xcrun")
let output = Command::new("/usr/bin/xcrun")
.args(&[
"altool",
"-u",
Expand All @@ -231,6 +217,18 @@ impl NotarizeOp {
.args(provider_args)
.args(args)
.output()
.unwrap()
.unwrap();

let stdout = String::from_utf8(output.stdout).unwrap();

if output.status.success() {
Ok(stdout)
} else {
let combined = String::from_utf8(output.stderr).unwrap() + &stdout;
Err(OperationError::detail(
"Notarization service returned an error. Please check the output and try again",
&combined,
))
}
}
}
8 changes: 5 additions & 3 deletions src/precheck/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl super::Precheck for HardenedRuntimeCheck {
} else {
Ok(Status::fail_with(
"Bundle does not have hardened runtime enabled.",
r#"codesign using --runtime flag, or pass OTHER_CODE_SIGN_FLAGS=--runtime to xcodebuild. You can also enable the "Hardened Runtime" capability in Xcode's target settings > "Signing and Capabilities""#,
r#"codesign using --options runtime flag, or pass OTHER_CODE_SIGN_FLAGS=--runtime to xcodebuild. You can also enable the "Hardened Runtime" capability in Xcode's target settings > "Signing and Capabilities""#,
None,
))
}
Expand All @@ -87,12 +87,14 @@ impl super::Precheck for NoGetTaskAllowCheck {
}

if !output.stdout.is_empty() {
if let Some(true) = crate::util::plist::bundle_entitlemens(&output.stdout).get_task_allow {
if let Some(true) =
crate::util::plist::bundle_entitlemens(&output.stdout).get_task_allow
{
return Ok(Status::fail_with(
"Bundle includes get-task-allow entitlement.",
"Specify CODE_SIGN_INJECT_BASE_ENTITLEMENTS=NO when running xcodebuild.",
None,
))
));
}
}

Expand Down
15 changes: 12 additions & 3 deletions src/util/input_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,18 @@ mod tests {

#[test]
fn test_identify_path() {
assert_eq!(Some(PathType::AppBundle), identify_path_type(PathBuf::from("Foo.app")).ok());
assert_eq!(Some(PathType::DiskImage), identify_path_type(PathBuf::from("Foo.dmg")).ok());
assert_eq!(Some(PathType::InstallerPackage), identify_path_type(PathBuf::from("Foo.pkg")).ok());
assert_eq!(
Some(PathType::AppBundle),
identify_path_type(PathBuf::from("Foo.app")).ok()
);
assert_eq!(
Some(PathType::DiskImage),
identify_path_type(PathBuf::from("Foo.dmg")).ok()
);
assert_eq!(
Some(PathType::InstallerPackage),
identify_path_type(PathBuf::from("Foo.pkg")).ok()
);
assert!(identify_path_type(PathBuf::from("Foo")).is_err());
}
}
2 changes: 1 addition & 1 deletion src/util/plist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ mod tests {
</plist>
"#;

static ENTITLEMENTS_OUTPUT:&str = r#"
static ENTITLEMENTS_OUTPUT: &str = r#"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
Expand Down
2 changes: 1 addition & 1 deletion src/util/plist/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) enum NotarizationStatus {
#[serde(rename_all = "kebab-case")]
pub(crate) struct BundleEntitlements {
#[serde(rename = "com.apple.security.get-task-allow")]
pub(crate) get_task_allow: Option<bool>
pub(crate) get_task_allow: Option<bool>,
}

/// Response from altool --upload-app
Expand Down

0 comments on commit 6197aa5

Please sign in to comment.