Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

fix: let Siri read the login in sideloaded builds (#143)

My-Name-Is-Jeff8eb4bbfae504
diff --git a/docs/tweaks.md b/docs/tweaks.md
index a98cd669..cd4ff7fa 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -19,11 +19,12 @@
backup and signing, the welcome tour
tweak/Sources/Diagnostics/ screen dumps, the tree server, the phone driver and the main thread hang sampler of FLEX builds
extension/LiveActivity/ the Live Activity widget, a WidgetKit extension of its own
- extension/AppGroups/ a dylib loaded by Spotify and its home screen widget that moves Spotify's App Groups
- into a group the re-signed IPA has; without it the widget stays a placeholder
+ extension/AppGroups/ a dylib loaded by Spotify and its widget, Siri and notification extensions that moves
+ Spotify's App Groups and its extension-credentials keychain group into groups the
+ re-signed IPA has; without it the widget stays a placeholder and Siri asks to verify
scripts/ pipeline.sh (build + inject), build-extension.sh (the widget extension, without an
Xcode project), merge-appintents.py (the widget's intents into Spotify's), insert-dylib.py (a load command into
- Spotify's widget), install.sh (sign + install), record-trees.py, record-session.py,
+ Spotify's extensions), install.sh (sign + install), record-trees.py, record-session.py,
dump-log.sh, extract-flags.py, check-layers.sh (the one-way imports between layers)
trees/ recorded view trees, one per screen; the input for every new hook. trees/clean/ holds
the numbered snapshots per screen of record-session.py, taken of Spotify as it came
diff --git a/extension/AppGroups/AppGroups.m b/extension/AppGroups/AppGroups.m
index 8c3d7da6..f515fd03 100644
--- a/extension/AppGroups/AppGroups.m
+++ b/extension/AppGroups/AppGroups.m
@@ -1,4 +1,5 @@
-// Spotify's App Groups, redirected into whichever group the sideload signature really has.
+// Spotify's App Groups and its extension-credentials keychain group, redirected into groups the
+// sideload signature really has.
//
// The main app hands the home screen widget everything it shows through UserDefaults suites named
// group.com.spotify.client.widget, .widget.data and .widget.lifecycle. Those groups belong to
@@ -6,11 +7,18 @@
// (group.<hash>.N from a paid certificate service, something else from AltStore), each process
// then gets a private, empty suite, and the widget stays on its "Open Spotify and play" placeholder.
//
-// This dylib is loaded by both Spotify and WidgetExtension.appex (scripts/pipeline.sh adds the load
-// command to the extension). In each it maps every group.* identifier the process is not entitled
-// to onto a folder inside one group it is entitled to, the same folder in both processes, so the
-// suites and container files meet again. It is plain runtime swizzling, no Substrate, because the
-// extension carries nothing else of the tweak.
+// This dylib is loaded by Spotify and its Widget, Intents and NotificationService extensions
+// (scripts/pipeline.sh adds the load command to each extension). In each it maps every group.*
+// identifier the process is not entitled to onto a folder inside one group it is entitled to, the
+// same folder in every process, so the suites and container files meet again. It is plain runtime
+// swizzling, no Substrate, because the extensions carry nothing else of the tweak.
+//
+// Keychain: the app saves the login the Siri and notification extensions sign in with under
+// the access group 8W66MEA7DD.com.spotify.client.extension-credentials, built from Spotify's team id
+// in SpotifyShared. A re-signed process is not entitled to it (errSecMissingEntitlement), so Siri asks
+// to verify the account (issue #60). Every SPTKeychainManager call builds its query in
+// getBaseDictionaryForDomain:key:accessGroup:accessAttr:synchronizable:, and there that group is
+// swapped for one the signature has, the same in the app and every extension.
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <os/log.h>
@@ -28,10 +36,15 @@ static NSArray<NSString *> *sEntitled;
static NSURL *(*sOrigContainerURL)(id, SEL, NSString *);
static id (*sOrigInitWithSuiteName)(id, SEL, NSString *);
-static NSArray<NSString *> *EntitledGroups(void) {
+static NSString *const kCredentialsGroupSuffix = @".com.spotify.client.extension-credentials";
+static NSArray<NSString *> *sKeychainEntitled;
+static NSString *sKeychainGroup;
+static id (*sOrigBaseDictionary)(id, SEL, id, id, NSString *, id, BOOL);
+
+static NSArray<NSString *> *EntitledGroups(CFStringRef entitlement) {
SecTaskRef task = SecTaskCreateFromSelf(NULL);
if (!task) return @[];
- CFTypeRef value = SecTaskCopyValueForEntitlement(task, CFSTR("com.apple.security.application-groups"), NULL);
+ CFTypeRef value = SecTaskCopyValueForEntitlement(task, entitlement, NULL);
CFRelease(task);
NSArray *groups = CFBridgingRelease(value);
if (![groups isKindOfClass:NSArray.class]) return @[];
@@ -78,9 +91,51 @@ static id SGInitWithSuiteName(NSUserDefaults *self, SEL _cmd, NSString *suite) {
return sOrigInitWithSuiteName(self, _cmd, suite);
}
+// The group the extension credentials go in: the signer's own copy of Spotify's (AltStore re-teams
+// it), else the first entitled one in sorted order. A TEAM.* entry is used as it is, not expanded, so it is
+// allowed whether or not securityd matches the wildcard. com.apple.token is CryptoTokenKit's.
+static NSString *CredentialsGroup(void) {
+ for (NSString *group in sKeychainEntitled) {
+ if ([group hasSuffix:kCredentialsGroupSuffix]) return group;
+ }
+ for (NSString *group in sKeychainEntitled) {
+ if (![group isEqualToString:@"com.apple.token"]) return group;
+ }
+ return nil;
+}
+
+static id SGBaseDictionary(id self, SEL _cmd, id domain, id key, NSString *group, id attr, BOOL sync) {
+ // Only Spotify's extension credentials group, and only when the signature lacks it: TrollStore keeps
+ // Spotify's entitlements and is left alone, and the Watch groups never match the suffix.
+ if ([group isKindOfClass:NSString.class] && [group hasSuffix:kCredentialsGroupSuffix] && ![sKeychainEntitled containsObject:group]) {
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{ os_log(sLog, "[spotifyglass] keychain: %{public}@ -> %{public}@", group, sKeychainGroup); });
+ group = sKeychainGroup;
+ }
+ return sOrigBaseDictionary(self, _cmd, domain, key, group, attr, sync);
+}
+
+// SpotifyShared is a direct dependency of the app and of every extension, so its classes are
+// registered before this constructor runs.
+static void InstallKeychainHook(void) {
+ sKeychainEntitled = EntitledGroups(CFSTR("keychain-access-groups"));
+ sKeychainGroup = CredentialsGroup();
+ os_log(sLog, "[spotifyglass] keychain: entitled to %{public}@, credentials in %{public}@",
+ [sKeychainEntitled componentsJoinedByString:@", "], sKeychainGroup);
+ if (!sKeychainGroup) return;
+ Method m = class_getInstanceMethod(objc_getClass("SPTKeychainManagerImpl"),
+ @selector(getBaseDictionaryForDomain:key:accessGroup:accessAttr:synchronizable:));
+ if (!m) {
+ os_log(sLog, "[spotifyglass] keychain: no -[SPTKeychainManagerImpl getBaseDictionaryForDomain:...]");
+ return;
+ }
+ sOrigBaseDictionary = (void *)method_setImplementation(m, (IMP)SGBaseDictionary);
+}
+
__attribute__((constructor)) static void SGAppGroupsInit(void) {
sLog = os_log_create("spotifyglass", "appgroups");
- sEntitled = EntitledGroups();
+ InstallKeychainHook();
+ sEntitled = EntitledGroups(CFSTR("com.apple.security.application-groups"));
os_log(sLog, "[spotifyglass] appgroups: %{public}@ entitled to %{public}@",
NSBundle.mainBundle.bundleIdentifier, [sEntitled componentsJoinedByString:@", "]);
if (sEntitled.count == 0) return;
diff --git a/scripts/pipeline.sh b/scripts/pipeline.sh
index bddccae1..48c2dfce 100755
--- a/scripts/pipeline.sh
+++ b/scripts/pipeline.sh
@@ -113,7 +113,8 @@ else
fi
# Spotify's widget reads what the app writes through App Group suites the re-signed IPA is not entitled
-# to; this dylib, loaded by the app and by the widget, puts both on a group the signature does have.
+# to, and Siri reads the login from a keychain group it is not entitled to either; this dylib, loaded by
+# the app and its extensions, puts them all on groups the signature does have.
echo "==> building the App Group shim"
GROUPS_DYLIB="$ROOT/out/SpotifyGlassAppGroups.dylib"
xcrun --sdk iphoneos clang -target arm64-apple-ios16.0 -dynamiclib -fobjc-arc -Os -framework Foundation -framework Security \
@@ -158,21 +159,30 @@ if [ -n "$KEEP_WATCH" ]; then
(cd "$PATCH" && zip -q -r "$OUT_ABS" "${APP_DIR}Watch")
rm -rf "$PATCH"
fi
-echo "==> loading the App Group shim in the home screen widget"
-WIDGET_BIN="${APP_DIR}PlugIns/WidgetExtension.appex/WidgetExtension"
-if unzip -l "$OUT" "$WIDGET_BIN" >/dev/null 2>&1; then
- PATCH="$(mktemp -d)"
- unzip -q "$OUT" "$WIDGET_BIN" -d "$PATCH"
- "$ROOT/scripts/insert-dylib.py" "$PATCH/$WIDGET_BIN" @rpath/SpotifyGlassAppGroups.dylib
- # Fakesigned again with its own entitlements, the way cyan -s left it, for TrollStore.
- ldid -e "$PATCH/$WIDGET_BIN" > "$PATCH/ents.plist"
- ldid -S"$PATCH/ents.plist" "$PATCH/$WIDGET_BIN"
+# The widget reads the App Group suites; Siri (IntentsExtension) and the notification service sign in
+# with the credentials the app keeps in the keychain (extension/AppGroups/AppGroups.m, issue #60).
+PATCH="$(mktemp -d)"
+EXT_BINS=()
+for EXT in WidgetExtension IntentsExtension NotificationServiceExtension; do
+ echo "==> loading the App Group shim in $EXT"
+ EXT_BIN="${APP_DIR}PlugIns/$EXT.appex/$EXT"
+ if unzip -l "$OUT" "$EXT_BIN" >/dev/null 2>&1; then
+ unzip -q "$OUT" "$EXT_BIN" -d "$PATCH"
+ "$ROOT/scripts/insert-dylib.py" "$PATCH/$EXT_BIN" @rpath/SpotifyGlassAppGroups.dylib
+ # Fakesigned again with its own entitlements, the way cyan -s left it, for TrollStore.
+ ldid -e "$PATCH/$EXT_BIN" > "$PATCH/ents.plist"
+ ldid -S"$PATCH/ents.plist" "$PATCH/$EXT_BIN"
+ EXT_BINS+=("$EXT_BIN")
+ else
+ echo " no $EXT.appex in this IPA"
+ fi
+done
+# One zip pass: each update rewrites the whole IPA.
+if [ ${#EXT_BINS[@]} -gt 0 ]; then
OUT_ABS="$(cd "$(dirname "$OUT")" && pwd)/$(basename "$OUT")"
- (cd "$PATCH" && zip -q "$OUT_ABS" "$WIDGET_BIN")
- rm -rf "$PATCH"
-else
- echo " no WidgetExtension.appex in this IPA"
+ (cd "$PATCH" && zip -q "$OUT_ABS" "${EXT_BINS[@]}")
fi
+rm -rf "$PATCH"
shopt -s nullglob
ICONS=("$ROOT"/icons/*.png)