Skip to content

Commit 6df82a9

Browse files
authored
Codesign XCFrameworks for darwin add to app (#183399)
When the Flutter.xcframework (and various [other plugins flagged as Privacy-impacting](https://developer.apple.com/support/third-party-SDK-requirements/)) are embedded in a native app using our add to app instructions, it is required for them to be code-signed before build. This PR will codesign all produced XCFrameworks with either the the signing identity passed into the command, found through the Flutter app's Xcode project's settings, or found through the Flutter config. If it's unable to find an identity or it finds more than one, it'll throw and ask the user to pass in an identity. See [go/flutter-ios-privacy-impacting-sdks-codesign-requirement](http://goto.google.com/flutter-ios-privacy-impacting-sdks-codesign-requirement) for explanation of code signature requirement. Fixes #148300. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 7189eb4 commit 6df82a9

25 files changed

Lines changed: 2795 additions & 172 deletions

‎dev/devicelab/bin/tasks/build_ios_framework_module_test.dart‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ Future<void> _testBuildIosFramework(Directory projectDir, {bool isModule = false
8989
'--output=$outputDirectoryName',
9090
'--obfuscate',
9191
'--split-debug-info=symbols',
92+
'--codesign-identity',
93+
'-',
9294
],
9395
);
9496
});
@@ -374,6 +376,18 @@ Future<void> _testBuildIosFramework(Directory projectDir, {bool isModule = false
374376
checkFileExists(simulatorHeaderPath);
375377
}
376378

379+
section('Check all XCFrameworks are codesigned');
380+
for (final mode in <String>['Debug', 'Profile', 'Release']) {
381+
final String modePath = path.join(outputPath, mode);
382+
await _checkCodeSignature(path.join(modePath, 'Flutter.xcframework'));
383+
await _checkCodeSignature(path.join(modePath, 'App.xcframework'));
384+
await _checkCodeSignature(path.join(modePath, 'connectivity.xcframework'));
385+
await _checkCodeSignature(path.join(modePath, 'Reachability.xcframework'));
386+
if (isModule) {
387+
await _checkCodeSignature(path.join(modePath, 'FlutterPluginRegistrant.xcframework'));
388+
}
389+
}
390+
377391
// This builds all build modes' frameworks by default
378392
section('Build podspec and static plugins');
379393

@@ -388,6 +402,7 @@ Future<void> _testBuildIosFramework(Directory projectDir, {bool isModule = false
388402
'--force', // Allow podspec creation on master.
389403
'--output=$cocoapodsOutputDirectoryName',
390404
'--static',
405+
'--no-codesign',
391406
],
392407
);
393408
});
@@ -473,6 +488,8 @@ Future<void> _testBuildMacOSFramework(Directory projectDir) async {
473488
'--output=$outputDirectoryName',
474489
'--obfuscate',
475490
'--split-debug-info=symbols',
491+
'--codesign-identity',
492+
'-',
476493
],
477494
);
478495
});
@@ -701,6 +718,15 @@ Future<void> _testBuildMacOSFramework(Directory projectDir) async {
701718
);
702719
}
703720

721+
section('Check all XCFrameworks are codesigned');
722+
for (final mode in <String>['Debug', 'Profile', 'Release']) {
723+
final String modePath = path.join(outputPath, mode);
724+
await _checkCodeSignature(path.join(modePath, 'FlutterMacOS.xcframework'));
725+
await _checkCodeSignature(path.join(modePath, 'App.xcframework'));
726+
await _checkCodeSignature(path.join(modePath, 'connectivity_macos.xcframework'));
727+
await _checkCodeSignature(path.join(modePath, 'Reachability.xcframework'));
728+
}
729+
704730
// This builds all build modes' frameworks by default
705731
section('Build podspec and static plugins');
706732

@@ -715,6 +741,7 @@ Future<void> _testBuildMacOSFramework(Directory projectDir) async {
715741
'--force', // Allow podspec creation on master.
716742
'--output=$cocoapodsOutputDirectoryName',
717743
'--static',
744+
'--no-codesign',
718745
],
719746
);
720747
});
@@ -821,6 +848,7 @@ Future<void> _testBuildFrameworksWithoutPlugins(
821848
'--force', // Allow podspec creation on master.
822849
'--output=$noPluginsOutputDir',
823850
'--no-plugins',
851+
'--no-codesign',
824852
],
825853
);
826854
});
@@ -852,6 +880,7 @@ Future<void> _testStaticAndNoPlugins(Directory projectDir) async {
852880
'--output=$noPluginsOutputDir',
853881
'--no-plugins',
854882
'--static',
883+
'--no-codesign',
855884
],
856885
canFail: true,
857886
);
@@ -886,6 +915,14 @@ Future<void> _checkStatic(String pathToLibrary) async {
886915
}
887916
}
888917

918+
Future<void> _checkCodeSignature(String pathToArtifact) async {
919+
final stderrBuffer = StringBuffer();
920+
await eval('codesign', <String>['-dv', pathToArtifact], canFail: true, stderr: stderrBuffer);
921+
if (stderrBuffer.toString().contains('not signed at all')) {
922+
throw TaskResult.failure('$pathToArtifact is not signed');
923+
}
924+
}
925+
889926
Future<bool> _linksOnFlutter(String pathToBinary) async {
890927
final String loadCommands = await eval('otool', <String>['-l', '-arch', 'arm64', pathToBinary]);
891928
return loadCommands.contains('Flutter.framework');

‎packages/flutter_tools/lib/executable.dart‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ List<FlutterCommand> generateCommands({required bool verboseHelp, required bool
197197
verboseHelp: verboseHelp,
198198
androidSdk: globals.androidSdk,
199199
logger: globals.logger,
200+
config: globals.config,
201+
platform: globals.platform,
202+
fileSystemUtils: globals.fsUtils,
203+
terminal: globals.terminal,
204+
plistParser: globals.plistParser,
205+
processUtils: globals.processUtils,
200206
),
201207
ChannelCommand(verboseHelp: verboseHelp),
202208
CleanCommand(verbose: verbose),

‎packages/flutter_tools/lib/src/commands/build.dart‎

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
import 'package:meta/meta.dart';
66

77
import '../android/android_sdk.dart';
8+
import '../base/config.dart';
89
import '../base/file_system.dart';
910
import '../base/logger.dart';
1011
import '../base/os.dart';
12+
import '../base/platform.dart';
13+
import '../base/process.dart';
14+
import '../base/terminal.dart';
1115
import '../build_system/build_system.dart';
1216
import '../commands/build_linux.dart';
1317
import '../commands/build_macos.dart';
1418
import '../commands/build_windows.dart';
19+
import '../ios/code_signing.dart';
20+
import '../ios/plist_parser.dart';
1521
import '../runner/flutter_command.dart';
1622
import 'build_aar.dart';
1723
import 'build_apk.dart';
@@ -21,6 +27,7 @@ import 'build_ios.dart';
2127
import 'build_ios_framework.dart';
2228
import 'build_macos_framework.dart';
2329
import 'build_web.dart';
30+
import 'darwin_add_to_app.dart';
2431

2532
class BuildCommand extends FlutterCommand {
2633
BuildCommand({
@@ -29,6 +36,12 @@ class BuildCommand extends FlutterCommand {
2936
required OperatingSystemUtils osUtils,
3037
required Logger logger,
3138
required AndroidSdk? androidSdk,
39+
required Config config,
40+
required Platform platform,
41+
required ProcessUtils processUtils,
42+
required FileSystemUtils fileSystemUtils,
43+
required Terminal terminal,
44+
required PlistParser plistParser,
3245
bool verboseHelp = false,
3346
}) {
3447
_addSubcommand(
@@ -43,13 +56,43 @@ class BuildCommand extends FlutterCommand {
4356
_addSubcommand(BuildAppBundleCommand(logger: logger, verboseHelp: verboseHelp));
4457
_addSubcommand(BuildIOSCommand(logger: logger, verboseHelp: verboseHelp));
4558
_addSubcommand(
46-
BuildIOSFrameworkCommand(logger: logger, buildSystem: buildSystem, verboseHelp: verboseHelp),
59+
BuildIOSFrameworkCommand(
60+
logger: logger,
61+
buildSystem: buildSystem,
62+
verboseHelp: verboseHelp,
63+
codesign: DarwinAddToAppCodesigning(
64+
logger: logger,
65+
xcodeCodeSigningSettings: XcodeCodeSigningSettings(
66+
config: config,
67+
logger: logger,
68+
platform: platform,
69+
processUtils: processUtils,
70+
fileSystem: fileSystem,
71+
fileSystemUtils: fileSystemUtils,
72+
terminal: terminal,
73+
plistParser: plistParser,
74+
),
75+
),
76+
),
4777
);
4878
_addSubcommand(
4979
BuildMacOSFrameworkCommand(
5080
logger: logger,
5181
buildSystem: buildSystem,
5282
verboseHelp: verboseHelp,
83+
codesign: DarwinAddToAppCodesigning(
84+
logger: logger,
85+
xcodeCodeSigningSettings: XcodeCodeSigningSettings(
86+
config: config,
87+
logger: logger,
88+
platform: platform,
89+
processUtils: processUtils,
90+
fileSystem: fileSystem,
91+
fileSystemUtils: fileSystemUtils,
92+
terminal: terminal,
93+
plistParser: plistParser,
94+
),
95+
),
5396
),
5497
);
5598
_addSubcommand(BuildIOSArchiveCommand(logger: logger, verboseHelp: verboseHelp));

0 commit comments

Comments
 (0)