@@ -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.
19191962Future <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' } '
0 commit comments