Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion sweetpad-cli/PLAN_LINUX.md
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,14 @@ Clippy with `-D warnings`, formatting and diff checks also pass.
- [x] App extensions and widgets: an `embeddedBinaryValidationUtility`
stand-in makes Xcode's checks (bundle ID prefix, matching versions);
a widget built here registers in the simulator
- [ ] App Clips
- [x] App Clips. The [delivery fixture](../sweetpad-lib/ci/fixture-delivery/README.md#app-clips)
builds a host with an embedded Clip on Linux and with Xcode. Both hosts
launch on an iPhone simulator, and each installed Clip displays a fresh
HTTPS invocation URL in XCTest. The Release device archives and Linux
development IPA match on host/Clip entitlements and bundle metadata.
Apple's tools verify both signatures, their provisioning profiles, and
both archive dSYMs. Both engines reject a signed Clip missing its parent
entitlement.
- [x] Test targets: `test build` adds the selected test plan's targets, or
the scheme's testables, as `build-for-testing` does, and leaves the
testing frameworks out of the host app like Xcode 27. The bundle passes
Expand Down
43 changes: 36 additions & 7 deletions sweetpad-cli/src/cli/codesign/provisioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,7 @@ pub(super) fn answer(
}
merge(&mut entitlements, project);
if let Some(profile) = &profile {
for key in ["aps-environment", "com.apple.developer.aps-environment"] {
if plist::get(&entitlements, key).is_some()
&& let Some(value) = plist::get(&profile.entitlements, key)
{
plist::set(&mut entitlements, key, value.clone());
}
}
profile.apply_capabilities(&mut entitlements, mac);
}
if !mac || profile.is_some() {
plist::set(
Expand Down Expand Up @@ -485,6 +479,21 @@ pub(super) fn check_entitlements(
Ok(())
}

/// A signed App Clip identifies exactly one full app, including its App ID prefix.
pub(crate) fn check_clip_parent(entitlements: &Plist, host_id: &str) -> Result<(), String> {
let key = "com.apple.developer.parent-application-identifiers";
if let Some(Plist::Array(parents)) = plist::get(entitlements, key)
&& let [Plist::String(parent)] = parents.as_slice()
&& parent == host_id
{
return Ok(());
}
Err(format!(
"The {key} entitlement of an App Clip must match the application-identifier entitlement \
('{host_id}') of its containing parent app."
))
}

/// Whether a profile has to grant entitlement `key`.
fn provisioned(key: &str) -> bool {
(key.starts_with("com.apple.developer.") && key != "com.apple.developer.team-identifier")
Expand Down Expand Up @@ -636,6 +645,26 @@ impl Profile {
}

impl Profile {
/// Xcode takes the requested push environment from the profile. It also
/// signs an iOS host with its registered App Clip association, even when
/// the project has no entitlements file or this build embeds no Clip.
pub(super) fn apply_capabilities(&self, entitlements: &mut Plist, mac: bool) {
for key in ["aps-environment", "com.apple.developer.aps-environment"] {
if plist::get(entitlements, key).is_some()
&& let Some(value) = plist::get(&self.entitlements, key)
{
plist::set(entitlements, key, value.clone());
}
}
let clips = "com.apple.developer.associated-appclip-app-identifiers";
if !mac
&& plist::get(entitlements, clips).is_none()
&& let Some(value) = plist::get(&self.entitlements, clips)
{
plist::set(entitlements, clips, value.clone());
}
}

/// The application identifier it allows, with its team: exact, or a
/// prefix ending in `*`. A macOS profile names it with Apple's prefix.
pub fn application_identifier(&self) -> Option<&str> {
Expand Down
23 changes: 9 additions & 14 deletions sweetpad-cli/src/cli/codesign/resign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,9 @@ pub(super) fn plan_with(
let app = &request.app;
let info = read_info(app)?;
let mac = app.join("Contents").is_dir();
let default_platform = if mac { "macosx" } else { "iphoneos" };
let platform =
provisioning::platform(plist::string(&info, "DTPlatformName").unwrap_or(if mac {
"macosx"
} else {
"iphoneos"
}));
provisioning::platform(plist::string(&info, "DTPlatformName").unwrap_or(default_platform));
let archived = archived(app)?;
let team = match (
&request.team,
Expand Down Expand Up @@ -162,7 +159,7 @@ pub(super) fn plan_with(
if is_provisioned(&path) {
let id = bundle_id(&path)?;
let bundle = bundle.insert(id);
let archived = archived_entitlements(&path)?;
let archived = signed_entitlements(&path)?;
// A Developer ID app embeds a profile only for what Apple grants
// through one, or when ExportOptions names one.
let provisioned = request.method != Method::DeveloperId
Expand All @@ -184,6 +181,9 @@ pub(super) fn plan_with(
} else {
unprovisioned(archived, &team)
};
if path.parent() == Some(app.join("AppClips").as_path()) {
provisioning::check_clip_parent(&signed, &format!("{team}.{}", bundle_id(app)?))?;
}
let icloud = "com.apple.developer.icloud-container-environment";
if let Some(environment) = &request.icloud_environment
&& plist::get(&signed, icloud).is_some()
Expand Down Expand Up @@ -387,7 +387,8 @@ fn archived(bundle: &Path) -> Result<Option<blobs::Existing>, String> {
Ok(layout.signature(&slice.data).and_then(blobs::read_existing))
}

fn archived_entitlements(bundle: &Path) -> Result<Plist, String> {
/// The entitlements in the code signature of a bundle's main executable.
pub(crate) fn signed_entitlements(bundle: &Path) -> Result<Plist, String> {
match archived(bundle)?.and_then(|e| e.entitlements) {
Some(xml) => plist::parse(&xml),
None => Ok(Plist::Dict(Vec::new())),
Expand Down Expand Up @@ -523,13 +524,7 @@ pub(super) fn transform(
let allow = granted("get-task-allow").unwrap_or(Plist::Bool(false));
plist::set(&mut entitlements, "get-task-allow", allow);
}
for key in ["aps-environment", "com.apple.developer.aps-environment"] {
if plist::get(&entitlements, key).is_some()
&& let Some(value) = granted(key)
{
plist::set(&mut entitlements, key, value);
}
}
profile.apply_capabilities(&mut entitlements, mac);
if let Some(value) = granted("beta-reports-active") {
plist::set(&mut entitlements, "beta-reports-active", value);
}
Expand Down
47 changes: 47 additions & 0 deletions sweetpad-cli/src/cli/codesign/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,53 @@ fn an_export_refuses_a_profile_of_another_kind_or_a_missing_one() {
assert!(teams.contains("names no team"), "{teams}");
}

#[test]
fn a_signed_app_clip_must_name_exactly_its_host() {
let host = "TESTTEAM01.dev.sweetpad.app";
let parent = Plist::String(host.into());
let other = Plist::String("TESTTEAM01.dev.sweetpad.other".into());
let check = |parents| {
let rights = Plist::Dict(vec![(
"com.apple.developer.parent-application-identifiers".into(),
Plist::Array(parents),
)]);
provisioning::check_clip_parent(&rights, host)
};
assert!(check(vec![parent.clone()]).is_ok());
assert!(check(vec![other.clone()]).is_err());
assert!(check(vec![parent, other]).is_err());
assert!(provisioning::check_clip_parent(&Plist::Dict(vec![]), host).is_err());
}

#[test]
fn export_restores_the_profiles_app_clip_association_to_an_ad_hoc_archive() {
let mut profile =
provisioning::find_named(kind_profiles(), "Sweetpad Kinds app-store").unwrap();
let key = "com.apple.developer.associated-appclip-app-identifiers";
let clip = Plist::Array(vec![Plist::String(
"TESTTEAM01.dev.sweetpad.kinds.app.Clip".into(),
)]);
plist::set(&mut profile.entitlements, key, clip.clone());
let export = |archived| {
resign::transform(
archived,
&profile,
"TESTTEAM01",
"dev.sweetpad.kinds.app",
false,
resign::Method::AppStoreConnect,
)
};
let signed = export(Plist::Dict(vec![])).unwrap();
assert_eq!(plist::get(&signed, key), Some(&clip));

let other = Plist::Array(vec![Plist::String(
"TESTTEAM01.dev.sweetpad.other.Clip".into(),
)]);
let mismatch = export(Plist::Dict(vec![(key.into(), other)])).unwrap_err();
assert!(mismatch.contains(key), "{mismatch}");
}

#[test]
#[allow(clippy::too_many_lines)] // one table of entitlements per method
fn export_entitlements_move_to_the_profile_and_team() {
Expand Down
25 changes: 18 additions & 7 deletions sweetpad-cli/src/cli/darwin_tools/embedded_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
//! Info.plist> [-signing-cert <name>]`, which Swift Build runs on each app
//! extension, App Clip or watch app it embeds in an app.
//!
//! It makes the checks of Xcode's that hold without signing: an error when
//! the embedded bundle's identifier doesn't start with the app's, and a
//! warning when its `CFBundleVersion`, or else its
//! `CFBundleShortVersionString`, differs from the app's or is missing. The messages are
//! Xcode's, on stderr, where Swift Build reads them.
//! Checks the embedded bundle's identifier and versions against its host.
//! A device App Clip must also name its host in its signed entitlements.

use std::path::{Path, PathBuf};
use std::process::ExitCode;

use sweetpad_lib::derived_data::plist_strings;

use crate::cli::codesign::{provisioning::check_clip_parent, resign::signed_entitlements};
use crate::cli::property_list as plist;

pub(super) fn main(args: &[String]) -> ExitCode {
match validate(args) {
Ok(warnings) => {
Expand All @@ -36,7 +36,6 @@ fn validate(args: &[String]) -> Result<Vec<String>, String> {
while let Some(arg) = it.next() {
match arg.as_str() {
"-info-plist-path" => host_plist = Some(PathBuf::from(super::value(arg, &mut it)?)),
// Nothing is signed during the build here.
"-signing-cert" => {
super::value(arg, &mut it)?;
}
Expand All @@ -54,7 +53,19 @@ fn validate(args: &[String]) -> Result<Vec<String>, String> {
));
}
let own = plist_strings(&info_plist(&embedded));
Ok(check(&own, &host)?.into_iter().collect())
let warning = check(&own, &host)?;
if embedded
.parent()
.is_some_and(|dir| dir.ends_with("AppClips"))
&& own
.iter()
.any(|(k, v)| k == "DTPlatformName" && v == "iphoneos")
&& let Some(app) = host_plist.parent()
&& let Some(host_id) = plist::string(&signed_entitlements(app)?, "application-identifier")
{
check_clip_parent(&signed_entitlements(&embedded)?, host_id)?;
}
Ok(warning.into_iter().collect())
}

/// A bundle's Info.plist: at its root on iOS, in `Contents` on macOS.
Expand Down
2 changes: 1 addition & 1 deletion sweetpad-docs/docs/cli/linux/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sidebar_label: Support and configuration

| Operation | On Linux |
| --- | --- |
| Build iOS apps, extensions, and widgets | Supported. |
| Build iOS apps, extensions, widgets, and App Clips | Supported. App Clips embed in their host and can be exported in a development-signed IPA. |
| Build macOS apps | Supported. Running them needs a Mac. |
| Build tvOS, watchOS, and visionOS simulator targets | Builds and links. Running them and device signing are untested. |
| Build Mac Catalyst targets | Untested. |
Expand Down
Loading
Loading