Skip to content

Commit 9d25562

Browse files
committed
Adding MacOs signing artifact generation guide
1 parent f2adf07 commit 9d25562

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

synapse-electron/README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,128 @@ When incrementing the desktop application for a release, there are **2 versions*
264264
- **IMPORTANT**: Check the "Set as a pre-release" checkbox
265265

266266
**Note**: Replace `X.Y.Z` with the actual semantic version numbers (e.g., `1.2.3`).
267+
268+
269+
270+
# macOS Code Signing: Artifact Generation Guide
271+
272+
**Focus:** Developer ID Application Certificate (for signing `.app` bundles)
273+
274+
## Phase 1: Generating the Request (CSR)
275+
276+
*Context:* You must generate a certificate signing request on your local Mac to create the Private Key.
277+
278+
1. **Open Keychain Access** and go to **Certificate Assistant** \> **Request a Certificate From a Certificate Authority...**
279+
2. **Generate Request:**
280+
* **User Email:** Your Apple ID email.
281+
* **Common Name:** `[Company] App Signer` (Use a distinct name).
282+
* **Request is:** Saved to disk.
283+
* **Save as:** `Application_Request.csr`.
284+
285+
> **Crucial:** Do not delete the new **Private Key** (named `[Company] App Signer`) that appears in your Keychain. This is the "lock" waiting for the certificate.
286+
287+
-----
288+
289+
## Phase 2: The Apple Portal Handoff
290+
291+
*Context:* The Account Holder must use the specific file generated above.
292+
293+
**Instructions for Account Holder:**
294+
295+
1. **Revoke** any previous/failed certificates to prevent confusion.
296+
2. Go to **Certificates**, click **(+)**.
297+
3. Select **Developer ID Application**.
298+
4. Upload `Application_Request.csr`.
299+
5. **Download and send back** the resulting `.cer` file (e.g., `developerID_application.cer`).
300+
301+
-----
302+
303+
## Phase 3: Import & Export (The Keychain Step)
304+
305+
*Context:* You must pair the downloaded certificate with your local private key and export it.
306+
307+
1. **Import:** Double-click the `.cer` file to install it into your **login** keychain.
308+
2. **Force Combine & Export:**
309+
* Select the **"All Items"** tab in Keychain Access.
310+
* Search for your Common Name (e.g., "App Signer").
311+
* Hold **Command (⌘)** and select **BOTH** the **Developer ID Application Certificate** AND the matching **Private Key**.
312+
* **Right-click** on the highlighted selection \> **Export 2 items...**.
313+
* **File Format:** `.p12`.
314+
* **Save as:** `certificate-application.p12`.
315+
* **Password:** Set a temporary password (e.g., `temp123`). *You will need this in the next step.*
316+
317+
-----
318+
319+
## Phase 4: Re-encrypt for CI/CD (The OpenSSL Step)
320+
321+
*Context:* Legacy `.p12` files exported from macOS often use RC2-40-CBC encryption, which causes "MAC verification failed" errors in modern GitHub Actions runners. You must re-encrypt the file using AES-256.
322+
323+
**Run the following commands in your terminal where you saved `certificate-application.p12`:**
324+
325+
### Step 1: Extract Certificate and Private Key
326+
327+
*Note: Replace `OLD_COMPLEX_PASSWORD` with the password you set in Phase 3.*
328+
329+
```bash
330+
# Extract certificate (use -legacy flag to handle macOS RC2-40-CBC encryption)
331+
openssl pkcs12 -legacy -in certificate-application.p12 -clcerts -nokeys -out cert.pem -passin pass:'OLD_COMPLEX_PASSWORD'
332+
333+
# Extract private key
334+
openssl pkcs12 -legacy -in certificate-application.p12 -nocerts -out key.pem -passin pass:'OLD_COMPLEX_PASSWORD' -passout pass:temppass
335+
```
336+
337+
### Step 2: Re-encrypt with Modern AES-256-CBC
338+
339+
*Note: Replace `NEW_SIMPLE_PASSWORD` with a strong, simple password (avoid special characters like $ or \! to prevent shell escaping issues in CI).*
340+
341+
```bash
342+
# Create new p12 with AES-256-CBC encryption and SHA256 MAC
343+
openssl pkcs12 -export \
344+
-out certificate-new.p12 \
345+
-inkey key.pem \
346+
-in cert.pem \
347+
-passin pass:temppass \
348+
-passout pass:'NEW_SIMPLE_PASSWORD' \
349+
-keypbe AES-256-CBC \
350+
-certpbe AES-256-CBC \
351+
-macalg sha256
352+
```
353+
354+
### Step 3: Verify and Encode
355+
356+
Validate the file before uploading to GitHub.
357+
358+
```bash
359+
# 1. Test that the new password works
360+
openssl pkcs12 -in certificate-new.p12 -nokeys -passin pass:'NEW_SIMPLE_PASSWORD' -passout pass:dummy -info -nodes
361+
362+
# 2. Clean up temp files
363+
rm key.pem cert.pem
364+
365+
# 3. Create the Base64 String for GitHub Secrets (No newlines)
366+
base64 -i certificate-new.p12 | tr -d '\n' > cert_single_line.b64
367+
```
368+
369+
> **Expected Verification Output:**
370+
> You should see `PKCS7 Encrypted data: PBES2, PBKDF2, AES-256-CBC` and `MAC: sha256`.
371+
372+
-----
373+
374+
## Phase 5: Final Artifact Checklist
375+
376+
You are ready to configure GitHub Actions. Ensure you have these items saved:
377+
378+
1. [ ] **`cert_single_line.b64`** (The file content to paste into GitHub Secret `MACOS_CERTIFICATE`)
379+
2. [ ] **`NEW_SIMPLE_PASSWORD`** (The string to paste into GitHub Secret `MACOS_CERTIFICATE_PASSWORD`)
380+
3. [ ] **Team ID** (e.g., `A1B2C3D4E5`)
381+
4. [ ] **App-Specific Password** (for Notarization)
382+
383+
-----
384+
385+
## Troubleshooting
386+
387+
| Issue | Cause | Solution |
388+
| :--- | :--- | :--- |
389+
| **"MAC verification failed"** | The .p12 uses legacy RC2 encryption or the password has special characters escaping in shell. | Perform **Phase 4** exactly as written. Ensure `NEW_SIMPLE_PASSWORD` does not contain complex shell characters. |
390+
| **Orphaned Key** | Certificate and Key exist but won't export together. | Use the **"Force Combine"** method in Phase 3 (Select both items manually + Right Click). |
391+
| **"Attribute specified more than once"** | Reusing an old CSR file on Apple's portal. | Generate a fresh CSR in Phase 1. |

0 commit comments

Comments
 (0)