appstore-precheck 1.19.0 → 1.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +81 -39
- package/package.json +2 -2
- package/skills/appstore-precheck/SKILL.md +39 -146
- package/skills/appstore-precheck/guidelines-baseline.json +284 -35
- package/skills/appstore-precheck/guidelines-fingerprints.json +307 -93
- package/skills/appstore-precheck/references/finding-commentary.md +93 -0
- package/skills/appstore-precheck/references/methodology.md +56 -19
- package/skills/appstore-precheck/references/optional-review.md +56 -0
- package/skills/appstore-precheck/references/pierre-deep-review.md +292 -47
- package/skills/appstore-precheck/references/review-catalog.json +500 -13
- package/skills/appstore-precheck/references/screenshot-vision-review.md +8 -8
- package/skills/appstore-precheck/references/simulator-dynamic-review.md +72 -12
- package/skills/appstore-precheck/references/typesafe.md +15 -0
- package/skills/appstore-precheck/scripts/artifact-review.sh +10 -0
- package/skills/appstore-precheck/scripts/augment-json.py +29 -0
- package/skills/appstore-precheck/scripts/build-run.sh +5 -0
- package/skills/appstore-precheck/scripts/coverage-sections.sh +6 -0
- package/skills/appstore-precheck/scripts/dynamic-run.sh +94 -9
- package/skills/appstore-precheck/scripts/dynamic.sh +25 -1
- package/skills/appstore-precheck/scripts/evidence.sh +8 -3
- package/skills/appstore-precheck/scripts/findings.sh +8 -0
- package/skills/appstore-precheck/scripts/lib/artifact-review.py +518 -0
- package/skills/appstore-precheck/scripts/lib/asc-client.py +293 -0
- package/skills/appstore-precheck/scripts/lib/build-evidence.py +50 -0
- package/skills/appstore-precheck/scripts/lib/build-exec.py +50 -0
- package/skills/appstore-precheck/scripts/lib/build-plan.py +106 -0
- package/skills/appstore-precheck/scripts/lib/build-plan.sh +15 -0
- package/skills/appstore-precheck/scripts/lib/build-run.py +177 -0
- package/skills/appstore-precheck/scripts/lib/coverage-run.sh +23 -0
- package/skills/appstore-precheck/scripts/lib/coverage-sections.py +244 -0
- package/skills/appstore-precheck/scripts/lib/dyn-demo-login.py +111 -0
- package/skills/appstore-precheck/scripts/lib/dyn-device.sh +32 -4
- package/skills/appstore-precheck/scripts/lib/dyn-explore.py +312 -0
- package/skills/appstore-precheck/scripts/lib/dyn-guideline-capture.py +301 -0
- package/skills/appstore-precheck/scripts/lib/dyn-guidelines.py +112 -0
- package/skills/appstore-precheck/scripts/lib/dyn-guidelines.sh +23 -0
- package/skills/appstore-precheck/scripts/lib/dyn-process.py +75 -0
- package/skills/appstore-precheck/scripts/lib/dyn-quorum.sh +28 -30
- package/skills/appstore-precheck/scripts/lib/dyn-scrub.py +79 -0
- package/skills/appstore-precheck/scripts/lib/dyn-signals.sh +2 -2
- package/skills/appstore-precheck/scripts/lib/metadata-review.py +369 -0
- package/skills/appstore-precheck/scripts/lib/optin-scan.sh +73 -0
- package/skills/appstore-precheck/scripts/lib/optional-records.py +60 -0
- package/skills/appstore-precheck/scripts/lib/runtime-blocking.py +26 -0
- package/skills/appstore-precheck/scripts/lib/safe_write.py +61 -0
- package/skills/appstore-precheck/scripts/lib/scan-guidelines.sh +199 -0
- package/skills/appstore-precheck/scripts/lib/static-guidelines.py +341 -0
- package/skills/appstore-precheck/scripts/lib/static-reader.py +39 -0
- package/skills/appstore-precheck/scripts/metadata-review.sh +4 -0
- package/skills/appstore-precheck/scripts/opt-in-review.py +160 -0
- package/skills/appstore-precheck/scripts/runtime-review.sh +5 -0
- package/skills/appstore-precheck/scripts/scan.sh +56 -23
- package/skills/appstore-precheck/scripts/semantic/client.py +3 -1
- package/skills/appstore-precheck/scripts/semantic/collect.py +82 -38
- package/skills/appstore-precheck/scripts/semantic/engine.py +165 -127
- package/skills/appstore-precheck/scripts/semantic/questions.py +5 -1
- package/skills/appstore-precheck/scripts/semantic/review_v4.py +81 -0
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Read-only inspection of an existing .app, .ipa, or .xcarchive.
|
|
3
|
+
|
|
4
|
+
Results describe evidence, not a blanket App Store approval. Missing build/tool
|
|
5
|
+
evidence is explicitly NOT_RUN/SKIP. No application code is launched.
|
|
6
|
+
"""
|
|
7
|
+
import argparse
|
|
8
|
+
import datetime
|
|
9
|
+
import hashlib
|
|
10
|
+
import fnmatch
|
|
11
|
+
import json
|
|
12
|
+
import pathlib
|
|
13
|
+
import plistlib
|
|
14
|
+
import re
|
|
15
|
+
import shutil
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
import tempfile
|
|
19
|
+
import zipfile
|
|
20
|
+
|
|
21
|
+
CHECKS = (
|
|
22
|
+
"artifact-entitlements", "artifact-reason-api", "artifact-private-api",
|
|
23
|
+
"artifact-url-schemes", "artifact-ats", "artifact-sdk",
|
|
24
|
+
"artifact-embedded-sdk", "artifact-executable-loading", "artifact-debug",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def record(check_id, status, reason, evidence=None):
|
|
29
|
+
return {"check_id": check_id, "status": status, "evidence_class": "artifact",
|
|
30
|
+
"reason": reason, "evidence": evidence or []}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def plist(path):
|
|
34
|
+
try:
|
|
35
|
+
with path.open("rb") as stream:
|
|
36
|
+
return plistlib.load(stream)
|
|
37
|
+
except (OSError, ValueError, TypeError, OverflowError):
|
|
38
|
+
return None
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def tool(name, *args):
|
|
42
|
+
binary = shutil.which(name)
|
|
43
|
+
if not binary:
|
|
44
|
+
return None
|
|
45
|
+
try:
|
|
46
|
+
return subprocess.run([binary] + list(args), stdout=subprocess.PIPE,
|
|
47
|
+
stderr=subprocess.PIPE, timeout=20, check=False)
|
|
48
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def output(result):
|
|
53
|
+
if result is None:
|
|
54
|
+
return ""
|
|
55
|
+
return (result.stdout + b"\n" + result.stderr).decode("utf-8", "replace")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def select_app(path, temp):
|
|
59
|
+
if not path or not path.exists():
|
|
60
|
+
return None, None, "No built artifact was supplied"
|
|
61
|
+
if path.is_dir() and path.suffix == ".app":
|
|
62
|
+
return path, "app", ""
|
|
63
|
+
if path.is_dir() and path.suffix == ".xcarchive":
|
|
64
|
+
apps = sorted((path / "Products" / "Applications").glob("*.app"))
|
|
65
|
+
if len(apps) == 1:
|
|
66
|
+
return apps[0], "xcarchive", ""
|
|
67
|
+
return None, "xcarchive", "Archive must contain exactly one .app"
|
|
68
|
+
if path.is_file() and path.suffix == ".ipa":
|
|
69
|
+
try:
|
|
70
|
+
with zipfile.ZipFile(path) as archive:
|
|
71
|
+
entries = [i for i in archive.infolist() if re.match(r"^Payload/[^/]+\.app/", i.filename)]
|
|
72
|
+
apps = {i.filename.split("/")[1] for i in entries}
|
|
73
|
+
if len(apps) != 1 or not entries:
|
|
74
|
+
return None, "ipa", "IPA must contain exactly one Payload .app"
|
|
75
|
+
if len(entries) > 10000 or sum(i.file_size for i in entries) > 1024 * 1024 * 1024:
|
|
76
|
+
return None, "ipa", "IPA has too many or too-large members"
|
|
77
|
+
root = temp / "Payload" / next(iter(apps))
|
|
78
|
+
for info in entries:
|
|
79
|
+
member = pathlib.PurePosixPath(info.filename)
|
|
80
|
+
if ".." in member.parts or info.file_size > 512 * 1024 * 1024:
|
|
81
|
+
return None, "ipa", "Unsafe or oversized IPA member"
|
|
82
|
+
target = temp.joinpath(*member.parts)
|
|
83
|
+
if info.is_dir():
|
|
84
|
+
target.mkdir(parents=True, exist_ok=True)
|
|
85
|
+
continue
|
|
86
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
87
|
+
with archive.open(info) as src, target.open("wb") as dst:
|
|
88
|
+
shutil.copyfileobj(src, dst)
|
|
89
|
+
return root, "ipa", ""
|
|
90
|
+
except (OSError, zipfile.BadZipFile, RuntimeError):
|
|
91
|
+
return None, "ipa", "Unreadable IPA"
|
|
92
|
+
return None, None, "Expected .app, .ipa, or .xcarchive"
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def code_bundles(app):
|
|
96
|
+
"""Include extension and App Clip executable boundaries, not just the main app."""
|
|
97
|
+
return [app] + sorted(p for p in app.rglob('*') if p.is_dir() and
|
|
98
|
+
p.suffix in ('.appex', '.framework', '.app'))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def embedded_frameworks(app):
|
|
102
|
+
return [p for p in code_bundles(app)[1:] if p.suffix == '.framework']
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def executable(app, info):
|
|
106
|
+
name = info.get("CFBundleExecutable")
|
|
107
|
+
path = app / name if isinstance(name, str) and pathlib.Path(name).name == name else None
|
|
108
|
+
return path if path and path.is_file() else None
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def machos(app, main_binary):
|
|
112
|
+
binaries = [main_binary] if main_binary else []
|
|
113
|
+
for framework in code_bundles(app)[1:]:
|
|
114
|
+
framework_info = plist(framework / "Info.plist")
|
|
115
|
+
if isinstance(framework_info, dict):
|
|
116
|
+
binary = executable(framework, framework_info)
|
|
117
|
+
if binary:
|
|
118
|
+
binaries.append(binary)
|
|
119
|
+
return binaries
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def entitlements(app):
|
|
123
|
+
result = tool("codesign", "-d", "--entitlements", ":-", str(app))
|
|
124
|
+
if result is None:
|
|
125
|
+
return None, "codesign unavailable (install Xcode Command Line Tools)"
|
|
126
|
+
if result.returncode != 0:
|
|
127
|
+
return None, "Code-signing entitlements unavailable; signature not verified"
|
|
128
|
+
raw = result.stdout or result.stderr
|
|
129
|
+
start = raw.find(b"<?xml")
|
|
130
|
+
if start < 0:
|
|
131
|
+
start = raw.find(b"<plist")
|
|
132
|
+
if start < 0:
|
|
133
|
+
return None, "No readable code-signing entitlements (unsigned simulator app or invalid signature)"
|
|
134
|
+
try:
|
|
135
|
+
value = plistlib.loads(raw[start:])
|
|
136
|
+
return value if isinstance(value, dict) else None, ""
|
|
137
|
+
except (ValueError, TypeError, OverflowError):
|
|
138
|
+
return None, "Could not parse code-signing entitlements"
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def review_entitlements(info, ents, error, binary):
|
|
142
|
+
if ents is None:
|
|
143
|
+
return record(CHECKS[0], "SKIP", error)
|
|
144
|
+
issues = []
|
|
145
|
+
if ents.get("com.apple.developer.healthkit") and not any(
|
|
146
|
+
info.get(k) for k in ("NSHealthShareUsageDescription", "NSHealthUpdateUsageDescription")):
|
|
147
|
+
issues.append("HealthKit entitlement without Health usage description")
|
|
148
|
+
modes = info.get("UIBackgroundModes") or []
|
|
149
|
+
if "remote-notification" in modes and not ents.get("aps-environment"):
|
|
150
|
+
issues.append("remote-notification background mode without aps-environment entitlement")
|
|
151
|
+
if ents.get("com.apple.developer.associated-domains") and not isinstance(
|
|
152
|
+
ents.get("com.apple.developer.associated-domains"), list):
|
|
153
|
+
issues.append("associated-domains entitlement is malformed")
|
|
154
|
+
if binary:
|
|
155
|
+
try:
|
|
156
|
+
data = binary.read_bytes()
|
|
157
|
+
if b"HKHealthStore" in data and not ents.get("com.apple.developer.healthkit"):
|
|
158
|
+
issues.append("HealthKit symbol without HealthKit entitlement")
|
|
159
|
+
if b"registerForRemoteNotifications" in data and not ents.get("aps-environment"):
|
|
160
|
+
issues.append("push registration symbol without aps-environment entitlement")
|
|
161
|
+
except OSError:
|
|
162
|
+
pass
|
|
163
|
+
if issues:
|
|
164
|
+
return record(CHECKS[0], "NEEDS_REVIEW", "Entitlements and Info.plist need reconciliation", issues)
|
|
165
|
+
return record(CHECKS[0], "PASS", "No checked entitlement/Info.plist mismatch observed")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# Identifiers checked against Apple's required-reason API documentation, 2026-09-27.
|
|
169
|
+
# Membership does not prove that the declared reason matches actual use.
|
|
170
|
+
REASON_SOURCE = "https://developer.apple.com/documentation/bundleresources/app-privacy-configuration/nsprivacyaccessedapitypes/nsprivacyaccessedapitype"
|
|
171
|
+
APPROVED_REASONS = {
|
|
172
|
+
"NSPrivacyAccessedAPICategoryFileTimestamp": {"DDA9.1", "C617.1", "3B52.1", "0A2A.1"},
|
|
173
|
+
"NSPrivacyAccessedAPICategorySystemBootTime": {"35F9.1", "8FFB.1", "3D61.1"},
|
|
174
|
+
"NSPrivacyAccessedAPICategoryDiskSpace": {"85F4.1", "E174.1", "7D9E.1", "B728.1"},
|
|
175
|
+
"NSPrivacyAccessedAPICategoryActiveKeyboards": {"3EC4.1", "54BD.1"},
|
|
176
|
+
"NSPrivacyAccessedAPICategoryUserDefaults": {"CA92.1", "1C8F.1", "C56D.1", "AC6B.1"},
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
REASON_SYMBOLS = {
|
|
181
|
+
"NSPrivacyAccessedAPICategoryFileTimestamp": ("_stat", "_fstat", "_lstat", "_fstatat", "_getattrlist"),
|
|
182
|
+
"NSPrivacyAccessedAPICategoryDiskSpace": ("_statfs", "_fstatfs", "_statvfs", "_fstatvfs"),
|
|
183
|
+
"NSPrivacyAccessedAPICategoryUserDefaults": ("_OBJC_CLASS_$_NSUserDefaults",),
|
|
184
|
+
"NSPrivacyAccessedAPICategorySystemBootTime": ("_mach_absolute_time",),
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
def review_reasons(app, binary):
|
|
188
|
+
if not binary:
|
|
189
|
+
return record(CHECKS[1], "SKIP", "CFBundleExecutable is missing")
|
|
190
|
+
issues, unavailable = [], []
|
|
191
|
+
for bundle in code_bundles(app):
|
|
192
|
+
label = str(bundle.relative_to(app))
|
|
193
|
+
info = plist(bundle / 'Info.plist')
|
|
194
|
+
candidate = executable(bundle, info) if isinstance(info, dict) else None
|
|
195
|
+
manifest = plist(bundle / "PrivacyInfo.xcprivacy")
|
|
196
|
+
declared = set()
|
|
197
|
+
if manifest is not None:
|
|
198
|
+
rows = manifest.get('NSPrivacyAccessedAPITypes', []) if isinstance(manifest, dict) else None
|
|
199
|
+
if not isinstance(rows, list):
|
|
200
|
+
issues.append(label + ': malformed required-reason API array')
|
|
201
|
+
rows = []
|
|
202
|
+
for item in rows:
|
|
203
|
+
if not isinstance(item, dict):
|
|
204
|
+
issues.append(label + ': malformed required-reason API entry')
|
|
205
|
+
continue
|
|
206
|
+
category = item.get('NSPrivacyAccessedAPIType')
|
|
207
|
+
reasons = item.get('NSPrivacyAccessedAPITypeReasons')
|
|
208
|
+
if not isinstance(category, str) or category not in APPROVED_REASONS:
|
|
209
|
+
issues.append(label + ': unknown API category; compare current Apple documentation')
|
|
210
|
+
elif not isinstance(reasons, list) or not reasons or any(
|
|
211
|
+
not isinstance(reason, str) or reason not in APPROVED_REASONS[category] for reason in reasons):
|
|
212
|
+
issues.append(label + ':' + category + ': empty, malformed or unrecognized reason identifier')
|
|
213
|
+
else:
|
|
214
|
+
declared.add(category)
|
|
215
|
+
elif (bundle / 'PrivacyInfo.xcprivacy').exists():
|
|
216
|
+
issues.append(label + ': unreadable privacy manifest')
|
|
217
|
+
if not candidate:
|
|
218
|
+
unavailable.append(label + ': executable unavailable')
|
|
219
|
+
continue
|
|
220
|
+
result = tool("nm", "-u", str(candidate))
|
|
221
|
+
if result is None or result.returncode != 0:
|
|
222
|
+
unavailable.append(label + ': nm unavailable')
|
|
223
|
+
continue
|
|
224
|
+
symbols = output(result)
|
|
225
|
+
observed = {category for category, needles in REASON_SYMBOLS.items()
|
|
226
|
+
if any(re.search(re.escape(needle) + r"(?:\s|$)", symbols, re.M) for needle in needles)}
|
|
227
|
+
issues.extend(label + ':' + category + ': no valid reason in this code bundle manifest'
|
|
228
|
+
for category in sorted(observed - declared))
|
|
229
|
+
if issues:
|
|
230
|
+
return record(CHECKS[1], "NEEDS_REVIEW",
|
|
231
|
+
"Bundle-local API/reason mismatch; applicability and actual API purpose require review", issues + unavailable)
|
|
232
|
+
if unavailable:
|
|
233
|
+
return record(CHECKS[1], "SKIP", "Could not inspect every code bundle", unavailable)
|
|
234
|
+
return record(CHECKS[1], "PASS", "Mapped bundle-local symbols/reason identifiers are consistent; dynamic use and reason eligibility remain unverified")
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def review_private(app, binary):
|
|
238
|
+
if not binary:
|
|
239
|
+
return record(CHECKS[2], "SKIP", "CFBundleExecutable is missing")
|
|
240
|
+
private, restricted, unavailable = [], [], []
|
|
241
|
+
for candidate in machos(app, binary):
|
|
242
|
+
linked = tool("otool", "-L", str(candidate))
|
|
243
|
+
symbols = tool("nm", "-u", str(candidate))
|
|
244
|
+
if linked is None or linked.returncode != 0:
|
|
245
|
+
unavailable.append(candidate.name + ":otool")
|
|
246
|
+
else:
|
|
247
|
+
private.extend(candidate.name + ":" + line.strip() for line in output(linked).splitlines()
|
|
248
|
+
if "/System/Library/PrivateFrameworks/" in line)
|
|
249
|
+
if symbols is None or symbols.returncode != 0:
|
|
250
|
+
unavailable.append(candidate.name + ":nm")
|
|
251
|
+
elif re.search(r"\b_task_for_pid\b", output(symbols)):
|
|
252
|
+
restricted.append(candidate.name + ":task_for_pid")
|
|
253
|
+
if private:
|
|
254
|
+
return record(CHECKS[2], "FINDING", "App executable directly links a private Apple framework", private)
|
|
255
|
+
if restricted:
|
|
256
|
+
return record(CHECKS[2], "NEEDS_REVIEW", "Restricted symbol observed; verify public API entitlement and use", restricted + unavailable)
|
|
257
|
+
if unavailable:
|
|
258
|
+
return record(CHECKS[2], "SKIP", "otool -L or nm -u unavailable for some Mach-O files (install Xcode Command Line Tools)", unavailable)
|
|
259
|
+
return record(CHECKS[2], "PASS", "No direct private framework linkage observed; selectors resolved at runtime remain unverified")
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def review_schemes(info):
|
|
263
|
+
value = info.get("LSApplicationQueriesSchemes", [])
|
|
264
|
+
if not isinstance(value, list):
|
|
265
|
+
return record(CHECKS[3], "NEEDS_REVIEW", "LSApplicationQueriesSchemes is not an array")
|
|
266
|
+
suspicious = [x for x in value if isinstance(x, str) and x.lower() in
|
|
267
|
+
{"cydia", "sileo", "zbra", "filza"}]
|
|
268
|
+
malformed = [str(x) for x in value if not isinstance(x, str) or not re.fullmatch(r"[A-Za-z][A-Za-z0-9+.-]*", x)]
|
|
269
|
+
if suspicious or malformed:
|
|
270
|
+
return record(CHECKS[3], "NEEDS_REVIEW", "URL scheme queries need purpose and format review", suspicious + malformed)
|
|
271
|
+
return record(CHECKS[3], "PASS", "Declared URL scheme queries have no mapped suspicious or malformed values")
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def review_ats(info):
|
|
275
|
+
ats = info.get("NSAppTransportSecurity", {})
|
|
276
|
+
if not isinstance(ats, dict):
|
|
277
|
+
return record(CHECKS[4], "NEEDS_REVIEW", "NSAppTransportSecurity is malformed")
|
|
278
|
+
exceptions = []
|
|
279
|
+
for key in ("NSAllowsArbitraryLoads", "NSAllowsArbitraryLoadsInWebContent", "NSAllowsLocalNetworking"):
|
|
280
|
+
if ats.get(key):
|
|
281
|
+
exceptions.append(key)
|
|
282
|
+
domains = ats.get("NSExceptionDomains") or {}
|
|
283
|
+
if isinstance(domains, dict):
|
|
284
|
+
exceptions += ["NSExceptionDomains:" + str(d) for d in domains]
|
|
285
|
+
if exceptions:
|
|
286
|
+
return record(CHECKS[4], "NEEDS_REVIEW", "ATS exception requires a documented transport justification", exceptions)
|
|
287
|
+
return record(CHECKS[4], "PASS", "No Info.plist ATS exception observed")
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def version(value):
|
|
291
|
+
if not isinstance(value, str) or not re.fullmatch(r"\d+(?:\.\d+)*", value):
|
|
292
|
+
return None
|
|
293
|
+
return tuple(int(x) for x in value.split("."))
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def review_sdk(info):
|
|
297
|
+
minimum, sdk = info.get("MinimumOSVersion"), info.get("DTSDKName")
|
|
298
|
+
if not version(minimum) or not isinstance(sdk, str) or not re.fullmatch(r"iphone(?:os|simulator)\d+(?:\.\d+)*", sdk):
|
|
299
|
+
return record(CHECKS[5], "NEEDS_REVIEW", "MinimumOSVersion or DTSDKName is missing/malformed",
|
|
300
|
+
["MinimumOSVersion=" + str(minimum), "DTSDKName=" + str(sdk)])
|
|
301
|
+
sdk_version = version(re.search(r"\d+(?:\.\d+)*$", sdk).group())
|
|
302
|
+
if version(minimum) > sdk_version:
|
|
303
|
+
return record(CHECKS[5], "FINDING", "MinimumOSVersion exceeds build SDK version",
|
|
304
|
+
["minimum=" + minimum, "sdk=" + sdk])
|
|
305
|
+
return record(CHECKS[5], "NEEDS_REVIEW", "Versions are internally consistent; compare SDK with Apple's current submission requirement",
|
|
306
|
+
["minimum=" + minimum, "sdk=" + sdk])
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def review_frameworks(app, info):
|
|
310
|
+
frameworks = embedded_frameworks(app)
|
|
311
|
+
if not frameworks:
|
|
312
|
+
return record(CHECKS[6], "PASS", "No embedded frameworks found")
|
|
313
|
+
issues = []
|
|
314
|
+
unverified = []
|
|
315
|
+
simulator = str(info.get("DTSDKName", "")).startswith("iphonesimulator")
|
|
316
|
+
for framework in frameworks:
|
|
317
|
+
if plist(framework / "PrivacyInfo.xcprivacy") is None:
|
|
318
|
+
issues.append(framework.name + ": no readable PrivacyInfo.xcprivacy")
|
|
319
|
+
result = tool("codesign", "--verify", "--strict", str(framework))
|
|
320
|
+
if result is None:
|
|
321
|
+
unverified.append(framework.name + ": codesign unavailable")
|
|
322
|
+
elif result.returncode != 0:
|
|
323
|
+
(unverified if simulator else issues).append(framework.name + ": signature not verified")
|
|
324
|
+
if issues:
|
|
325
|
+
return record(CHECKS[6], "NEEDS_REVIEW", "Embedded SDK manifest/signature review required; not every framework necessarily requires a manifest", issues + unverified)
|
|
326
|
+
if unverified:
|
|
327
|
+
return record(CHECKS[6], "SKIP", "Embedded signature verification unavailable", unverified)
|
|
328
|
+
return record(CHECKS[6], "PASS", "Embedded frameworks contain readable manifests and signatures verified")
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def review_loading(binary):
|
|
332
|
+
if not binary:
|
|
333
|
+
return record(CHECKS[7], "SKIP", "CFBundleExecutable is missing")
|
|
334
|
+
try:
|
|
335
|
+
data = binary.read_bytes()
|
|
336
|
+
except OSError:
|
|
337
|
+
return record(CHECKS[7], "SKIP", "Could not read executable")
|
|
338
|
+
tokens = [name for name, needle in (("download", b"download"), ("executable", b"executable")) if needle in data]
|
|
339
|
+
if {"download", "executable"}.issubset(tokens):
|
|
340
|
+
return record(CHECKS[7], "NEEDS_REVIEW", "Binary strings suggest dynamic loading or downloaded executable content; inspect code path", tokens)
|
|
341
|
+
return record(CHECKS[7], "PASS", "No mapped dynamic loading/download string combination observed")
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def review_debug(app, ents):
|
|
345
|
+
paths = [str(p.relative_to(app)) for p in app.rglob("*") if p.is_file() and
|
|
346
|
+
((p.suffix == ".mobileprovision" and p.name != "embedded.mobileprovision") or p.suffix in (".dSYM", ".xctest") or
|
|
347
|
+
p.name in (".DS_Store", "debug.log"))]
|
|
348
|
+
if ents and ents.get("get-task-allow") is True:
|
|
349
|
+
paths.append("get-task-allow=true")
|
|
350
|
+
if paths:
|
|
351
|
+
return record(CHECKS[8], "NEEDS_REVIEW", "Bundle contains debug/test artifacts or a development entitlement", paths[:30])
|
|
352
|
+
if ents is None:
|
|
353
|
+
return record(CHECKS[8], "SKIP", "No mapped debug files found, but entitlements could not be read")
|
|
354
|
+
return record(CHECKS[8], "PASS", "No mapped debug artifacts or get-task-allow entitlement observed")
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def inspect(app, signatures):
|
|
358
|
+
info = plist(app / "Info.plist")
|
|
359
|
+
if not isinstance(info, dict):
|
|
360
|
+
return [record(c, "SKIP", "App Info.plist is absent or unreadable") for c in CHECKS]
|
|
361
|
+
binary = executable(app, info)
|
|
362
|
+
records, main_ents = [], None
|
|
363
|
+
for bundle, signed in zip(code_bundles(app), signatures):
|
|
364
|
+
if bundle.suffix == '.framework':
|
|
365
|
+
continue
|
|
366
|
+
bundle_info = plist(bundle / 'Info.plist')
|
|
367
|
+
if not isinstance(bundle_info, dict):
|
|
368
|
+
records.append(record(CHECKS[0], 'SKIP', 'Bundle Info.plist unavailable'))
|
|
369
|
+
continue
|
|
370
|
+
ents, error = entitlements(bundle)
|
|
371
|
+
if signed['signature_status'] != 'VERIFIED':
|
|
372
|
+
ents, error = None, 'Signature unavailable or invalid; entitlement inspection cannot establish signed consistency'
|
|
373
|
+
if bundle == app:
|
|
374
|
+
main_ents = ents
|
|
375
|
+
row = review_entitlements(bundle_info, ents, error, executable(bundle, bundle_info))
|
|
376
|
+
if signed['profile_issues']:
|
|
377
|
+
row = record(CHECKS[0], 'NEEDS_REVIEW', 'Decoded provisioning profile and signed entitlement mismatch',
|
|
378
|
+
row['evidence'] + signed['profile_issues'])
|
|
379
|
+
row['evidence'] = [signed['bundle'] + ': ' + entry for entry in row['evidence']]
|
|
380
|
+
records.append(row)
|
|
381
|
+
issues = [entry for row in records if row['status'] == 'NEEDS_REVIEW' for entry in row['evidence']]
|
|
382
|
+
gaps = [row['reason'] for row in records if row['status'] == 'SKIP']
|
|
383
|
+
combined = (record(CHECKS[0], 'NEEDS_REVIEW', 'App/extension entitlement or profile mismatch requires review', issues + gaps)
|
|
384
|
+
if issues else record(CHECKS[0], 'SKIP', 'App/extension signed entitlement inspection incomplete', gaps)
|
|
385
|
+
if gaps else record(CHECKS[0], 'PASS', 'No checked app/extension entitlement or decoded profile mismatch observed'))
|
|
386
|
+
return [combined, review_reasons(app, binary), review_private(app, binary),
|
|
387
|
+
review_schemes(info), review_ats(info), review_sdk(info), review_frameworks(app, info),
|
|
388
|
+
review_loading(binary), review_debug(app, main_ents)]
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def digest_file(path):
|
|
392
|
+
if not path or not path.is_file():
|
|
393
|
+
return None
|
|
394
|
+
digest = hashlib.sha256()
|
|
395
|
+
with path.open('rb') as stream:
|
|
396
|
+
for block in iter(lambda: stream.read(1024 * 1024), b''):
|
|
397
|
+
digest.update(block)
|
|
398
|
+
return digest.hexdigest()
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def identity(app):
|
|
402
|
+
info = plist(app / 'Info.plist') or {}
|
|
403
|
+
if not isinstance(info, dict):
|
|
404
|
+
info = {}
|
|
405
|
+
binary = executable(app, info)
|
|
406
|
+
return {'bundle_id': info.get('CFBundleIdentifier'), 'version': info.get('CFBundleShortVersionString'),
|
|
407
|
+
'build': info.get('CFBundleVersion'), 'binary_sha256': digest_file(binary),
|
|
408
|
+
'info_plist_sha256': digest_file(app / 'Info.plist'), 'sdk': info.get('DTSDKName')}
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def permitted(value, allowed):
|
|
412
|
+
if isinstance(value, str) and isinstance(allowed, str):
|
|
413
|
+
return fnmatch.fnmatchcase(value, allowed)
|
|
414
|
+
if isinstance(value, list) and isinstance(allowed, list):
|
|
415
|
+
return all(any(permitted(item, rule) for rule in allowed) for item in value)
|
|
416
|
+
return type(value) is type(allowed) and value == allowed
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
def signing_evidence(app):
|
|
420
|
+
rows = []
|
|
421
|
+
for bundle in code_bundles(app):
|
|
422
|
+
info = plist(bundle / 'Info.plist') or {}
|
|
423
|
+
if not isinstance(info, dict):
|
|
424
|
+
info = {}
|
|
425
|
+
verified = tool('codesign', '--verify', '--strict', str(bundle))
|
|
426
|
+
details = tool('codesign', '-d', str(bundle))
|
|
427
|
+
# Verification errors alone cannot distinguish unsigned code from invalid signatures.
|
|
428
|
+
present = details is not None and details.returncode == 0
|
|
429
|
+
status = ('UNAVAILABLE' if verified is None else 'UNSIGNED' if not present else
|
|
430
|
+
'VERIFIED' if verified.returncode == 0 else 'INVALID')
|
|
431
|
+
ents, _ = entitlements(bundle)
|
|
432
|
+
issues, gaps = [], []
|
|
433
|
+
if status != 'VERIFIED':
|
|
434
|
+
gaps.append('Code signature not verified')
|
|
435
|
+
if ents is None:
|
|
436
|
+
gaps.append('Entitlements not readable')
|
|
437
|
+
profile_path = bundle / 'embedded.mobileprovision'
|
|
438
|
+
profile = None
|
|
439
|
+
if profile_path.is_file():
|
|
440
|
+
decoded = tool('security', 'cms', '-D', '-i', str(profile_path))
|
|
441
|
+
if decoded is not None and decoded.returncode == 0:
|
|
442
|
+
try:
|
|
443
|
+
profile = plistlib.loads(decoded.stdout)
|
|
444
|
+
except (ValueError, TypeError, OverflowError):
|
|
445
|
+
pass
|
|
446
|
+
if isinstance(profile, dict) and isinstance(profile.get('Entitlements'), dict) and ents is not None:
|
|
447
|
+
allowed = profile['Entitlements']
|
|
448
|
+
for key, value in ents.items():
|
|
449
|
+
if key not in allowed or not permitted(value, allowed[key]):
|
|
450
|
+
issues.append('Entitlement not authorized by decoded profile: ' + key)
|
|
451
|
+
app_id = ents.get('application-identifier')
|
|
452
|
+
bundle_id = info.get('CFBundleIdentifier')
|
|
453
|
+
if not isinstance(app_id, str) or not isinstance(bundle_id, str) or not app_id.endswith('.' + bundle_id):
|
|
454
|
+
issues.append('Signed application identifier does not match bundle identifier')
|
|
455
|
+
expiration = profile.get('ExpirationDate')
|
|
456
|
+
if isinstance(expiration, datetime.datetime):
|
|
457
|
+
if expiration.replace(tzinfo=datetime.timezone.utc) <= datetime.datetime.now(datetime.timezone.utc):
|
|
458
|
+
issues.append('Decoded provisioning profile has expired')
|
|
459
|
+
else:
|
|
460
|
+
gaps.append('Profile expiry unavailable')
|
|
461
|
+
else:
|
|
462
|
+
gaps.append('Embedded provisioning profile consistency not inspected')
|
|
463
|
+
rows.append({'bundle': str(bundle.relative_to(app)), 'signature_status': status,
|
|
464
|
+
'identity': identity(bundle), 'profile_issues': issues, 'gaps': gaps})
|
|
465
|
+
return rows
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
def scope_report(app, args):
|
|
469
|
+
observed = identity(app)
|
|
470
|
+
mismatches = [key for key, value in (('bundle_id', args.expected_bundle),
|
|
471
|
+
('version', args.expected_version), ('build', args.expected_build))
|
|
472
|
+
if value is not None and observed.get(key) != value]
|
|
473
|
+
simulator = str(observed.get('sdk') or '').startswith('iphonesimulator')
|
|
474
|
+
signatures = signing_evidence(app)
|
|
475
|
+
return {'identity': observed, 'identity_matches_expected': not mismatches,
|
|
476
|
+
'identity_expectations_supplied': any(x is not None for x in
|
|
477
|
+
(args.expected_bundle, args.expected_version, args.expected_build)),
|
|
478
|
+
'identity_mismatches': mismatches,
|
|
479
|
+
'evidence_kind': 'simulator_app' if simulator else 'device_artifact',
|
|
480
|
+
'signing': signatures, 'distribution_status': 'NOT_VERIFIED',
|
|
481
|
+
'physical_device_status': 'NOT_RUN', 'source_binding_status': 'NOT_PROVIDED',
|
|
482
|
+
'limitations': ['Signature verification is not App Store distribution eligibility or certificate/profile authority verification.',
|
|
483
|
+
'No physical-device behavior was executed.',
|
|
484
|
+
'API symbols and network domains do not prove complete privacy or tracking compliance.',
|
|
485
|
+
'No source provenance was inferred from the supplied artifact.']}
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
def main():
|
|
489
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
490
|
+
parser.add_argument("--app", help="Existing .app, .ipa, or .xcarchive")
|
|
491
|
+
parser.add_argument("--format", choices=("json", "text"), default="text")
|
|
492
|
+
parser.add_argument('--expected-bundle', help='Expected CFBundleIdentifier; mismatch invalidates identity binding')
|
|
493
|
+
parser.add_argument('--expected-version', help='Expected CFBundleShortVersionString')
|
|
494
|
+
parser.add_argument('--expected-build', help='Expected CFBundleVersion')
|
|
495
|
+
args = parser.parse_args()
|
|
496
|
+
with tempfile.TemporaryDirectory(prefix="appstore-precheck-artifact-") as scratch:
|
|
497
|
+
app, kind, gap = select_app(pathlib.Path(args.app) if args.app else None,
|
|
498
|
+
pathlib.Path(scratch))
|
|
499
|
+
scope = scope_report(app, args) if app else None
|
|
500
|
+
checks = inspect(app, scope["signing"]) if app else [record(c, "NOT_RUN", gap) for c in CHECKS]
|
|
501
|
+
result = {"artifact_type": kind, "artifact": args.app, "executed": False,
|
|
502
|
+
"checks": checks, "scope": scope}
|
|
503
|
+
if args.format == "json":
|
|
504
|
+
print(json.dumps(result, indent=2, sort_keys=True))
|
|
505
|
+
else:
|
|
506
|
+
if app:
|
|
507
|
+
scope = result['scope']
|
|
508
|
+
print('ARTIFACT-SCOPE: {} distribution=NOT_VERIFIED physical=NOT_RUN source=NOT_PROVIDED'.format(scope['evidence_kind']))
|
|
509
|
+
if scope['identity_mismatches']:
|
|
510
|
+
print('ARTIFACT-SKIP: identity mismatch — ' + ', '.join(scope['identity_mismatches']))
|
|
511
|
+
for item in checks:
|
|
512
|
+
print("ARTIFACT-{}: [{}] {} — {}".format(item["status"], item["check_id"],
|
|
513
|
+
item["reason"], "; ".join(item["evidence"])))
|
|
514
|
+
return 0
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
if __name__ == "__main__":
|
|
518
|
+
sys.exit(main())
|