@@ -61,9 +61,74 @@ bool checkCacheIsCurrent() {
61
61
}
62
62
}
63
63
64
- void main () {
65
- final List <String > failures = < String > [];
64
+ List <String > get binariesWithEntitlements => List <String >.unmodifiable (< String > [
65
+ 'idevice_id' ,
66
+ 'ideviceinfo' ,
67
+ 'idevicename' ,
68
+ 'idevicescreenshot' ,
69
+ 'idevicesyslog' ,
70
+ 'libimobiledevice.6.dylib' ,
71
+ 'ideviceinstaller' ,
72
+ 'libplist.3.dylib' ,
73
+ 'iproxy' ,
74
+ 'libusbmuxd.4.dylib' ,
75
+ 'libssl.1.0.0.dylib' ,
76
+ 'libcrypto.1.0.0.dylib' ,
77
+ 'libzip.5.0.dylib' ,
78
+ 'libzip.5.dylib' ,
79
+ 'gen_snapshot' ,
80
+ 'dart' ,
81
+ 'flutter_tester' ,
82
+ 'gen_snapshot_arm64' ,
83
+ 'gen_snapshot_armv7' ,
84
+ ]);
85
+
86
+ List <String > get expectedEntitlements => List <String >.unmodifiable (< String > [
87
+ 'com.apple.security.cs.allow-jit' ,
88
+ 'com.apple.security.cs.allow-unsigned-executable-memory' ,
89
+ 'com.apple.security.cs.allow-dyld-environment-variables' ,
90
+ 'com.apple.security.network.client' ,
91
+ 'com.apple.security.network.server' ,
92
+ 'com.apple.security.cs.disable-library-validation' ,
93
+ ]);
94
+
95
+
96
+ /// Check if the binary has the expected entitlements.
97
+ bool hasExpectedEntitlements (String binaryPath) {
98
+ try {
99
+ final ProcessResult entitlementResult = Process .runSync (
100
+ 'codesign' ,
101
+ < String > [
102
+ '--display' ,
103
+ '--entitlements' ,
104
+ ':-' ,
105
+ binaryPath,
106
+ ],
107
+ );
108
+
109
+ if (entitlementResult.exitCode != 0 ) {
110
+ print ('The `codesign --entitlements` command failed with exit code ${entitlementResult .exitCode }:\n '
111
+ '${entitlementResult .stderr }\n ' );
112
+ return false ;
113
+ }
66
114
115
+ bool passes = true ;
116
+ final String output = entitlementResult.stdout as String ;
117
+ for (final String entitlement in expectedEntitlements) {
118
+ final bool entitlementExpected = binariesWithEntitlements.contains (path.basename (binaryPath));
119
+ if (output.contains (entitlement) != entitlementExpected) {
120
+ print ('File "$binaryPath " ${entitlementExpected ? 'does not have expected' : 'has unexpected' } entitlement $entitlement .' );
121
+ passes = false ;
122
+ }
123
+ }
124
+ return passes;
125
+ } catch (e) {
126
+ print (e);
127
+ return false ;
128
+ }
129
+ }
130
+
131
+ void main () {
67
132
if (! Platform .isMacOS) {
68
133
print ('Error! Expected operating system "macos", actual operating system '
69
134
'is: "${Platform .operatingSystem }"' );
@@ -78,28 +143,45 @@ void main() {
78
143
exit (1 );
79
144
}
80
145
146
+ final List <String > unsignedBinaries = < String > [];
147
+ final List <String > wrongEntitlementBinaries = < String > [];
81
148
for (final String binaryPath in findBinaryPaths (cacheDirectory)) {
82
149
print ('Verifying the code signature of $binaryPath ' );
83
- final ProcessResult result = Process .runSync (
150
+ final ProcessResult codeSignResult = Process .runSync (
84
151
'codesign' ,
85
152
< String > [
86
153
'-vvv' ,
87
154
binaryPath,
88
155
],
89
156
);
90
- if (result .exitCode != 0 ) {
91
- failures .add (binaryPath);
157
+ if (codeSignResult .exitCode != 0 ) {
158
+ unsignedBinaries .add (binaryPath);
92
159
print ('File "$binaryPath " does not appear to be codesigned.\n '
93
- 'The `codesign` command failed with exit code ${result .exitCode }:\n '
94
- '${result .stderr }\n ' );
160
+ 'The `codesign` command failed with exit code ${codeSignResult .exitCode }:\n '
161
+ '${codeSignResult .stderr }\n ' );
162
+ continue ;
163
+ } else {
164
+ print ('Verifying entitlements of $binaryPath ' );
165
+ if (! hasExpectedEntitlements (binaryPath)) {
166
+ wrongEntitlementBinaries.add (binaryPath);
167
+ }
95
168
}
96
169
}
97
170
98
- if (failures.isNotEmpty) {
99
- print ('Found ${failures .length } unsigned binaries.' );
100
- failures.forEach (print);
171
+ if (unsignedBinaries.isNotEmpty) {
172
+ print ('Found ${unsignedBinaries .length } unsigned binaries:' );
173
+ unsignedBinaries.forEach (print);
174
+ }
175
+
176
+ if (wrongEntitlementBinaries.isNotEmpty) {
177
+ print ('Found ${wrongEntitlementBinaries .length } binaries with unexpected entitlements:' );
178
+ wrongEntitlementBinaries.forEach (print);
179
+ }
180
+
181
+ if (unsignedBinaries.isNotEmpty) {
182
+ // TODO(jmagman): Also exit if `wrongEntitlementBinaries.isNotEmpty` after https://github.com/flutter/flutter/issues/46704 is done.
101
183
exit (1 );
102
184
}
103
185
104
- print ('Verified that binaries are codesigned.' );
186
+ print ('Verified that binaries are codesigned and have expected entitlements .' );
105
187
}
0 commit comments