From faa622e379922125cc92adbb12fb7aa67409a1a2 Mon Sep 17 00:00:00 2001 From: Guilherme Rambo Date: Tue, 6 Jan 2026 13:35:04 -0300 Subject: [PATCH] Project setup to facilitate external contributions (#783) --- .gitignore | 4 ++ Sources/Config/Config.xcconfig | 5 ++ .../Packages/Sources/XPCWrappers/TeamID.swift | 26 +++++++++ .../XPCWrappers/XPCServiceDelegate.swift | 2 +- .../Sources/XPCWrappers/XPCTypedSession.swift | 2 +- Sources/Secretive.xcodeproj/project.pbxproj | 42 +++++++------- configure_team_id.sh | 56 +++++++++++++++++++ 7 files changed, 115 insertions(+), 22 deletions(-) create mode 100644 Sources/Packages/Sources/XPCWrappers/TeamID.swift create mode 100755 configure_team_id.sh diff --git a/.gitignore b/.gitignore index d0d8b7c..e7e7a4d 100644 --- a/.gitignore +++ b/.gitignore @@ -93,3 +93,7 @@ iOSInjectionProject/ Archive.xcarchive .DS_Store contents.xcworkspacedata + +# Per-User Configs + +Sources/Config/OpenSource.xcconfig \ No newline at end of file diff --git a/Sources/Config/Config.xcconfig b/Sources/Config/Config.xcconfig index e81adaa..4cc6879 100644 --- a/Sources/Config/Config.xcconfig +++ b/Sources/Config/Config.xcconfig @@ -1,3 +1,8 @@ CI_VERSION = GITHUB_CI_VERSION CI_BUILD_NUMBER = GITHUB_BUILD_NUMBER CI_BUILD_LINK = GITHUB_BUILD_URL + +#include? "OpenSource.xcconfig" + +SECRETIVE_BASE_BUNDLE_ID = $(SECRETIVE_BASE_BUNDLE_ID_OSS:default=com.maxgoedjen.Secretive) +SECRETIVE_DEVELOPMENT_TEAM = $(SECRETIVE_DEVELOPMENT_TEAM_OSS:default=Z72PRUAWF6) diff --git a/Sources/Packages/Sources/XPCWrappers/TeamID.swift b/Sources/Packages/Sources/XPCWrappers/TeamID.swift new file mode 100644 index 0000000..56848a1 --- /dev/null +++ b/Sources/Packages/Sources/XPCWrappers/TeamID.swift @@ -0,0 +1,26 @@ +import Foundation + +extension ProcessInfo { + private static let fallbackTeamID = "Z72PRUAWF6" + + private static let teamID: String = { + #if DEBUG + guard let task = SecTaskCreateFromSelf(nil) else { + assertionFailure("SecTaskCreateFromSelf failed") + return fallbackTeamID + } + + guard let value = SecTaskCopyValueForEntitlement(task, "com.apple.developer.team-identifier" as CFString, nil) as? String else { + assertionFailure("SecTaskCopyValueForEntitlement(com.apple.developer.team-identifier) failed") + return fallbackTeamID + } + + return value + #else + /// Always use hardcoded team ID for release builds, just in case. + return fallbackTeamID + #endif + }() + + public var teamID: String { Self.teamID } +} diff --git a/Sources/Packages/Sources/XPCWrappers/XPCServiceDelegate.swift b/Sources/Packages/Sources/XPCWrappers/XPCServiceDelegate.swift index 9fd9216..b2050f4 100644 --- a/Sources/Packages/Sources/XPCWrappers/XPCServiceDelegate.swift +++ b/Sources/Packages/Sources/XPCWrappers/XPCServiceDelegate.swift @@ -12,7 +12,7 @@ public final class XPCServiceDelegate: NSObject, NSXPCListenerDelegate { newConnection.exportedInterface = NSXPCInterface(with: (any _XPCProtocol).self) let exportedObject = exportedObject newConnection.exportedObject = exportedObject - newConnection.setCodeSigningRequirement("anchor apple generic and certificate leaf[subject.OU] = Z72PRUAWF6") + newConnection.setCodeSigningRequirement("anchor apple generic and certificate leaf[subject.OU] = \"\(ProcessInfo.processInfo.teamID)\"") newConnection.resume() return true } diff --git a/Sources/Packages/Sources/XPCWrappers/XPCTypedSession.swift b/Sources/Packages/Sources/XPCWrappers/XPCTypedSession.swift index fc73a34..509c48e 100644 --- a/Sources/Packages/Sources/XPCWrappers/XPCTypedSession.swift +++ b/Sources/Packages/Sources/XPCWrappers/XPCTypedSession.swift @@ -8,7 +8,7 @@ public struct XPCTypedSession/dev/null) + TEAMID=$(/usr/libexec/PlistBuddy -c "Print :IDEProvisioningTeams:$KEY:$i:teamID" "$XCODEPREFS" 2>/dev/null) + + if [ $? -ne 0 ]; then + break + fi + + echo "$TEAMID - $NAME" + + i=$(($i + 1)) + done + done +} + +if [ -z "$1" ]; then + print_team_ids + echo "" + echo "> What is your Apple Developer Team ID? (looks like 1A23BDCD)" + read TEAM_ID +else + TEAM_ID=$1 +fi + +if [ -z "$TEAM_ID" ]; then + echo "You must enter a team id" + print_team_ids + exit 1 +fi + +echo "Setting team ID to $TEAM_ID" + +echo "// This file was automatically generated, do not edit directly." > $TEAM_ID_FILE +echo "" >> $TEAM_ID_FILE +echo "SECRETIVE_BASE_BUNDLE_ID_OSS=${TEAM_ID}.com.example.Secretive" >> $TEAM_ID_FILE +echo "SECRETIVE_DEVELOPMENT_TEAM_OSS=${TEAM_ID}" >> $TEAM_ID_FILE + +echo "" +echo "Successfully generated configuration at $TEAM_ID_FILE, you may now build the app using the \"Secretive\" target" +echo "You may need to close and re-open the project in Xcode if it's already open" +echo "" \ No newline at end of file