Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codesign Lottie.xcframework #2259

Merged
merged 12 commits into from
Dec 15, 2023
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@ jobs:
- '14.1' # Swift 5.7.1
steps:
- uses: actions/checkout@v2
- uses: apple-actions/import-codesign-certs@v2
with:
p12-file-base64: ${{ secrets.SIGNING_CERTIFICATE_BASE_64 }}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: _BASE64 would be a little more natural spelling, but no strong feelings on that.

p12-password: ${{ secrets.SIGNING_CERTIFICATE_PASSWORD }}
Copy link
Member Author

@calda calda Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed these steps to create a self-signing certificate and installed it as a secret in this repository:

  • Create code signing certificate in Keychain Assistant (instructions)
  • Export .p12 file for the code signing certificate, protected with a password. I also added this password to my iCloud Keychain for future reference in case we need it.
  • Add certificate password as GitHub actions secret (SIGNING_CERTIFICATE_PASSWORD)
  • Convert certificate file to base64, e.g. using base64 -i "Lottie iOS Self Signing.p12".
  • Added base 64 as secret to GitHub repo, e.g. using SIGNING_CERTIFICATE_BASE_64 key

- uses: ./.github/actions/setup
with:
xcode: ${{ matrix.xcode }}
- name: Build XCFramework
# Once there is a production Xcode version with the visionOS SDK, we will
# Once there is a production Xcode version with the visionOS SDK, we will
# need to also build an XCFramework using that version but without `SKIP_VISION_OS=true`
run: SKIP_VISION_OS=true bundle exec rake build:xcframework[Lottie-Xcode-${{ matrix.xcode }}]
- name: Upload XCFramework
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ Lottie supports Swift / Xcode versions back to the minimum version that is permi

Lottie does not collect any data. We provide this notice to help you fill out [App Privacy Details](https://developer.apple.com/app-store/app-privacy-details/). We additionally provide a [privacy manifest](https://github.com/airbnb/lottie-ios/blob/master/PrivacyInfo.xcprivacy) which can be included in your app.

## Security

We distribute XCFramework bundles for each release on [GitHub](https://github.com/airbnb/lottie-ios/releases/latest). In Lottie 4.4.0 and later, these XCFramework bundles include a [code signature](https://developer.apple.com/documentation/xcode/verifying-the-origin-of-your-xcframeworks). These bundles are self-signed under the name "Lottie iOS" and have the following fingerprint:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include some instructions on how someone could use the fingerprint to verify the integrity of their framework artifact?

Copy link
Member Author

@calda calda Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, updated: c7944f6

I couldn't easily find out how to verify this outside of Xcode, e.g. via the command line. Open to suggestions if you have any ideas!

I tried codesign -dv --verbose=4 Lottie.xcframework, but it doesn't show this specific fingerprint string:

Executable=/Users/calstephens/Downloads/BuildProducts/Lottie.xcframework/Info.plist
Identifier=Lottie
Format=bundle
CodeDirectory v=20100 size=183 flags=0x0(none) hashes=1+3 location=embedded
Hash type=sha256 size=32
CandidateCDHash sha1=8e6caf486f23b91f5bbc5eb92c40343ca894cf0d
CandidateCDHashFull sha1=8e6caf486f23b91f5bbc5eb92c40343ca894cf0d
CandidateCDHash sha256=99b40b7bf0ff70ea7abab9e549d3bdd01b26226b
CandidateCDHashFull sha256=99b40b7bf0ff70ea7abab9e549d3bdd01b26226b613be5bca5976e32834aa4f7
Hash choices=sha1,sha256
CMSDigest=4baf8f8e561d838359115d9a23741afeac1a999720d6715a10c5b0238a988081
CMSDigestType=2
Page size=none
CDHash=99b40b7bf0ff70ea7abab9e549d3bdd01b26226b
Signature size=6332
Authority=Lottie iOS
Timestamp=Dec 15, 2023 at 9:15:20 AM
Info.plist entries=3
TeamIdentifier=not set
Sealed Resources version=2 rules=10 files=83
Internal requirements count=1 size=84

Perhaps one of the hashes here corresponds to the fingerprint shown in Xcode via some encoding, but I'm not sure.


```
89 2F 1B 43 04 7B 50 53 8F 2F 46 EA D9 29 00 DD 3D 48 11 F358 21 78 C0 61 A5 FB 20 F1 11 CB 26
```

In Xcode you can verify this by selecting `Lottie.xcframework` and confirming that it shows the following information:

![Code Signature in Xcode](_Gifs/code_signature.png)

## Contributing

We always appreciate contributions from the community. To make changes to the project, you can clone the repo and open `Lottie.xcworkspace`. This workspace includes:
Expand Down
17 changes: 16 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,28 @@ namespace :build do

xcodebuild(xcframeworkInvocation.join(" "))

# Archive the XCFramework into a zip file
Dir.chdir('.build/archives') do
# Codesign the XCFramework using the "Lottie iOS" certificate, which should be installed in the keychain.
# - Check to make sure the certificate is installed before attemtping to codesign.
# - In GitHub actions CI, only jobs run by contibutors have access to repo secrets,
# so PR jobs from external contributors won't have access to this certificate.
# In that case we skip codesigning so the job doesn't fail.
puts "Checking if signing certificate is installed..."
`security find-certificate -c 'Lottie iOS'`
if $?.success?
puts "Signing certificate is installed. Code signing Lottie.xcframework."
sh 'codesign --timestamp -v --sign "Lottie iOS" Lottie.xcframework'
else
puts "Signing certificate is not installed. Lottie.xcframework will not be code signed."
end

# Archive the XCFramework into a zip file
# Use --symlinks to avoid "Multiple binaries share the same codesign path. This can happen if your build process copies frameworks by following symlinks."
# error when validating macOS apps (#1948)
sh "zip -r --symlinks #{args[:zip_archive_name]}.xcframework.zip Lottie.xcframework"
sh 'rm -rf Lottie.xcframework'
end

sh "swift package compute-checksum .build/archives/#{args[:zip_archive_name]}.xcframework.zip"
end
end
Expand Down
Binary file added _Gifs/code_signature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading