Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8001abe

Browse files
authoredMar 20, 2020
Add entitlement checks to codesigning test (flutter#52919)
1 parent 284e3ba commit 8001abe

File tree

1 file changed

+93
-11
lines changed

1 file changed

+93
-11
lines changed
 

‎dev/bots/codesign.dart

Lines changed: 93 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,74 @@ bool checkCacheIsCurrent() {
6161
}
6262
}
6363

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+
}
66114

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() {
67132
if (!Platform.isMacOS) {
68133
print('Error! Expected operating system "macos", actual operating system '
69134
'is: "${Platform.operatingSystem}"');
@@ -78,28 +143,45 @@ void main() {
78143
exit(1);
79144
}
80145

146+
final List<String> unsignedBinaries = <String>[];
147+
final List<String> wrongEntitlementBinaries = <String>[];
81148
for (final String binaryPath in findBinaryPaths(cacheDirectory)) {
82149
print('Verifying the code signature of $binaryPath');
83-
final ProcessResult result = Process.runSync(
150+
final ProcessResult codeSignResult = Process.runSync(
84151
'codesign',
85152
<String>[
86153
'-vvv',
87154
binaryPath,
88155
],
89156
);
90-
if (result.exitCode != 0) {
91-
failures.add(binaryPath);
157+
if (codeSignResult.exitCode != 0) {
158+
unsignedBinaries.add(binaryPath);
92159
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+
}
95168
}
96169
}
97170

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.
101183
exit(1);
102184
}
103185

104-
print('Verified that binaries are codesigned.');
186+
print('Verified that binaries are codesigned and have expected entitlements.');
105187
}

0 commit comments

Comments
 (0)
Please sign in to comment.