--- title: Code signing description: Prepare bundle IDs, certificates, private keys, and provisioning profiles for local or CI builds. --- A downloaded certificate is not a signing identity. The certificate contains a public key; Xcode also needs the matching private key. App Store Connect can return certificates and provisioning profiles, but it cannot return a private key after the certificate request has been created. Use the [signing command reference](/commands/signing) for every flag, profile-type table, encrypted repository format, encryption guarantees, multi-target manifest, CI example, rotation and revocation sequence, and troubleshooting case. This guide explains which workflow to choose. ## Existing identity on one Mac If the matching private key already exists in the selected macOS keychain, fetch the public certificate and provisioning profile: ```bash asc signing fetch \ --app APP_ID \ --bundle-id com.example.app \ --profile-type IOS_APP_STORE \ --output .asc/signing/app-store \ --format json \ --pretty ``` Install the profile by file rather than copying it to a guessed Xcode directory: ```bash asc profiles local install \ --path .asc/signing/app-store/PROFILE.mobileprovision \ --output json ``` The `.cer` file is useful for inspection and verification. Importing it without its private key does not make the machine able to sign. ## New certificate Generate the private key and certificate request locally, then send the request to App Store Connect: ```bash mkdir -p .asc/signing .asc/secrets chmod 700 .asc/signing .asc/secrets certificate_response=.asc/signing/distribution-certificate.json asc certificates create \ --certificate-type IOS_DISTRIBUTION \ --generate-csr \ --key-out .asc/secrets/distribution.key \ --csr-out .asc/signing/distribution.csr \ --output json \ --pretty > "$certificate_response" ``` The private key remains in `.asc/secrets/distribution.key`. Do not commit it, print it, or upload it as a CI artifact. Back it up through encrypted signing sync before removing the bootstrap copy. The key and CSR are written before the API request. After a timeout or ambiguous failure, first list certificates and check whether the request created one whose public key matches the preserved private key. Do not rerun `--generate-csr` or use `--force`: ```bash asc certificates list \ --certificate-type IOS_DISTRIBUTION \ --paginate \ --output json \ --pretty > .asc/signing/distribution-certificates-after-ambiguous-create.json ``` When a matching certificate exists, retrieve that resource into a fresh response file: ```bash certificate_response=.asc/signing/distribution-certificate-recovered.json asc certificates view \ --id MATCHING_CERTIFICATE_ID \ --output json \ --pretty > "$certificate_response" ``` If no matching certificate exists, retry with the preserved CSR and a fresh response file: ```bash certificate_response=.asc/signing/distribution-certificate-retry.json asc certificates create \ --certificate-type IOS_DISTRIBUTION \ --csr .asc/signing/distribution.csr \ --output json \ --pretty > "$certificate_response" ``` ## Shared App Store identity Read the certificate resource ID and public certificate from the same create response. `signing sync push` uses the SHA-256 fingerprint to bind the generated private key, while profile reconciliation uses the resource ID to select that same certificate: ```bash CERTIFICATE_ID="$( jq -r '.data.id' "$certificate_response" )" CERTIFICATE_SHA256="$( jq -r '.data.attributes.certificateContent' \ "$certificate_response" \ | openssl base64 -d -A \ | openssl x509 -inform DER -outform DER \ | shasum -a 256 \ | awk '{print toupper($1)}' )" ``` `signing sync pull` does not transport the App Store Connect certificate resource ID. Save `CERTIFICATE_ID` as a protected, non-secret CI variable named `ASC_DISTRIBUTION_CERTIFICATE_ID`, scoped to the environment that uses this signing repository. Keep that variable paired with the synced identity and update both during rotation. Push that verified private key, certificate, and profile into a private encrypted Git repository: ```bash chmod 600 \ ~/.config/asc/signing-sync-password \ .asc/secrets/distribution.key asc signing sync push \ --bundle-id com.example.app \ --profile-type IOS_APP_STORE \ --repo git@github.com:team/signing.git \ --password-file ~/.config/asc/signing-sync-password \ --private-key .asc/secrets/distribution.key \ --identity-sha256 "$CERTIFICATE_SHA256" \ --create-missing \ --output json \ --pretty ``` For an app with embedded targets, use one strict target manifest so the repository update covers all bundle identifiers in one commit: ```json { "schemaVersion": 1, "targets": [ {"bundleId": "com.example.app"}, {"bundleId": "com.example.app.widget"} ] } ``` ```bash asc signing sync push \ --targets-file ./signing-targets.json \ --profile-type IOS_APP_STORE \ --repo git@github.com:team/signing.git \ --password-file ~/.config/asc/signing-sync-password \ --private-key .asc/secrets/distribution.key \ --identity-sha256 "$CERTIFICATE_SHA256" \ --create-missing \ --output json ``` The same profile type, certificate filter, identity, and device set apply to every target. A batch can create profiles before the final repository push, so a later failure may leave those immutable App Store Connect profiles in place. What AES-256-GCM, PBKDF2, scrypt, and authenticated metadata do and do not guarantee is in [What the encrypted store protects](/commands/signing#what-the-encrypted-store-protects). ## Pull in CI Write the repository password from the CI secret manager to a runner-private file, then pull the signing assets. `signing sync` already forces noninteractive Git (`GIT_TERMINAL_PROMPT=0` and, unless you overrode SSH, `GIT_SSH_COMMAND=ssh -o BatchMode=yes`); keep any custom SSH wrapper equally noninteractive so a prompt cannot hang the runner. The full CI example lives in the [signing command reference](/commands/signing#ci-example). ```bash set +x umask 077 signing_tmp="$(mktemp -d "$RUNNER_TEMP/asc-signing.XXXXXX")" password_file="$signing_tmp/repository-password" cleanup_signing_pull() { rm -f "$password_file" rmdir "$signing_tmp" >/dev/null 2>&1 || true } trap cleanup_signing_pull EXIT printf '%s' "$SIGNING_SYNC_PASSWORD" > "$password_file" mkdir -p .asc/signing chmod 700 .asc/signing asc signing sync pull \ --repo git@github.com:team/signing.git \ --password-file "$password_file" \ --output-dir .asc/signing/pulled \ --output json > .asc/signing/pull-result.json ``` The result lists private identities under `sensitiveFiles`. Install the pulled PKCS#12 into a new dedicated keychain when separate archive and export commands need the identity to persist: ```bash identity_path="$( jq -er ' [.sensitiveFiles[]? | select(endswith(".p12"))] | if length == 1 then .[0] else error("expected exactly one signing identity") end ' .asc/signing/pull-result.json )" keychain_path="$signing_tmp/release.keychain-db" keychain_password_file="$signing_tmp/keychain-password" cleanup_signing() { asc signing keychain delete \ --keychain "$keychain_path" \ --confirm >/dev/null 2>&1 || true rm -f "$password_file" "$keychain_password_file" rmdir "$signing_tmp" >/dev/null 2>&1 || true } trap cleanup_signing EXIT openssl rand -base64 32 > "$keychain_password_file" asc signing keychain install \ --identity ".asc/signing/pulled/$identity_path" \ --identity-password-file "$password_file" \ --keychain "$keychain_path" \ --keychain-password-file "$keychain_password_file" \ --add-to-search-list \ --confirm \ --output json jq -r '.files[] | select(test("\\.(mobileprovision|provisionprofile)$"))' \ .asc/signing/pull-result.json \ | while IFS= read -r profile_path; do asc profiles local install \ --path ".asc/signing/pulled/$profile_path" \ --output json done ``` The receipt supplies the identity's complete relative path. This example requires exactly one pulled PKCS#12 identity and stops if that invariant is not met. The identity password is the encrypted-repository password because sync normalizes the pulled PKCS#12 under that secret. The keychain password is a separate generated secret. The install command is macOS-only, requires a cgo-enabled build, refuses an existing destination, and rolls back the new keychain if import, codesigning verification, or search-list activation fails. It does not change the default keychain. The run-owned temporary directory ensures the cleanup trap cannot delete a pre-existing keychain if installation fails. The keychain remains available after the command succeeds. Keep archive and export inside the lifetime of the cleanup trap on disposable CI workers; for a long-lived machine, omit the trap only when the dedicated keychain is intended to remain. Do not upload the decrypted directory, password files, or keychain. ## Bootstrap a fresh CI runner A fresh macOS runner starts with an App Store Connect API key and nothing else. Before `xcodebuild` can sign, it needs a private key with its certificate, a provisioning profile for every target, a keychain that `codesign` can use, and project build settings that name those profiles. `asc` covers each step: | Step | Command | | --- | --- | | Authenticate | `ASC_KEY_ID`, `ASC_ISSUER_ID`, and `ASC_PRIVATE_KEY_B64` from the CI secret store | | Create or obtain the identity and profiles | First run: `asc signing fetch --create-missing --create-missing-certificate`. Later runs: `asc signing sync pull` | | Keep the identity for later runs | `asc signing sync push --identity ...` | | Install the identity and profiles | `asc signing keychain install --confirm` and `asc profiles local install` | | Point the project at the profiles | `asc xcode signing plan --profile ...`, then `asc xcode signing apply --confirm` | | Archive and export | `asc xcode archive`, then `asc xcode export --export-options ...` | | Clean up | `asc signing keychain delete --confirm` | Provide the API key through [environment variables](/configuration/environment-variables) from the CI secret store. The key's role must allow creating certificates and profiles for the first run. ### First run: one pass from API key to signed archive When the team has no active certificate of the required type, one `signing fetch` creates the private key, certificate signing request, certificate, profile, and password-protected `.p12`. The private key exists only on this runner, so the script pushes the new identity to the encrypted store before it builds anything. A disposable runner that skips that push loses the key when the job ends. ```bash set -eo pipefail set +x umask 077 signing_tmp="$(mktemp -d "$RUNNER_TEMP/asc-signing.XXXXXX")" p12_password_file="$signing_tmp/p12-password" sync_password_file="$signing_tmp/repository-password" keychain_path="$signing_tmp/release.keychain-db" keychain_password_file="$signing_tmp/keychain-password" cleanup_signing() { asc signing keychain delete \ --keychain "$keychain_path" \ --confirm >/dev/null 2>&1 || true rm -f "$p12_password_file" "$sync_password_file" "$keychain_password_file" rmdir "$signing_tmp" >/dev/null 2>&1 || true } trap cleanup_signing EXIT openssl rand -base64 32 > "$p12_password_file" printf '%s' "$SIGNING_SYNC_PASSWORD" > "$sync_password_file" mkdir -p .asc/signing .asc/artifacts chmod 700 .asc/signing asc signing fetch \ --bundle-id com.example.app \ --profile-type IOS_APP_STORE \ --create-missing \ --create-missing-certificate \ --identity-password-file "$p12_password_file" \ --output .asc/signing/bootstrap \ --format json > .asc/signing/fetch-result.json p12_path="$(jq -er '.p12Path' .asc/signing/fetch-result.json)" profile_path="$(jq -er '.profileFile' .asc/signing/fetch-result.json)" asc signing sync push \ --bundle-id com.example.app \ --profile-type IOS_APP_STORE \ --repo git@github.com:team/signing.git \ --password-file "$sync_password_file" \ --identity "$p12_path" \ --identity-password-file "$p12_password_file" \ --output json openssl rand -base64 32 > "$keychain_password_file" asc signing keychain install \ --identity "$p12_path" \ --identity-password-file "$p12_password_file" \ --keychain "$keychain_path" \ --keychain-password-file "$keychain_password_file" \ --add-to-search-list \ --confirm \ --output json asc profiles local install \ --path "$profile_path" \ --output json asc xcode signing plan \ --project Example.xcodeproj \ --profile "$profile_path" \ --configuration Release \ --export-options-out .asc/artifacts/ExportOptions.plist \ --output json > .asc/signing/xcode-plan.json jq -e '.ready' .asc/signing/xcode-plan.json >/dev/null asc xcode signing apply \ --plan .asc/xcode/signing/plan.json \ --confirm \ --output json asc xcode archive \ --project Example.xcodeproj \ --scheme Example \ --configuration Release \ --archive-path .asc/artifacts/Example.xcarchive asc xcode export \ --archive-path .asc/artifacts/Example.xcarchive \ --export-options .asc/artifacts/ExportOptions.plist \ --ipa-path .asc/artifacts/Example.ipa ``` Read these boundaries before relying on the script: * A certificate is created only when no active certificate of the inferred type exists. Otherwise the receipt reports `certificateCreationState: "reused"` and has no `p12Path`, so the `jq -e` lookup stops the script under `set -e`. The runner cannot sign with a certificate whose private key lives elsewhere; push that identity once from the machine that holds it, as in [Shared App Store identity](#shared-app-store-identity). * `--create-missing-certificate` fetches one bundle ID and cannot be combined with `--match-extensions`. For an app with extensions, run a second `asc signing fetch --match-extensions --create-missing` into another output directory after the certificate exists. Pass every `profileFile` from its `results` to `profiles local install` and to `xcode signing plan` as repeated `--profile` flags. Push the identity for all of those bundle IDs with `signing sync push --bundle-id com.example.app --match-extensions`, or with a `--targets-file` manifest that lists each bundle ID as in [Shared App Store identity](#shared-app-store-identity); the manifest takes bundle IDs, not profile paths. * `.asc/signing/bootstrap` holds the private key, CSR, and `.p12`. Do not upload it as an artifact. The `.p12` password in this script is a generated secret that exists only for this job; the pushed copy is re-protected with the store password. * `xcode signing plan` exits 0 with `ready: false` when a target has no matching profile, so the script checks `ready`. `xcode signing apply` edits the checked-out project file and refuses a blocked or stale plan. * `sync push` can also create the identity itself: `asc signing sync push --create-missing --create-missing-certificate --identity-password-file PATH`. Use that form in a one-time bootstrap job when you do not want the first run to build. ### Every later run Once the store holds the identity, a fresh runner pulls it instead of creating another certificate. The [CI example](/commands/signing#ci-example) runs `signing sync pull`, `signing keychain install`, `profiles local install`, `xcode signing plan --profile`, `xcode signing apply`, `xcode archive`, and `xcode export` in one step, and removes the keychain afterward. A pulled `.p12` is protected by the store password, not by the bootstrap `.p12` password. ## Registered-device release testing For an iOS archive with extensions or other embedded targets, reconcile the archive against an exact protected device file: ```bash : "${ASC_DISTRIBUTION_CERTIFICATE_ID:?configure the resource ID paired with the synced identity}" chmod 600 .asc/distribution/devices.json asc signing reconcile plan \ --archive-path .asc/artifacts/Example.xcarchive \ --devices-file .asc/distribution/devices.json \ --certificate "$ASC_DISTRIBUTION_CERTIFICATE_ID" \ --minimum-validity-days 14 \ --output json \ --pretty asc signing reconcile apply \ --plan .asc/distribution/signing/plan.json \ --confirm \ --output json > .asc/distribution/signing/apply-result.json ``` Planning is read-only and can return a successful `ready: false` result with blockers. Apply performs only the additive actions recorded in a ready plan; it does not delete profiles, create certificates, or change capabilities. Planning creates `plan.json` without replacing an existing file. If a plan reports blockers, review it and fix them first. Then rerun the same plan command with `--overwrite`, or choose a new `--state-dir` when the blocked plan must remain on disk. `signing run` accepts exactly one profile. Use the temporary-keychain export below only for a single-target archive whose main app uses that profile. When this runs in a later CI step than the pull, recreate the runner-private password file because the pull step's cleanup trap removed its copy: ```bash set +x umask 077 password_file="$RUNNER_TEMP/asc-signing-password" trap 'rm -f "$password_file"' EXIT printf '%s' "$SIGNING_SYNC_PASSWORD" > "$password_file" signing_command=( asc xcode export --archive-path .asc/artifacts/Example.xcarchive --ipa-path .asc/artifacts/Example.ipa --method release-testing --signing-style manual --team-id TEAM_ID ) asc signing run \ --identity .asc/signing/pulled/identities/distribution/IDENTITY.p12 \ --identity-password-file "$password_file" \ --profile .asc/distribution/signing/profiles/PROFILE.mobileprovision \ --receipt .asc/distribution/signing-run.json \ -- "${signing_command[@]}" ``` `signing run` accepts iOS ad hoc profiles with registered devices. It rejects App Store, development, enterprise, macOS, and tvOS profiles. For an archive with extensions, App Clips, Watch apps, or other embedded targets, don't use this single-profile wrapper for export. On a disposable macOS worker, use `asc signing keychain install` for the job-scoped identity, install each completed profile action's `outputPath` from `.asc/distribution/signing/apply-result.json`, export, and discard the worker state when the job ends. ## What the encrypted store does not do The default store is Git. `--storage object` keeps the same ciphertext in an S3 or S3-compatible bucket, with credentials from the standard AWS configuration chain, including workload identity; `--storage gitlab-secure-files` and `--storage aws-secrets-manager` are experimental alternatives. Password rotation supports Git and object storage. The store does not renew certificates or assign different profile types or device sets per target. Profile renewal, device refresh, and one-type cleanup are explicit `sync push` options and `sync nuke`, all Git-only; see [Renew, refresh, and remove synced profiles](/commands/signing#renew-refresh-and-remove-synced-profiles). Per-target Xcode build settings come from `xcode signing plan --profile`, and the dedicated keychain lifecycle is under [Manage a dedicated keychain](/commands/signing#manage-a-dedicated-keychain). Treat certificate rotation as a separate reviewed operation. Renew first, push the successor identity, verify a clean pull, then revoke or deactivate; the ordering is under [Rotation and expiry](/commands/signing#rotation-and-expiry). Read the [signing command reference](/commands/signing) before the first live push; it includes file-permission rules, exact output fields, failure boundaries, profile maintenance, and recovery behavior.