PulseCanvas / app · pulsecanvas.ai / scripts / validate-store-artifact.py
| 1 | #!/usr/bin/env python3 |
| 2 | """Fail closed on malformed store bundles; --local accepts the Apple Development sandbox test.""" |
| 3 | import argparse, datetime, hashlib, json, pathlib, plistlib, re, subprocess |
| 4 | p=argparse.ArgumentParser();m=p.add_mutually_exclusive_group();m.add_argument('--local',action='store_true');m.add_argument('--archive',action='store_true',help='Validate a signed archive before distribution export; its development signature may have no profile.');p.add_argument('app',type=pathlib.Path);a=p.parse_args() |
| 5 | root=a.app.resolve();info=plistlib.loads((root/'Contents/Info.plist').read_bytes()) |
| 6 | exe=root/'Contents/MacOS'/info['CFBundleExecutable'] |
| 7 | assert info['LSMinimumSystemVersion']=='14.0' |
| 8 | config_root=pathlib.Path(__file__).resolve().parent.parent |
| 9 | release_config=(config_root/'Version.xcconfig').read_text()+'\n'+(config_root/'macOS/Release.xcconfig').read_text() |
| 10 | expected_version=re.search(r'^MARKETING_VERSION\s*=\s*(\S+)',release_config,re.M).group(1) |
| 11 | expected_build=re.search(r'^CURRENT_PROJECT_VERSION\s*=\s*(\S+)',release_config,re.M).group(1) |
| 12 | assert info['CFBundleShortVersionString']==expected_version |
| 13 | assert info['CFBundleVersion']==expected_build |
| 14 | assert info['CFBundleIdentifier']==('com.protomota.pulsecanvas.storevalidation' if a.local else 'com.protomota.pulsecanvas') |
| 15 | for binary in [exe]: |
| 16 | arch=subprocess.check_output(['lipo','-archs',str(binary)],text=True).strip() |
| 17 | assert arch=='arm64', (binary,arch) |
| 18 | subprocess.run(['codesign','--verify','--deep','--strict',str(root)],check=True) |
| 19 | raw=subprocess.check_output(['codesign','-d','--entitlements',':-',str(root)],stderr=subprocess.DEVNULL) |
| 20 | ent=plistlib.loads(raw[raw.index(b'<?xml'):]) |
| 21 | for key in ['com.apple.security.app-sandbox','com.apple.security.files.user-selected.read-write','com.apple.security.files.bookmarks.app-scope']: |
| 22 | assert ent.get(key) is True,key |
| 23 | assert not ent.get('com.apple.security.get-task-allow',False) |
| 24 | # Radio downloads the public catalog and tracks; incoming connections remain disabled. |
| 25 | assert ent.get('com.apple.security.network.client') is True |
| 26 | assert not any(ent.get(k) for k in ['com.apple.security.network.server','com.apple.security.device.audio-input','com.apple.security.cs.disable-library-validation']) |
| 27 | assert not any('temporary-exception' in k for k in ent) |
| 28 | for binary in [root]: |
| 29 | sig=subprocess.check_output(['codesign','-dv','--verbose=4',str(binary)],stderr=subprocess.STDOUT,text=True) |
| 30 | assert 'TeamIdentifier=22HV69L32T' in sig and 'runtime' in sig,sig |
| 31 | if not a.local and not a.archive: |
| 32 | assert (root/'Contents/embedded.provisionprofile').exists(),'Provisioning profile missing' |
| 33 | assert any(s in subprocess.check_output(['codesign','-dv','--verbose=4',str(root)],stderr=subprocess.STDOUT,text=True) for s in ['Authority=Apple Distribution:', 'Authority=3rd Party Mac Developer Application:']),'App Store distribution signature required' |
| 34 | profile=plistlib.loads(subprocess.check_output(['security','cms','-D','-i',str(root/'Contents/embedded.provisionprofile')])) |
| 35 | assert profile['TeamIdentifier']==['22HV69L32T'] |
| 36 | assert profile['Entitlements']['com.apple.application-identifier']=='22HV69L32T.com.protomota.pulsecanvas' |
| 37 | assert not profile['Entitlements'].get('com.apple.security.get-task-allow',False) |
| 38 | assert not profile.get('ProvisionedDevices') and not profile.get('ProvisionsAllDevices',False),'App Store profile required' |
| 39 | assert profile['ExpirationDate'] > datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None),'Provisioning profile expired' |
| 40 | res=root/'Contents/Resources';privacy=plistlib.loads((res/'PrivacyInfo.xcprivacy').read_bytes()) |
| 41 | assert not privacy['NSPrivacyTracking'] and not privacy['NSPrivacyCollectedDataTypes'] |
| 42 | # Every visual is compiled from PulseCanvas Metal sources; no prebuilt shader modules ship. |
| 43 | assert not list(res.rglob('*.ll')) and not list(res.rglob('VisualShaders*')),'Retired shader modules must not be bundled' |
| 44 | for f in ['AppIcon.icns','Legal/Edition.txt','Legal/PulseCanvas-LICENSE.txt']: |
| 45 | assert (res/f).is_file(),f |
| 46 | assert (res/'Legal/PulseCanvas-LICENSE.txt').read_bytes() == (pathlib.Path(__file__).resolve().parent.parent/'LICENSE').read_bytes(),'Bundled application license must match the release source' |
| 47 | assert not (res/'Legal/PulseCanvas-MIT-LICENSE.txt').exists(),'Obsolete application-license copy must not be bundled' |
| 48 | # Inspect the actual app, including nested resources and executable imports. |
| 49 | assert not list(root.rglob('*.milk')), 'OpenGL presets must not be bundled' |
| 50 | assert not any('projectm' in path.name.lower() or path.name == 'Sparkle.framework' for path in root.rglob('*')), 'Excluded engine/updater resource found' |
| 51 | assert not any(key.startswith(('SU', 'SPU')) for key in info), 'Sparkle settings must not enter store builds' |
| 52 | imports=subprocess.check_output(['otool','-L',str(exe)],text=True) |
| 53 | assert 'OpenGL.framework' not in imports and 'Sparkle' not in imports and 'libprojectM' not in imports, imports |
| 54 | symbols=subprocess.check_output(['nm','-u',str(exe)],text=True) |
| 55 | assert 'CGLCreateContext' not in symbols and '_projectm_' not in symbols, 'OpenGL engine symbols found' |
| 56 | native_catalog = res/'Resources/NativeVisualizers.json' |
| 57 | if native_catalog.is_file(): |
| 58 | catalog = json.loads(native_catalog.read_text()) |
| 59 | slots = catalog['nativeCount'] |
| 60 | assert catalog['schema'] == 1 and slots == len(catalog['effects']) |
| 61 | assert [e['id'] for e in catalog['effects']] == [f'native:{i}' for i in range(slots)] |
| 62 | assert [e['scene'] for e in catalog['effects']] == list(range(slots)) |
| 63 | # Retired designs keep their IDs for migration; the edition counts offered designs. |
| 64 | offered = [e for e in catalog['effects'] if not e.get('retired')] |
| 65 | count = catalog.get('activeCount', slots) |
| 66 | assert count == len(offered) and len({e['name'] for e in offered}) == count |
| 67 | for shader, digest in catalog['shaders'].items(): |
| 68 | assert pathlib.Path(shader).name == shader |
| 69 | assert hashlib.sha256((res/'Resources'/shader).read_bytes()).hexdigest() == digest, shader |
| 70 | else: |
| 71 | # Historical 1.0.2 (10) predates native catalog expansion; inspect its own |
| 72 | # edition receipt rather than claiming it contains newly developed effects. |
| 73 | count = 31 |
| 74 | assert f'{count} native Metal visualizers' in (res/'Legal/Edition.txt').read_text() |
| 75 | print(json.dumps({'bundle':info['CFBundleIdentifier'],'version':info['CFBundleShortVersionString'],'build':info['CFBundleVersion'],'architecture':'arm64','sandbox':True,'presets':0,'nativeVisualizers':count,'edition':'metal','sparkle':False,'openGL':False,'signing': 'Apple Development local test' if a.local else ('team-signed archive; distribution export required' if a.archive else 'App Store distribution signature; Apple processing status checked separately')},indent=2)) |