This document explains how to work with secrets, certificates, and provisioning profiles in the SparX Wallet Flutter project.
Application secret data is located in the project root in the secrets folder:
├── lib
├── ...
├── secrets/
│ ├── secrets.tar.gpg
│ ├── .secrets.example
│ └── .secrets
secrets.tar.gpg: Encrypted archive containing all confidential data.secrets.example: Template for your own .secrets file.secrets: Your personal secrets file (not committed to the repository)
To set up your local secrets:
- Copy the template:
cp secrets/.secrets.example secrets/.secrets - Fill
.secretswith your credentials:
export SECRET_PASSPHRASE="abc"
export MATCH_PASSWORD="qwerty"
export FASTLANE_USER="example@gmail.com"
export FASTLANE_PASSWORD="pass"
Important notes:
- Never commit your
.secretsfile to the repository FASTLANE_USERandFASTLANE_PASSWORDare your own Apple Developer credentialsSECRET_PASSPHRASEandMATCH_PASSWORDshould be obtained from your teammatesSECRET_PASSPHRASEpassphrase the GPG tarball (with secrets)MATCH_PASSWORD: passphrase for iOS provisioning profiles and certificates. Used for Fastlane's match command.
To decrypt the secrets archive:
melos decrypt-secretsThis command will place the secrets files in the necessary directories: /secrets, /android, and /ios.
When performing a build via Github Actions, secrets are temporarily located in the required folders. After building the application, scripts/clean.sh is run to remove secrets.
- To create a new secrets archive, set up a directory structure:
somefolder/
├── android/
│ ├── your_keystore_name.keystore
│ ├── fastlane/
│ │ ├── GooglePlayServiceAccount.json
│ │ └── key.properties
├── fastlane/
│ ├── FirebaseADKey.json
│ └── FirebaseAPIKey.json
├── ios/
│ ├── fastlane/
│ │ └── YourDeveloperAppleAuthKey.p8
├── secrets/
│ ├── ios-provisioning-key
│ ├── ios-provisioning-key.pub
│ └── sentry-dsn.txt
-
/android/your_keystore_name.keystoreKeystore file in jks format. Used to sign an APK file -
/android/fastlane/GooglePlayServiceAccount.jsonFile with Google service account credentials for interacting with the Google API and Google Play Developer API. -
/android/key.propertiesFile with data for signing APK files. -
/fastlane/FirebaseADKey.jsonNeeded to interact with the Firebase API. Contains data for scripts to interact with Firebase services. -
/fastlane/FirebaseAPIKey.jsonUsed to update the build number in Firebase Realtime Database. -
/ios/fastlane/YourDeveloperAppleAuthKey.p8Required to work with the App Store Connect API. -
/secrets/ios-provisioning-keyProvisioning Profile file -
/secrets/ios-provisioning-key.pubApple public key to run match_assure. -
/secrets/sentry-dsn.txtText file with dns for working with sentry.
- Then create the encrypted archive:
tar -cf secrets.tar *
gpg --symmetric --cipher-algo AES256 secrets.tarTo update existing secrets:
-
Decrypt the archive:
gpg --output secrets.tar --decrypt secrets.tar.gpg
-
Unpack the archive:
tar -xf secrets.tar
-
Update the necessary files and repackage:
tar c * > secrets.tar gpg --symmetric --cipher-algo AES256 secrets.tar
-
Place the resulting file in the
secretsdirectory
Warning: When archiving the contents, exclude unnecessary files like the old .gpg file and your personal .secrets file.
For iOS we use match to manage certificates and provisioning profiles. It's configured in ios/fastlane/Matchfile.
There is no need to manually create certificates and profiles; match will do everything for you and save it.
To renew certificates and provisioning profiles after adding new devices to the Apple Developer Account, run the following command:
melos build:ios_match_new_devicesIf you configuring a new machine, you should run the following command to install certificates and provisioning profiles:
melos build:ios_match_assureThe password for executing match commands is taken from the .secrets/MATCH_PASSWORD file.
Warning: If there are problems with the certificates or they are out of date, use a set of commands to create new certificates:
fastlane match nuke development
fastlane match nuke distribution
melos run build:ios_match_assureThis will not cause problems even if other application certificates are affected.
When running the melos run build:ios_match_assure command through the terminal or another fastlane command that requires entering a 6-digit apple verification code, the code may be ignored by the terminal. Instead of entering code, a line break occurs.
To work around this issue, in the project root or another location, create a text file fastlane_session.txt (the name can be anything).
-
Create a fastlane session token:
touch fastlane_session.txt fastlane spaceauth -u YOUR_APPLE_ID
-
Copy the token to fastlane_session.txt and set an environment variable:
Remove extra characters such as
\n
export FASTLANE_SESSION=$(cat fastlane_session.txt)Example contents of the fastlane_session.txt file:
---
- !ruby/object:HTTP::Cookie
name: abcdefg
value: ABCDEFG111111cf12345a12
for_domain: true
path: "/"
secure: true
httponly: true
expires:
max_age:
created_at: 2024-06-07 23:51:26.367930000 +07:00
accessed_at: 2024-06-07 23:51:26.372267000 +07:00
- !ruby/object:HTTP::Cookie
name: ABCDE
...If cloning the repository takes a long time when running the command melos build:ios_match_new_devices, then possible reasons:
- Insufficient rights. Contact the administrator.
- You need an ssh key.
Variant of fix:
- Ensure you have proper permissions
- Set up an SSH key:
- Create and add an SSH key to GitHub
- Run
cd ~/.ssh/; ssh-addin your terminal
For CI/CD, the following secrets are needed in GitHub repository settings:
BOT_ACCESS_TOKEN: Personal access token (PAT) used to fetch the repository. We should use PAT and not default GITHUB_TOKEN because "When you use the repository's GITHUB_TOKEN to perform tasks, events triggered by the GITHUB_TOKEN, with the exception of workflow_dispatch and repository_dispatch, will not create a new workflow run". We want to trigger a workflow from the workflow (to run tests), so we need to use PAT. This thing is used inversionworkflow.SECRET_PASSPHRASE: Same as in your local.secretsfileMATCH_PASSWORD: Same as in your local.secretsfile
Warning: SECRET_PASSPHRASE needs to be located in CI/CD (when using Github Actions, located in the Secrets of the repository) to decrypt the gpg file.