Signing a package is a multi-step process.
- Generate a signing request.
- Generate Developer ID Installer certificate.
- Sign the macOS PKG file.
Steps to Generate a Signing Request
For generating a certificate, first of all you require a Certificate Signing Request (CSR) file.
- Open “Keychain Access” program within your macOS device.
- Click on Keychain Access appearing on the top menu bar.
- Go to Certificate Assistant > Request a Certificate From a Certificate Authority.
- Add your email address in the User Email Address field, and name in the Common Name field. Leave the CA Email Address field blank.
- Under the Request is option, click Saved to Disc.
- Click Continue.
- Specify the location on the device where the .csr file is to be saved and click Save.
The signing request will be saved to your machine in the specified location. This file is required to generate the “Developer ID Installer” certificate.
Steps to Generate Developer ID Installer Certificate
To generate the certificate:
- Go to Apple Developer Portal. Click on Accounts.
- Either create a new account or sign in using an existing account.
- Click on Certificates > IDs > Profiles.
- Click on Certificates + and select Developer ID Installer.
- Upload the Certificate Signing Request which was downloaded in the above step.
- The Developer ID Installer certificate will be generated. Download the certificate and install it on your macOS device to sign the packages.
Steps to Build and Sign a macOS PKG file
To build and sign a macOS PKG file for a third-party app,
- Install the app on the device.
- Open “Terminal”.
- Build the .pkg file using the pkgbuild command.
pkgbuild --component /path_to_installed_app/macapp.app --install-location /Applications --sign "Developer ID Installer: *******" /path_to_saved_package/packagename.pkg
Here, the quoted text refers to the name of your certificate. The two arguments specify the location of the already installed .app file (/path_to_installed_app/macapp.app) and the location of the newly generated .pkg file (/path_to_saved_package/packagename.pkg), respectively.
- Sign the .pkg file using the productbuild command.
productbuild --package /path_to_saved_package/packagename.pkg --content /path_to_app/ --sign "Developer ID Installer: *******" /path_to_signed_pkg/signed.pkg
Here, the quoted text refers to the name of the certificate. The two arguments specify the location of the newly generated .pkg file (/path_to_saved_package/packagename.pkg) and the location of the signed .pkg file (/path_to_signed_pkg/signed.pkg), respectively.
Steps to sign macOS PKG files
To sign a macOS PKG file,
- Open “Keychain Access” within the Mac and locate the certificate. The name of the certificate should be of the format: Developer ID Installer: Apple account name (serial number).
- Open “Terminal”. The command to sign the package should look something like this:
productsign -sign “Developer ID Installer: Your Apple Account Name (**********)” ~/Desktop/example.pkg ~/Desktop/signed-example.pkg
Here, the quoted text following the –sign tag refers to the name of your certificate. The two arguments, following the name of the certificate, refer to the current location of the unsigned package (/Desktop/example.pkg) and the location of the signed package (/Desktop/signed-example.pkg), respectively.
The signed certificate gets stored in the destination path specified in the command. Now you can upload it to the app inventory.