Skip to content
← All articles

12 min read

How to generate an iOS Distribution certificate without a Mac

Create an iOS Distribution certificate and provisioning profile with openssl and the App Store Connect API, no Mac needed, and a .p12 that Keychain accepts.

You have the code. You have a paid Apple Developer account. You have a Windows or Linux laptop, and a CI log that ends with a red line saying no signing certificate was found for “iOS Distribution”. The message is short and sounds like one missing file.

Then you search for the fix. Every answer starts the same way: open Keychain Access, choose Certificate Assistant, request a certificate from a certificate authority. Keychain Access is a Mac application. You close the tab, open another one, and the second answer says the same thing with different screenshots.

That is where the hours go. Not into the problem itself, but into the gap between what the tutorials assume (a Mac) and what you actually have. The good news is that the problem is small once you see its shape. Apple exposes certificates through an HTTP API, and everything else is openssl. This article walks through the whole path, and I tested every command I publish with throwaway keys. At the end I show what pkgr automates, because that is why I know this path well.

Three objects, and who proves what

Most of the pain comes from mixing up three things that sound alike: the certificate, the App ID and the provisioning profile. Each one answers a different question, and the profile is the one that ties the other two together.

The private key is a file you create on your machine. It is the only thing that can produce your signature, so it never leaves you. Apple never sees it. The certificate is Apple’s statement that a given public key belongs to your developer team. You prove ownership of the key by sending Apple a certificate signing request (CSR), which contains the public half and is signed by the private half. Apple returns a certificate that wraps your public key and carries Apple’s own signature.

The App ID, also called the bundle identifier, is a different kind of object. It says that com.example.myapp is a name registered to your team. It has nothing to do with who signs. The provisioning profile is the link: a file signed by Apple that lists which certificate is allowed to sign which App ID. For an Ad Hoc build, it also lists the devices allowed to run it.

Diagram of the signing trust map: private key and certificate on one side, App ID in the middle, provisioning profile joining them, and the device or App Store checking the signed app against the profile.
Who proves what: the key signs, the certificate vouches for the signer, the App ID names the app, the profile joins them.

When you install an app, the device or the App Store runs two checks. Does the signature on the app match a certificate listed in the embedded profile? Does the bundle id in the app match the one in the profile? If both answers are yes, the app is accepted. If either is no, you get one of those vague signing errors.

This map explains most of the confusing messages. “No signing certificate found” usually means the certificate exists on Apple’s side but your build machine does not hold the matching private key. A certificate without its key is a public document. It cannot sign anything.

The limit nobody mentions until it hurts

Apple allows a small number of active distribution certificates per account. For the standard Apple Developer Program, that number is three, and the repo’s own error handling describes it as “generally 3 active”. It is a limit per developer account, not per app.

This matters for two reasons. First, one certificate can sign any app on your account. Only the provisioning profile is tied to a single app. If you create a new certificate for every project, you hit the wall at the fourth one. Second, a lost private key is expensive. The certificate stays on Apple’s side, useless without its key, and the only way forward is to revoke it and create another, which uses a slot. Revoking also invalidates the profiles that used it.

So treat the key and the .p12 you are about to build like the only copy of something important. Back it up somewhere safe, and create one certificate per team, not per app.

The manual path, step by step

Here is the whole flow before the details. Apart from one browser visit, everything happens in a terminal.

Sequence diagram between you, openssl and the App Store Connect API: generate key and CSR, sign a JWT and POST the certificate request, build the p12, then POST the provisioning profile request.
The manual flow: two local steps with openssl, two calls to Apple, and an API key created once in the browser.

You need openssl, curl, jq and Node.js (the JWT script uses only Node’s built-in crypto module, no packages). I ran everything below on macOS with its built-in LibreSSL 3.3.6 and throwaway keys. A note on that comes later, because it matters for the .p12.

Step 1: create an App Store Connect API key

In App Store Connect, go to Users and Access, then Integrations, then App Store Connect API, and generate a key. Choose a role that can manage certificates. I use Admin. Apple lets you download the .p8 file only once, so save it immediately. Note the Key ID shown next to the key and the Issuer ID shown at the top of the page.

This is the one step you cannot script. There is no API to create an API key, which is why even the automated version of this flow starts here.

Step 2: create a private key and a CSR

openssl genrsa -out ios_dist.key 2048
openssl req -new -key ios_dist.key -out ios_dist.csr -subj "/CN=My Team Distribution"

The first command creates a 2048-bit RSA key, which is what Apple expects. The second builds the CSR and signs it with that key. The common name is only a label. Keep ios_dist.key somewhere private and backed up. You can check the CSR with openssl req -in ios_dist.csr -noout -verify.

Step 3: sign a JWT for the API

Every App Store Connect request carries a short-lived token signed with your .p8 key. The algorithm is ES256, the header holds your Key ID, and the payload holds your Issuer ID, an issue time, an expiry time and the audience appstoreconnect-v1. Apple caps the lifetime at 20 minutes. I use 15.

You can do this in shell, but ES256 signatures from openssl come out in DER form and JWT wants the raw form, so a few lines of Node are simpler. Save this as asc-jwt.mjs:

import { createPrivateKey, sign } from 'node:crypto';
import { readFileSync } from 'node:fs';

const [keyFile, keyId, issuerId] = process.argv.slice(2);
const b64url = (v) => Buffer.from(v).toString('base64url');

const now = Math.floor(Date.now() / 1000);
const header = { alg: 'ES256', kid: keyId, typ: 'JWT' };
const payload = { iss: issuerId, iat: now, exp: now + 15 * 60, aud: 'appstoreconnect-v1' };

const input = `${b64url(JSON.stringify(header))}.${b64url(JSON.stringify(payload))}`;
const signature = sign('sha256', Buffer.from(input), {
  key: createPrivateKey(readFileSync(keyFile)),
  dsaEncoding: 'ieee-p1363',
});
console.log(`${input}.${b64url(signature)}`);

Then generate a token and keep it in a variable:

JWT=$(node asc-jwt.mjs AuthKey_ABC123DEFG.p8 ABC123DEFG your-issuer-id)

I tested the script with a throwaway P-256 key and verified the signature against the public key. The dsaEncoding: 'ieee-p1363' option is the detail that matters. Without it, the signature has the wrong format and Apple will refuse the token.

Step 4: ask Apple to sign your CSR

The certificate request is a JSON body with the type IOS_DISTRIBUTION and your CSR as a plain PEM string. Let jq handle the escaping of the line breaks:

jq -n --rawfile csr ios_dist.csr \
  '{data:{type:"certificates",attributes:{certificateType:"IOS_DISTRIBUTION",csrContent:$csr}}}' \
  > cert-request.json

curl -sS -X POST https://api.appstoreconnect.apple.com/v1/certificates \
  -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" \
  -d @cert-request.json -o cert-response.json

If you already have the maximum number of certificates, Apple answers with a 409. Revoke one you no longer use and try again. On success the response contains the certificate id and the certificate itself as base64-encoded DER. Keep the id, you need it for the profile. Then turn the content into files:

jq -r .data.id cert-response.json
jq -r .data.attributes.certificateContent cert-response.json | base64 --decode > ios_distribution.cer
openssl x509 -inform der -in ios_distribution.cer -out ios_distribution.pem

Before going further, check that the certificate matches your key. If these two commands print the same public key, you are fine:

diff <(openssl x509 -in ios_distribution.pem -noout -pubkey) <(openssl pkey -in ios_dist.key -pubout) && echo match

Step 5: assemble a .p12 that Keychain accepts

A .p12 file bundles the certificate and the private key under one password. It is what a macOS build machine imports to sign with. And this is the step where the quiet failure lives.

openssl pkcs12 -export -inkey ios_dist.key -in ios_distribution.pem \
  -name "iOS Distribution" \
  -certpbe PBE-SHA1-3DES -keypbe PBE-SHA1-3DES -macalg sha1 \
  -out ios_distribution.p12

Those three algorithm flags are the point. I explain why in the next section. openssl asks for an export password. Pick a long one and store it next to the file.

You can confirm what you built without any Mac: openssl pkcs12 -in ios_distribution.p12 -info -noout should list pbeWithSHA1And3-KeyTripleDES-CBC for the key bag.

Step 6: register the App ID and create the profile

First, find the App ID’s Apple-side id. The filter matches by text, so select the exact identifier:

curl -sS -G https://api.appstoreconnect.apple.com/v1/bundleIds \
  -H "Authorization: Bearer $JWT" \
  --data-urlencode "filter[identifier]=com.example.myapp" -o bundle.json
BUNDLE_ID=$(jq -r --arg id com.example.myapp '.data[] | select(.attributes.identifier==$id) | .id' bundle.json)

If that returns nothing, the App ID does not exist yet. Create it with a POST to /v1/bundleIds with {"data":{"type":"bundleIds","attributes":{"identifier":"com.example.myapp","name":"My App","platform":"IOS"}}}, and use the id in the response.

Then create the profile. This request is where the trust map becomes a JSON document: one App ID, one certificate, and a type.

jq -n --arg b "$BUNDLE_ID" --arg c "$CERT_ID" \
  '{data:{type:"profiles",attributes:{name:"MyApp App Store",profileType:"IOS_APP_STORE"},
    relationships:{bundleId:{data:{type:"bundleIds",id:$b}},
                   certificates:{data:[{type:"certificates",id:$c}]}}}}' > profile-request.json

curl -sS -X POST https://api.appstoreconnect.apple.com/v1/profiles \
  -H "Authorization: Bearer $JWT" -H "Content-Type: application/json" \
  -d @profile-request.json -o profile-response.json
jq -r .data.attributes.profileContent profile-response.json | base64 --decode > MyApp_AppStore.mobileprovision

CERT_ID is the id you kept in step 4. Use IOS_APP_STORE for TestFlight and App Store builds. For an Ad Hoc profile, use IOS_APP_ADHOC and add a devices relationship listing the registered device ids. Profile names must be unique, and the API cannot edit an existing profile, so regenerating one means deleting the old one and creating it again.

Step 7: use the files on a macOS runner

You now hold a .p12, its password and a .mobileprovision. The build runs on a macOS machine, for example a GitHub-hosted runner. There it creates a temporary keychain, imports the .p12 with security import, copies the profile to ~/Library/MobileDevice/Provisioning Profiles/, and calls xcodebuild. I cover that last part in deploy-to-testflight-from-a-git-push.

Why the .p12 fails with OpenSSL 3 defaults

Here is the quiet failure. A .p12 file has three parts: a bag with the certificate, a bag with the encrypted private key, and a MAC that protects the whole file against tampering. Both the encryption and the MAC are derived from your password, and each part names the algorithm it uses.

OpenSSL 3 changed the defaults. According to the OpenSSL documentation, it now encrypts with AES-256-CBC using PBKDF2, and the MAC uses SHA-256. The older behavior, with 3DES or RC2, is behind the -legacy flag. That is good cryptography. But the Keychain importer on macOS only accepted the older dialect in my tests. So a file made with a fresh OpenSSL 3 install and no flags looks fine, passes openssl pkcs12 -info, and then fails on the Mac.

Diagram of a .p12 split into certificate bag, key bag and MAC, wrapped either with OpenSSL 3 defaults (AES-256 with PBKDF2 and a SHA-256 MAC) which fails Keychain import, or with legacy 3DES and SHA-1, which imports.
Same key and certificate, two wrappings. Only the legacy one is read by Keychain.

I could not run OpenSSL 3 itself on this machine, which ships with LibreSSL 3.3.6. So I reproduced the failure by forcing the same algorithm choices on LibreSSL, then imported each file into a throwaway keychain with security import. The result was consistent. With a SHA-256 MAC, the import failed with MAC verification failed during PKCS12 import (wrong password?). The password was correct. With AES encryption and a SHA-1 MAC, it failed with Unknown format in import. With 3DES encryption and a SHA-1 MAC, it printed 1 identity imported.

The misleading “wrong password” message is the real trap. You will check the password three times before you suspect the file format.

This is why the command in step 5 sets all three algorithms explicitly. On OpenSSL 3 you can also add -legacy, but that flag needs the legacy provider to be available, and some builds do not ship it. The explicit flags avoid that dependency. If you use OpenSSL 3 and the import still fails, run openssl pkcs12 -info -noout on the file and look for AES or PBKDF2.

What breaks, and what I could not test

Two limits, plainly. The Apple-side calls in steps 4 and 6 come from the implementation in pkgr’s repo, which makes the same calls. I did not re-run them against Apple for this article. I tested everything local: the CSR, the JWT signature, the JSON bodies, the base64 and DER conversion, the key match check and the .p12 import. And as said above, the OpenSSL 3 behavior is reproduced through LibreSSL with forced algorithms, not through OpenSSL 3 itself.

The .p12 also holds only your certificate, not Apple’s intermediate certificate. On a Mac that already trusts it, this is fine. pkgr’s own workflow does not import the intermediate separately, and signing works on GitHub’s macOS runners.

What pkgr automates, and what it does not

I built all of this into pkgr because I did not want anyone to repeat these seven steps for every Apple account. The wizard does the same work through the same Apple endpoints.

Side by side comparison of the manual seven-step path with openssl and the four-step pkgr wizard, both starting with the browser-only API key creation.
Same Apple API on both sides. The wizard removes the scripting, not the one manual step.

You still create the API key in App Store Connect yourself and paste the Issuer ID, Key ID and .p8 into pkgr. Then the RSA-2048 key is generated in your browser with the Web Crypto API, and the private key is never sent to the server. Only the CSR goes to the API. The CSR itself is built in the browser with node-forge. The backend signs a JWT with the .p8, calls POST /v1/certificates with the type IOS_DISTRIBUTION, and hands the certificate back. The .p12 is then assembled in the browser, again with node-forge, using 3DES to stay readable by Keychain. I picked node-forge over pkijs for that reason: pkijs only writes the modern encryption that Keychain rejects. The password is random, generated in the browser, and stored encrypted.

The certificate belongs to the Apple team, not to a single project, because of the three-certificate limit. Every project under that team reuses it. The provisioning profile is generated per app: pkgr finds or creates the App ID, then creates an IOS_APP_ADHOC profile for staging builds and an IOS_APP_STORE profile for production. If Apple answers with a 409 on the certificate, you get a message about the certificate limit, not a raw API error.

There are limits here too. If you upload your own .p12 instead of generating one, pkgr has no Apple certificate id for it, so automatic profile generation is switched off for that case. The API key step stays manual. And the wizard changes nothing about the rule from the start of this article: lose the private key, and the certificate is gone.

One next step

If you only needed to unblock a build, you can stop here and use the commands above. They work without pkgr.

If you would rather not maintain them, pkgr.app builds, signs and ships iOS apps from your GitHub repository, including the certificate and profile steps above. Early access is open at pkgr.app/early-access. The Founder offer is 100 spots, USD 149 paid once, for lifetime access to the Starter plan. Usage limits still apply. After the 100 spots, Starter goes monthly (USD 9 per month at the time of writing). If no build has been made by December 31, 2026, you get a full automatic refund.

Keep reading

If you want to see where the .p12 and the profile end up, deploy-to-testflight-from-a-git-push shows the GitHub Actions side. For the longer story of what went wrong while I built the automation, read what-i-learned-automating-ios-code-signing.