Skip to content

Commit 41f9235

Browse files
committed
Merge branch 'update-build-instructions'
2 parents 8b6acc5 + 8f3d94a commit 41f9235

File tree

1 file changed

+73
-59
lines changed

1 file changed

+73
-59
lines changed

ios/BuildInstructions.md

+73-59
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,53 @@
1-
# Create private key and Certificate Signing Request (CSR)
1+
## Dependencies
22

3-
## Create new private key and CSR
3+
One needs Go v1.19 and the latest stable rust to build the app.
4+
Go can be installed via
5+
```bash
6+
brew install go@1.19
7+
```
8+
9+
Rust should be installed via [rustup](https://rustup.rs). Once rust is
10+
installed, do not forget to install the iOS targets:
11+
12+
```bash
13+
rustup target install aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios
14+
```
15+
Pick between the ARM or x86 simulator targets, selecting the one that matches
16+
the host system.
17+
18+
Once both rust and go are installed, ensure they are available in your path.
19+
20+
## Configure Xcode project
21+
22+
Copy template files of Xcode build configuration:
23+
24+
```
25+
for file in ./ios/Configurations/*.template ; do cp $file ${file//.template/} ; done
26+
```
27+
28+
Template files provide our team ID and correct provisioning profiles and generally do not require
29+
any changes when configuring our build server or developer machines for members of Mullvad
30+
development team. In all other cases perform the following steps to configure the project:
31+
32+
1. Edit `Base.xcconfig` and fill in your Apple development team ID, which can be found on Apple
33+
developer portal in the top right corner next to your organization name (uppercase letters and
34+
digits).
35+
1. Edit `App.xcconfig` and `PacketTunnel.xcconfig` and supply the names of your provisioning profiles
36+
for development (Debug) and distribution (Release).
37+
1. Edit `Screenshots.xcconfig` and supply the name of your provisioning profile. We only specify
38+
development profile here as we never build UI testing targets for distribution. Skip this step if
39+
you do not intend to generate screenshots for the app.
40+
41+
Ensure you have a valid build profile for a development build for both
42+
MullvadVPN and PacketTunnel, both need the
43+
`packet-tunnel-provider-systemextension` NetworkExtension entitlement.
444

5-
OpenSSL will ask you the password for the private key, make sure to memorize it, you'll need it
45+
# The following instructions are only relevant for release builds.
46+
47+
## Create private key and Certificate Signing Request (CSR)
48+
### Create new private key and CSR
49+
50+
OpenSSL will ask you the password for the private key, make sure to memorize it, you'll need it
651
later.
752

853
```
@@ -13,7 +58,7 @@ openssl req -new -newkey rsa:2048 \
1358
-subj "/C=SE/O=<ORGANIZATION_NAME>/emailAddress=<YOUR_EMAIL>"
1459
```
1560

16-
## [Alternative] Create CSR using an existing private key
61+
### [Alternative] Create CSR using an existing private key
1762

1863
```
1964
openssl req -new \
@@ -23,15 +68,15 @@ openssl req -new \
2368
-subj "/C=SE/O=<ORGANIZATION_NAME>/emailAddress=<YOUR_EMAIL>"
2469
```
2570

26-
# Upload Certificate Signing Request (CSR) to Apple
71+
## Upload Certificate Signing Request (CSR) to Apple
2772

2873
1. Go to https://developer.apple.com/account/resources/certificates/list
2974
1. Click the plus button (+) in the heading to create a new certificate
3075
1. Select "Apple Distribution" option from the given list, press "Continue"
3176
1. Select the previously created `cert_signing_request` file for upload
3277
1. Download the provided `distribution.cer` on disk
3378

34-
# Download Apple WWDR certificate
79+
## Download Apple WWDR certificate
3580

3681
WWDR certificate is used to verify the development and distribution certificates issued by Apple.
3782

@@ -51,7 +96,7 @@ openssl x509 -inform der -outform pem \
5196
-out AppleWWDRCAG3.pem
5297
```
5398

54-
# Export private key and certificates
99+
## Export private key and certificates
55100

56101
Produce a PKCS12 container with the private key and all certificates. You will be asked to enter two
57102
passphrases:
@@ -60,7 +105,7 @@ passphrases:
60105
1. Export passphrase for PKCS12 file
61106

62107
You can store the produced `apple_code_signing.p12` file as a backup to be able to restore the keys
63-
in the event of hardware failure. However you should always be able to re-create everything from
108+
in the event of hardware failure. However you should always be able to re-create everything from
64109
scratch.
65110

66111
```
@@ -72,11 +117,11 @@ openssl pkcs12 -export \
72117
-name "<FRIENDLY_KEYCHAIN_NAME>"
73118
```
74119

75-
# Remove old private key and certificates from Keychain
120+
## Remove old private key and certificates from Keychain
76121

77122
__Skip this section if you create the private key for the very first time.__
78123

79-
If you happen to re-create the keys, you will have to remove the old keys and certificates from
124+
If you happen to re-create the keys, you will have to remove the old keys and certificates from
80125
Keychain.
81126

82127
You can list all certificates with corresponding keys by using the following command:
@@ -93,33 +138,33 @@ Valid identities only
93138
2) <HASH_ID> "Apple Development: <COMPANY NAME> (<TEAM ID>)"
94139
```
95140

96-
Pick the one that you don't want anymore and copy the `<HASH_ID>` from the output, then paste into
141+
Pick the one that you don't want anymore and copy the `<HASH_ID>` from the output, then paste into
97142
the command below:
98143

99144
```
100145
security delete-identity -Z <HASH_ID>
101146
```
102147

103-
This should take care of removing both private keys and certificates. Repeat as many times as needed
148+
This should take care of removing both private keys and certificates. Repeat as many times as needed
104149
if you wish to remove multiple identities.
105150

106-
# Import private key and certificates into Keychain
151+
## Import private key and certificates into Keychain
107152

108153
```
109154
security import apple_code_signing.p12 -f pkcs12 \
110155
-T /usr/bin/codesign \
111156
-P <EXPORT_PASSPHRASE>
112157
```
113158

114-
Note: `-T /usr/bin/codesign` instructs Keychain to suppress password prompt during code signing,
115-
although you still have to unlock Keychain for that to have any effect. This instruction is
116-
equivalent to choosing "Always allow" in the password prompt GUI on the first run of `codesign`
159+
Note: `-T /usr/bin/codesign` instructs Keychain to suppress password prompt during code signing,
160+
although you still have to unlock Keychain for that to have any effect. This instruction is
161+
equivalent to choosing "Always allow" in the password prompt GUI on the first run of `codesign`
117162
tool.
118163

119-
Note: providing the export passphrase using the `-P` flag is considered unsafe.
164+
Note: providing the export passphrase using the `-P` flag is considered unsafe.
120165
Leave the `-P <EXPORT_PASSPHRASE>` out to enter the passphrase via GUI.
121166

122-
Technically after that you can clean up all created keys and certificates since all of them are
167+
Technically after that you can clean up all created keys and certificates since all of them are
123168
securely stored in Keychain now.
124169

125170
```
@@ -130,7 +175,7 @@ rm distribution.{pem,cer} \
130175
private_key.pem
131176
```
132177

133-
# Create iOS provisioning profiles
178+
## Create iOS provisioning profiles
134179

135180
We will now create the provisioning profiles listed below using the Apple developer console.
136181

@@ -145,14 +190,14 @@ Follow these steps to add each of provisioning profiles:
145190
1. Click the plus button (+) in the heading to create a new provisioning profile
146191
1. Choose "App Store" under "Distribution", then hit "Continue"
147192
1. Choose the App ID (see the table above) and hit "Continue"
148-
1. Choose the distribution certificate that you had created after uploading the CSR
193+
1. Choose the distribution certificate that you had created after uploading the CSR
149194
(i.e `<ORGANIZATION_NAME> (Distribution)`)
150195
1. Type in the profile name (see the table above) and hit "Generate"
151-
1. Download the certificate in `ios/iOS Provisioning Profiles` directory. Create the directory if it
152-
does not exist.
153-
196+
1. Download the certificate in `ios/iOS Provisioning Profiles` directory. Create the directory if it
197+
does not exist.
198+
154199
Note: you can use a different directory for storing provisioning profiles, however in that case,
155-
make sure to provide the path to the custom location via `IOS_PROVISIONING_PROFILES_DIR`
200+
make sure to provide the path to the custom location via `IOS_PROVISIONING_PROFILES_DIR`
156201
environment variable when running `build.sh` (more on that later).
157202

158203
# Setup AppStore credentials
@@ -166,8 +211,8 @@ environment variables:
166211

167212
`IOS_APPLE_ID_PASSWORD` accepts a keychain reference in form of `@keychain:<KEYCHAIN_ITEM_NAME>`.
168213

169-
Use the app specific password instead of the actual account password and save it to Keychain.
170-
The app specific password can be created via [Apple ID website] and added to Keychain using the
214+
Use the app specific password instead of the actual account password and save it to Keychain.
215+
The app specific password can be created via [Apple ID website] and added to Keychain using the
171216
following command (note that `altool` will be authorized to access the saved password):
172217

173218
```
@@ -178,38 +223,7 @@ xcrun altool --store-password-in-keychain-item <KEYCHAIN_ITEM_NAME> \
178223

179224
[Apple ID website]: https://appleid.apple.com/account/manage
180225

181-
# Configure Xcode project
182-
183-
Copy template files of Xcode build configuration:
184-
185-
```
186-
for file in ./ios/Configurations/*.template ; do cp $file ${file//.template/} ; done
187-
```
188-
189-
Template files provide our team ID and correct provisioning profiles and generally do not require
190-
any changes when configuring our build server or developer machines for members of Mullvad
191-
development team. In all other cases perform the following steps to configure the project:
192-
193-
1. Edit `Base.xcconfig` and fill in your Apple development team ID, which can be found on Apple
194-
developer portal in the top right corner next to your organization name (uppercase letters and
195-
digits).
196-
1. Edit `App.xcconfig` and `PacketTunnel.xcconfig` and supply the names of your provisioning profiles
197-
for development (Debug) and distribution (Release).
198-
1. Edit `Api.xcconfig` to supply the endpoint that will be used to reach the Mullvad API.
199-
1. Edit `Screenshots.xcconfig` and supply the name of your provisioning profile. We only specify
200-
development profile here as we never build UI testing targets for distribution. Skip this step if
201-
you do not intend to generate screenshots for the app.
202-
203-
# Automated build and deployment
204-
205-
Build script does not bump the build number, so make sure to edit `Configurations/Version.xcconfig`
206-
and commit it back to repo.
207-
208-
1. Run `./ios/build.sh` to build and export the app for upload to AppStore.
209-
1. Run `./ios/build.sh --deploy` - same as above but also uploads the app to AppStore and
210-
makes it available over TestFlight.
211-
212-
# Keychain quirks
226+
## Keychain quirks
213227

214228
It's possible that `codesign` will keep throwing the password prompts for Keychain, in that case try
215229
running the following commands __after__ importing the credentials into Keychain:
@@ -219,7 +233,7 @@ security unlock-keychain <KEYCHAIN>
219233
security set-key-partition-list -S apple-tool:,apple: -s <KEYCHAIN>
220234
```
221235

222-
where `<KEYCHAIN>` is the name of the target Keychain where the signing credentials are stored.
236+
where `<KEYCHAIN>` is the name of the target Keychain where the signing credentials are stored.
223237
This guide does not use a separate Keychain store, so use `login.keychain-db` then.
224238

225239
Reference: https://docs.travis-ci.com/user/common-build-problems/#mac-macos-sierra-1012-code-signing-errors

0 commit comments

Comments
 (0)