Skip to content

Commit 899f423

Browse files
authored
Test codesigning xcframeworks in artifacts (#142666)
On the beta branch: ``` Verifying the code signature of /Users/m/Projects/flutter/bin/cache/artifacts/engine/ios-profile/extension_safe/Flutter.xcframework Verifying the code signature of /Users/m/Projects/flutter/bin/cache/artifacts/engine/ios-profile/Flutter.xcframework Verifying the code signature of /Users/m/Projects/flutter/bin/cache/artifacts/engine/ios/extension_safe/Flutter.xcframework Verifying the code signature of /Users/m/Projects/flutter/bin/cache/artifacts/engine/ios/Flutter.xcframework Verifying the code signature of /Users/m/Projects/flutter/bin/cache/artifacts/engine/ios-release/extension_safe/Flutter.xcframework Verifying the code signature of /Users/m/Projects/flutter/bin/cache/artifacts/engine/ios-release/Flutter.xcframework ``` Fixes #140934
1 parent d242d13 commit 899f423

2 files changed

Lines changed: 153 additions & 40 deletions

File tree

‎dev/bots/test.dart‎

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,7 @@ const List<String> expectedEntitlements = <String>[
16881688
///
16891689
/// This list should be kept in sync with the actual contents of Flutter's
16901690
/// cache.
1691-
Future<List<String>> binariesWithEntitlements(String flutterRoot) async {
1691+
List<String> binariesWithEntitlements(String flutterRoot) {
16921692
return <String> [
16931693
'artifacts/engine/android-arm-profile/darwin-x64/gen_snapshot',
16941694
'artifacts/engine/android-arm-release/darwin-x64/gen_snapshot',
@@ -1729,7 +1729,7 @@ Future<List<String>> binariesWithEntitlements(String flutterRoot) async {
17291729
///
17301730
/// This list should be kept in sync with the actual contents of Flutter's
17311731
/// cache.
1732-
Future<List<String>> binariesWithoutEntitlements(String flutterRoot) async {
1732+
List<String> binariesWithoutEntitlements(String flutterRoot) {
17331733
return <String>[
17341734
'artifacts/engine/darwin-x64-profile/FlutterMacOS.framework/Versions/A/FlutterMacOS',
17351735
'artifacts/engine/darwin-x64-release/FlutterMacOS.framework/Versions/A/FlutterMacOS',
@@ -1755,6 +1755,22 @@ Future<List<String>> binariesWithoutEntitlements(String flutterRoot) async {
17551755
.map((String relativePath) => path.join(flutterRoot, 'bin', 'cache', relativePath)).toList();
17561756
}
17571757

1758+
/// xcframeworks that are expected to be codesigned.
1759+
///
1760+
/// This list should be kept in sync with the actual contents of Flutter's
1761+
/// cache.
1762+
List<String> signedXcframeworks(String flutterRoot) {
1763+
return <String>[
1764+
'artifacts/engine/ios-profile/Flutter.xcframework',
1765+
'artifacts/engine/ios-profile/extension_safe/Flutter.xcframework',
1766+
'artifacts/engine/ios-release/Flutter.xcframework',
1767+
'artifacts/engine/ios-release/extension_safe/Flutter.xcframework',
1768+
'artifacts/engine/ios/Flutter.xcframework',
1769+
'artifacts/engine/ios/extension_safe/Flutter.xcframework',
1770+
]
1771+
.map((String relativePath) => path.join(flutterRoot, 'bin', 'cache', relativePath)).toList();
1772+
}
1773+
17581774
/// Verify the existence of all expected binaries in cache.
17591775
///
17601776
/// This function ignores code signatures and entitlements, and is intended to
@@ -1769,21 +1785,19 @@ Future<void> verifyExist(
17691785
final Set<String> foundFiles = <String>{};
17701786
final String cacheDirectory = path.join(flutterRoot, 'bin', 'cache');
17711787

1772-
1773-
17741788
for (final String binaryPath
17751789
in await findBinaryPaths(cacheDirectory, processManager: processManager)) {
1776-
if ((await binariesWithEntitlements(flutterRoot)).contains(binaryPath)) {
1790+
if (binariesWithEntitlements(flutterRoot).contains(binaryPath)) {
17771791
foundFiles.add(binaryPath);
1778-
} else if ((await binariesWithoutEntitlements(flutterRoot)).contains(binaryPath)) {
1792+
} else if (binariesWithoutEntitlements(flutterRoot).contains(binaryPath)) {
17791793
foundFiles.add(binaryPath);
17801794
} else {
17811795
throw Exception(
17821796
'Found unexpected binary in cache: $binaryPath');
17831797
}
17841798
}
17851799

1786-
final List<String> allExpectedFiles = await binariesWithEntitlements(flutterRoot) + await binariesWithoutEntitlements(flutterRoot);
1800+
final List<String> allExpectedFiles = binariesWithEntitlements(flutterRoot) + binariesWithoutEntitlements(flutterRoot);
17871801
if (foundFiles.length < allExpectedFiles.length) {
17881802
final List<String> unfoundFiles = allExpectedFiles
17891803
.where(
@@ -1807,71 +1821,76 @@ Future<void> verifySignatures(
18071821
String flutterRoot,
18081822
{@visibleForTesting ProcessManager processManager = const LocalProcessManager()}
18091823
) async {
1810-
final List<String> unsignedBinaries = <String>[];
1824+
final List<String> unsignedFiles = <String>[];
18111825
final List<String> wrongEntitlementBinaries = <String>[];
1812-
final List<String> unexpectedBinaries = <String>[];
1826+
final List<String> unexpectedFiles = <String>[];
18131827
final String cacheDirectory = path.join(flutterRoot, 'bin', 'cache');
18141828

1815-
for (final String binaryPath
1816-
in await findBinaryPaths(cacheDirectory, processManager: processManager)) {
1829+
final List<String> binariesAndXcframeworks =
1830+
(await findBinaryPaths(cacheDirectory, processManager: processManager)) + (await findXcframeworksPaths(cacheDirectory, processManager: processManager));
1831+
1832+
for (final String pathToCheck in binariesAndXcframeworks) {
18171833
bool verifySignature = false;
18181834
bool verifyEntitlements = false;
1819-
if ((await binariesWithEntitlements(flutterRoot)).contains(binaryPath)) {
1835+
if (binariesWithEntitlements(flutterRoot).contains(pathToCheck)) {
18201836
verifySignature = true;
18211837
verifyEntitlements = true;
18221838
}
1823-
if ((await binariesWithoutEntitlements(flutterRoot)).contains(binaryPath)) {
1839+
if (binariesWithoutEntitlements(flutterRoot).contains(pathToCheck)) {
1840+
verifySignature = true;
1841+
}
1842+
if (signedXcframeworks(flutterRoot).contains(pathToCheck)) {
18241843
verifySignature = true;
18251844
}
18261845
if (!verifySignature && !verifyEntitlements) {
1827-
unexpectedBinaries.add(binaryPath);
1828-
print('Unexpected binary $binaryPath found in cache!');
1846+
unexpectedFiles.add(pathToCheck);
1847+
print('Unexpected binary or xcframework $pathToCheck found in cache!');
18291848
continue;
18301849
}
1831-
print('Verifying the code signature of $binaryPath');
1850+
print('Verifying the code signature of $pathToCheck');
18321851
final io.ProcessResult codeSignResult = await processManager.run(
18331852
<String>[
18341853
'codesign',
18351854
'-vvv',
1836-
binaryPath,
1855+
pathToCheck,
18371856
],
18381857
);
18391858
if (codeSignResult.exitCode != 0) {
1840-
unsignedBinaries.add(binaryPath);
1859+
unsignedFiles.add(pathToCheck);
18411860
print(
1842-
'File "$binaryPath" does not appear to be codesigned.\n'
1861+
'File "$pathToCheck" does not appear to be codesigned.\n'
18431862
'The `codesign` command failed with exit code ${codeSignResult.exitCode}:\n'
18441863
'${codeSignResult.stderr}\n',
18451864
);
18461865
continue;
18471866
}
18481867
if (verifyEntitlements) {
1849-
print('Verifying entitlements of $binaryPath');
1850-
if (!(await hasExpectedEntitlements(binaryPath, flutterRoot, processManager: processManager))) {
1851-
wrongEntitlementBinaries.add(binaryPath);
1868+
print('Verifying entitlements of $pathToCheck');
1869+
if (!(await hasExpectedEntitlements(pathToCheck, flutterRoot, processManager: processManager))) {
1870+
wrongEntitlementBinaries.add(pathToCheck);
18521871
}
18531872
}
18541873
}
18551874

18561875
// First print all deviations from expectations
1857-
if (unsignedBinaries.isNotEmpty) {
1858-
print('Found ${unsignedBinaries.length} unsigned binaries:');
1859-
unsignedBinaries.forEach(print);
1876+
if (unsignedFiles.isNotEmpty) {
1877+
print('Found ${unsignedFiles.length} unsigned files:');
1878+
unsignedFiles.forEach(print);
18601879
}
18611880

18621881
if (wrongEntitlementBinaries.isNotEmpty) {
1863-
print('Found ${wrongEntitlementBinaries.length} binaries with unexpected entitlements:');
1882+
print('Found ${wrongEntitlementBinaries.length} files with unexpected entitlements:');
18641883
wrongEntitlementBinaries.forEach(print);
18651884
}
18661885

1867-
if (unexpectedBinaries.isNotEmpty) {
1868-
print('Found ${unexpectedBinaries.length} unexpected binaries in the cache:');
1869-
unexpectedBinaries.forEach(print);
1886+
if (unexpectedFiles.isNotEmpty) {
1887+
print('Found ${unexpectedFiles.length} unexpected files in the cache:');
1888+
unexpectedFiles.forEach(print);
18701889
}
18711890

18721891
// Finally, exit on any invalid state
1873-
if (unsignedBinaries.isNotEmpty) {
1874-
throw Exception('Test failed because unsigned binaries detected.');
1892+
if (unsignedFiles.isNotEmpty) {
1893+
throw Exception('Test failed because unsigned files detected.');
18751894
}
18761895

18771896
if (wrongEntitlementBinaries.isNotEmpty) {
@@ -1881,10 +1900,10 @@ Future<void> verifySignatures(
18811900
);
18821901
}
18831902

1884-
if (unexpectedBinaries.isNotEmpty) {
1885-
throw Exception('Test failed because unexpected binaries found in the cache.');
1903+
if (unexpectedFiles.isNotEmpty) {
1904+
throw Exception('Test failed because unexpected files found in the cache.');
18861905
}
1887-
print('Verified that binaries are codesigned and have expected entitlements.');
1906+
print('Verified that files are codesigned and have expected entitlements.');
18881907
}
18891908

18901909
/// Find every binary file in the given [rootDirectory].
@@ -1915,6 +1934,30 @@ Future<List<String>> findBinaryPaths(
19151934
return allBinaryPaths;
19161935
}
19171936

1937+
/// Find every xcframework in the given [rootDirectory].
1938+
Future<List<String>> findXcframeworksPaths(
1939+
String rootDirectory,
1940+
{@visibleForTesting ProcessManager processManager = const LocalProcessManager()
1941+
}) async {
1942+
final io.ProcessResult result = await processManager.run(
1943+
<String>[
1944+
'find',
1945+
rootDirectory,
1946+
'-type',
1947+
'd',
1948+
'-name',
1949+
'*xcframework',
1950+
],
1951+
);
1952+
final List<String> allXcframeworkPaths = LineSplitter.split(result.stdout as String)
1953+
.where((String s) => s.isNotEmpty)
1954+
.toList();
1955+
for (final String path in allXcframeworkPaths) {
1956+
print('Found: $path\n');
1957+
}
1958+
return allXcframeworkPaths;
1959+
}
1960+
19181961
/// Check mime-type of file at [filePath] to determine if it is binary.
19191962
Future<bool> isBinary(
19201963
String filePath,
@@ -1959,7 +2002,7 @@ Future<bool> hasExpectedEntitlements(
19592002
final String output = entitlementResult.stdout as String;
19602003
for (final String entitlement in expectedEntitlements) {
19612004
final bool entitlementExpected =
1962-
(await binariesWithEntitlements(flutterRoot)).contains(binaryPath);
2005+
binariesWithEntitlements(flutterRoot).contains(binaryPath);
19632006
if (output.contains(entitlement) != entitlementExpected) {
19642007
print(
19652008
'File "$binaryPath" ${entitlementExpected ? 'does not have expected' : 'has unexpected'} '

‎dev/bots/test/codesign_test.dart‎

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import './common.dart';
1111

1212
void main() async {
1313
const String flutterRoot = '/a/b/c';
14-
final List<String> allExpectedFiles = await binariesWithEntitlements(flutterRoot) + await binariesWithoutEntitlements(flutterRoot);
14+
final List<String> allExpectedFiles = binariesWithEntitlements(flutterRoot) + binariesWithoutEntitlements(flutterRoot);
1515
final String allFilesStdout = allExpectedFiles.join('\n');
16-
final List<String> withEntitlements = await binariesWithEntitlements(flutterRoot);
16+
final List<String> allExpectedXcframeworks = signedXcframeworks(flutterRoot);
17+
final String allXcframeworksStdout = allExpectedXcframeworks.join('\n');
18+
final List<String> withEntitlements = binariesWithEntitlements(flutterRoot);
1719

1820
group('verifyExist', () {
1921
test('Not all files found', () async {
@@ -74,8 +76,8 @@ void main() async {
7476
});
7577
});
7678

77-
group('findBinaryPaths', () {
78-
test('All files found', () async {
79+
group('find paths', () {
80+
test('All binary files found', () async {
7981
final List<FakeCommand> commandList = <FakeCommand>[];
8082
final FakeCommand findCmd = FakeCommand(
8183
command: const <String>[
@@ -117,7 +119,26 @@ void main() async {
117119
final ProcessManager processManager = FakeProcessManager.list(commandList);
118120
final List<String> foundFiles = await findBinaryPaths('$flutterRoot/bin/cache', processManager: processManager);
119121
expect(foundFiles, <String>[]);
120-
});
122+
});
123+
124+
test('All xcframeworks files found', () async {
125+
final List<FakeCommand> commandList = <FakeCommand>[
126+
FakeCommand(
127+
command: const <String>[
128+
'find',
129+
'$flutterRoot/bin/cache',
130+
'-type',
131+
'd',
132+
'-name',
133+
'*xcframework',
134+
],
135+
stdout: allXcframeworksStdout,
136+
)
137+
];
138+
final ProcessManager processManager = FakeProcessManager.list(commandList);
139+
final List<String> foundFiles = await findXcframeworksPaths('$flutterRoot/bin/cache', processManager: processManager);
140+
expect(foundFiles, allExpectedXcframeworks);
141+
});
121142

122143
group('isBinary', () {
123144
test('isTrue', () async {
@@ -223,6 +244,19 @@ void main() async {
223244
)
224245
);
225246
}
247+
commandList.add(
248+
FakeCommand(
249+
command: const <String>[
250+
'find',
251+
'$flutterRoot/bin/cache',
252+
'-type',
253+
'd',
254+
'-name',
255+
'*xcframework',
256+
],
257+
stdout: allXcframeworksStdout,
258+
),
259+
);
226260
for (final String expectedFile in allExpectedFiles) {
227261
commandList.add(
228262
FakeCommand(
@@ -248,6 +282,18 @@ void main() async {
248282
);
249283
}
250284
}
285+
286+
for (final String expectedXcframework in allExpectedXcframeworks) {
287+
commandList.add(
288+
FakeCommand(
289+
command: <String>[
290+
'codesign',
291+
'-vvv',
292+
expectedXcframework,
293+
],
294+
)
295+
);
296+
}
251297
final ProcessManager processManager = FakeProcessManager.list(commandList);
252298
await expectLater(verifySignatures(flutterRoot, processManager: processManager), completes);
253299
});
@@ -276,6 +322,19 @@ void main() async {
276322
)
277323
);
278324
}
325+
commandList.add(
326+
FakeCommand(
327+
command: const <String>[
328+
'find',
329+
'$flutterRoot/bin/cache',
330+
'-type',
331+
'd',
332+
'-name',
333+
'*xcframework',
334+
],
335+
stdout: allXcframeworksStdout,
336+
),
337+
);
279338
for (final String expectedFile in allExpectedFiles) {
280339
commandList.add(
281340
FakeCommand(
@@ -300,6 +359,17 @@ void main() async {
300359
);
301360
}
302361
}
362+
for (final String expectedXcframework in allExpectedXcframeworks) {
363+
commandList.add(
364+
FakeCommand(
365+
command: <String>[
366+
'codesign',
367+
'-vvv',
368+
expectedXcframework,
369+
],
370+
)
371+
);
372+
}
303373
final ProcessManager processManager = FakeProcessManager.list(commandList);
304374

305375
expect(

0 commit comments

Comments
 (0)