Repository Public
1#!/usr/bin/env python32# Registers SP Vault's bundle identifiers and capabilities and creates the Developer ID provisioning profiles of the3# macOS app and its AutoFill extension, with the EXISTING App Store Connect API key and Developer ID certificate.4# Idempotent: existing resources are reused; no certificate is ever created. Nothing secret is printed.5import base64, hashlib, os, subprocess, sys6sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))7import asc89OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "build", "profiles")10# identifier, display name, platform, capabilities, (Developer ID profile name, file) or None11TARGETS = [12 ("ai.spboucher.spvault", "SP Vault", "MAC_OS", ["ASSOCIATED_DOMAINS", "AUTOFILL_CREDENTIAL_PROVIDER"], ("SP Vault Developer ID", "SPVault.provisionprofile")),13 ("ai.spboucher.spvault.autofill", "SP Vault AutoFill", "MAC_OS", ["AUTOFILL_CREDENTIAL_PROVIDER"], ("SP Vault AutoFill Developer ID", "SPVaultAutoFill.provisionprofile")),14 ("ai.spboucher.spvault.ios", "SP Vault iOS", "IOS", ["ASSOCIATED_DOMAINS", "AUTOFILL_CREDENTIAL_PROVIDER", "APP_GROUPS"], None),15 ("ai.spboucher.spvault.ios.autofill", "SP Vault iOS AutoFill", "IOS", ["AUTOFILL_CREDENTIAL_PROVIDER", "APP_GROUPS"], None),16]17out = subprocess.run(["security", "find-certificate", "-c", "Developer ID Application", "-Z"], capture_output=True, text=True).stdout18local = [l.split(":")[1].strip() for l in out.splitlines() if l.startswith("SHA-1")]19if not local: sys.exit("no Developer ID Application certificate in the keychain")20s, d = asc.call("GET", "/v1/certificates?filter[certificateType]=DEVELOPER_ID_APPLICATION,DEVELOPER_ID_APPLICATION_G2&limit=100")21cert = next((c["id"] for c in d.get("data", []) if hashlib.sha1(base64.b64decode(c["attributes"]["certificateContent"])).hexdigest().upper() in local), None)22if not cert: sys.exit("the keychain's Developer ID certificate is not visible through the API")23os.makedirs(OUT, exist_ok=True)24for BID, DISPLAY, PLATFORM, CAPS, PROFILE in TARGETS:25 s, d = asc.call("GET", f"/v1/bundleIds?filter[identifier]={BID}&limit=20")26 ids = [b for b in d.get("data", []) if b["attributes"]["identifier"] == BID]27 if ids: bid = ids[0]["id"]; print("bundle id exists:", BID)28 else:29 s, d = asc.call("POST", "/v1/bundleIds", {"data": {"type": "bundleIds", "attributes": {"identifier": BID, "name": DISPLAY, "platform": PLATFORM}}})30 if s >= 300: sys.exit(f"cannot create bundle id {BID}: HTTP {s} {str(d)[:300]}")31 bid = d["data"]["id"]; print("bundle id created:", BID)32 s, d = asc.call("GET", f"/v1/bundleIds/{bid}/bundleIdCapabilities")33 have = [c["attributes"]["capabilityType"] for c in d.get("data", [])]34 changed = False35 for cap in CAPS:36 if cap in have: continue37 s, d = asc.call("POST", "/v1/bundleIdCapabilities", {"data": {"type": "bundleIdCapabilities", "attributes": {"capabilityType": cap}, "relationships": {"bundleId": {"data": {"type": "bundleIds", "id": bid}}}}})38 if s >= 300: print(f" WARNING: cannot enable {cap} on {BID}: HTTP {s} {str(d)[:200]}"); continue39 print(" capability enabled:", cap); changed = True40 if not PROFILE: continue41 NAME, FILE = PROFILE42 s, allp = asc.call("GET", "/v1/profiles?filter[profileType]=MAC_APP_DIRECT&limit=200")43 mine = [p for p in allp.get("data", []) if p["attributes"]["name"] == NAME]44 active = [p for p in mine if p["attributes"]["profileState"] == "ACTIVE"]45 if active and not changed: p = active[0]; print(" profile exists:", NAME)46 else:47 for stale in mine: asc.call("DELETE", f"/v1/profiles/{stale['id']}"); print(" stale profile removed")48 s, d = asc.call("POST", "/v1/profiles", {"data": {"type": "profiles", "attributes": {"name": NAME, "profileType": "MAC_APP_DIRECT"}, "relationships": {"bundleId": {"data": {"type": "bundleIds", "id": bid}}, "certificates": {"data": [{"type": "certificates", "id": cert}]}}}})49 if s >= 300: sys.exit(f"cannot create the profile {NAME}: HTTP {s} {str(d)[:300]}")50 p = d["data"]; print(" profile created:", NAME)51 content = base64.b64decode(p["attributes"]["profileContent"])52 open(os.path.join(OUT, FILE), "wb").write(content)53 for dest in ("~/Library/Developer/Xcode/UserData/Provisioning Profiles", "~/Library/MobileDevice/Provisioning Profiles"):54 dd = os.path.expanduser(dest); os.makedirs(dd, exist_ok=True)55 open(os.path.join(dd, p["attributes"]["uuid"] + ".provisionprofile"), "wb").write(content)56 print(" written:", FILE, "| uuid", p["attributes"]["uuid"], "| expires", p["attributes"]["expirationDate"][:10])57