Skip to content

Commit

Permalink
[tools/codesign][Darwin] Clean up and ignore eggs for jailbroken devices
Browse files Browse the repository at this point in the history
  • Loading branch information
sy6sy2 committed Aug 26, 2020
1 parent 41072b9 commit 55a11a1
Showing 1 changed file with 56 additions and 72 deletions.
128 changes: 56 additions & 72 deletions tools/darwin/Support/Codesign.command
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -x

#this is the list of binaries we have to sign for being able to run un-jailbroken
LIST_BINARY_EXTENSIONS="dylib so 0 vis pvr app"
LIST_BINARY_EXTENSIONS="dylib so app"

GEN_ENTITLEMENTS="$NATIVEPREFIX/bin/gen_entitlements.py"
DARWIN_EMBEDDED_ENTITLEMENTS="$XBMC_DEPENDS/share/darwin_embedded_entitlements.xml"
Expand All @@ -18,86 +18,70 @@ if [[ ! "$MACOS" && ! -f ${GEN_ENTITLEMENTS} ]]; then
exit -1
fi

if [[ "$MACOS" || "${PLATFORM_NAME}" == "iphoneos" || "${PLATFORM_NAME}" == "appletvos" ]]; then
if [ "$MACOS" ]; then
CONTENTS_PATH="${CODESIGNING_FOLDER_PATH}/Contents"
else
CONTENTS_PATH="${CODESIGNING_FOLDER_PATH}"
fi
if [ "$MACOS" ]; then
CONTENTS_PATH="${CODESIGNING_FOLDER_PATH}/Contents"
else
CONTENTS_PATH="${CODESIGNING_FOLDER_PATH}"
fi

if [ ! "$MACOS" ]; then
# do fake sign - needed for iOS >=5.1 and tvOS >=10.2 jailbroken devices
# see http://www.saurik.com/id/8
if [[ "${PLATFORM_NAME}" == "iphoneos" || "${PLATFORM_NAME}" == "appletvos" ]]; then
if [ -f "${LDID}" ]; then
find "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}/" -iname "*.dylib" -or -iname "*.so" | xargs "${LDID}" -S"${DARWIN_EMBEDDED_ENTITLEMENTS}"
"${LDID}" "-S${DARWIN_EMBEDDED_ENTITLEMENTS}" "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}/${EXECUTABLE_NAME}"

# repackage python eggs
EGGS=$(find "${CONTENTS_PATH}" -iname "*.egg" -type f)
for i in "$EGGS"; do
echo "$i"
mkdir del
unzip -q "$i" -d del
find ./del/ -iname "*.so" -type f | xargs "${LDID}" -S"${DARWIN_EMBEDDED_ENTITLEMENTS}"
rm "$i"
cd del && zip -qr "$i" ./* && cd ..
rm -r ./del/
done
fi
fi

# pull the CFBundleIdentifier out of the built xxx.app
BUNDLEID=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "${CONTENTS_PATH}/Info.plist")
echo "CFBundleIdentifier is ${BUNDLEID}"
"${LDID}" -S"${DARWIN_EMBEDDED_ENTITLEMENTS}" "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}/${EXECUTABLE_NAME}"
fi

# Prefer the expanded name, if available.
CODE_SIGN_IDENTITY_FOR_ITEMS="${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
if [ "${CODE_SIGN_IDENTITY_FOR_ITEMS}" = "" ] ; then
# Fall back to old behavior.
CODE_SIGN_IDENTITY_FOR_ITEMS="${CODE_SIGN_IDENTITY}"
fi
echo "${CODE_SIGN_IDENTITY_FOR_ITEMS}"
# pull the CFBundleIdentifier out of the built xxx.app
BUNDLEID=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "${CONTENTS_PATH}/Info.plist")
echo "CFBundleIdentifier is ${BUNDLEID}"

if [ ! "$MACOS" ]; then
${GEN_ENTITLEMENTS} "${BUNDLEID}" "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}/${EXECUTABLE_NAME}.xcent"
fi
# Prefer the expanded name, if available.
CODE_SIGN_IDENTITY_FOR_ITEMS="${EXPANDED_CODE_SIGN_IDENTITY_NAME}"
if [ "${CODE_SIGN_IDENTITY_FOR_ITEMS}" = "" ] ; then
# Fall back to old behavior.
CODE_SIGN_IDENTITY_FOR_ITEMS="${CODE_SIGN_IDENTITY}"
fi
echo "${CODE_SIGN_IDENTITY_FOR_ITEMS}"

# delete existing codesigning
if [ -d "${CONTENTS_PATH}/_CodeSignature" ]; then
rm -r "${CONTENTS_PATH}/_CodeSignature"
fi
if [[ ! "$MACOS" && -f "${CONTENTS_PATH}/embedded.mobileprovision" ]]; then
if [ ! "$MACOS" ]; then
${GEN_ENTITLEMENTS} "${BUNDLEID}" "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_FOLDER_PATH}/${EXECUTABLE_NAME}.xcent"
if [ -f "${CONTENTS_PATH}/embedded.mobileprovision" ]; then
rm -f "${CONTENTS_PATH}/embedded.mobileprovision"
fi
fi

#if user has set a code_sign_identity different from iPhone Developer we do a real codesign (for deployment on non-jailbroken devices)
if ! [ -z "${CODE_SIGN_IDENTITY_FOR_ITEMS}" ]; then
if egrep -q --max-count=1 -e '^iPhone (Developer|Distribution): ' -e '^Apple (Development|Distribution): ' -e '^[[:xdigit:]]+$' -e '^Developer ID Application: ' <<<"${CODE_SIGN_IDENTITY_FOR_ITEMS}"; then
echo "Doing a full bundle sign using genuine identity ${CODE_SIGN_IDENTITY_FOR_ITEMS}"
for binext in $LIST_BINARY_EXTENSIONS
do
echo "Signing binary: $binext"
# check if at least 1 file with the extension exists to sign, otherwise do nothing
FINDOUTPUT=$(find "${CONTENTS_PATH}" -name "*.$binext" -type f)
if [ `echo $FINDOUTPUT | wc -l` != 0 ]; then
for singlefile in $FINDOUTPUT; do
codesign -s "${CODE_SIGN_IDENTITY_FOR_ITEMS}" -fvvv -i "${BUNDLEID}" "${singlefile}"
done
fi
done
echo "In case your app crashes with SIG_SIGN check the variable LIST_BINARY_EXTENSIONS in tools/darwin/Support/Codesign.command"
# delete existing codesigning
if [ -d "${CONTENTS_PATH}/_CodeSignature" ]; then
rm -r "${CONTENTS_PATH}/_CodeSignature"
fi

for FRAMEWORK_PATH in $(find "${CONTENTS_PATH}" -name "*.framework" -type d)
do
DYLIB_BASENAME=$(basename "${FRAMEWORK_PATH%.framework}")
echo "Signing Framework: ${DYLIB_BASENAME}.framework"
FRAMEWORKBUNDLEID="${BUNDLEID}.framework.${DYLIB_BASENAME}"
codesign -s "${CODE_SIGN_IDENTITY_FOR_ITEMS}" -fvvv -i "${FRAMEWORKBUNDLEID}" "${FRAMEWORK_PATH}/${DYLIB_BASENAME}"
codesign -s "${CODE_SIGN_IDENTITY_FOR_ITEMS}" -fvvv -i "${FRAMEWORKBUNDLEID}" "${FRAMEWORK_PATH}"
done
#if user has set a code_sign_identity different from iPhone Developer we do a real codesign (for deployment on non-jailbroken devices)
if ! [ -z "${CODE_SIGN_IDENTITY_FOR_ITEMS}" ]; then
if egrep -q --max-count=1 -e '^iPhone (Developer|Distribution): ' -e '^Apple (Development|Distribution): ' -e '^[[:xdigit:]]+$' -e '^Developer ID Application: ' <<<"${CODE_SIGN_IDENTITY_FOR_ITEMS}"; then
echo "Doing a full bundle sign using genuine identity ${CODE_SIGN_IDENTITY_FOR_ITEMS}"
for binext in $LIST_BINARY_EXTENSIONS
do
echo "Signing binary: $binext"
# check if at least 1 file with the extension exists to sign, otherwise do nothing
FINDOUTPUT=$(find "${CONTENTS_PATH}" -iname "*.$binext" -type f)
if [ `echo $FINDOUTPUT | wc -l` != 0 ]; then
for singlefile in $FINDOUTPUT; do
codesign -s "${CODE_SIGN_IDENTITY_FOR_ITEMS}" -fvvv -i "${BUNDLEID}" "${singlefile}"
done
fi
done

#repackage python eggs
EGGS=$(find "${CONTENTS_PATH}" -name "*.egg" -type f)
for FRAMEWORK_PATH in $(find "${CONTENTS_PATH}" -iname "*.framework" -type d)
do
DYLIB_BASENAME=$(basename "${FRAMEWORK_PATH%.framework}")
echo "Signing Framework: ${DYLIB_BASENAME}.framework"
FRAMEWORKBUNDLEID="${BUNDLEID}.framework.${DYLIB_BASENAME}"
codesign -s "${CODE_SIGN_IDENTITY_FOR_ITEMS}" -fvvv -i "${FRAMEWORKBUNDLEID}" "${FRAMEWORK_PATH}/${DYLIB_BASENAME}"
codesign -s "${CODE_SIGN_IDENTITY_FOR_ITEMS}" -fvvv -i "${FRAMEWORKBUNDLEID}" "${FRAMEWORK_PATH}"
done

if [ "$MACOS" ]; then
#sign and repackage python eggs for osx
EGGS=$(find "${CONTENTS_PATH}" -iname "*.egg" -type f)
echo "Signing Eggs"
for i in $EGGS; do
echo $i
Expand All @@ -106,15 +90,15 @@ if [[ "$MACOS" || "${PLATFORM_NAME}" == "iphoneos" || "${PLATFORM_NAME}" == "app
for binext in $LIST_BINARY_EXTENSIONS
do
# check if at least 1 file with the extension exists to sign, otherwise do nothing
FINDOUTPUT=`find ./del/ -name "*.$binext" -type f`
FINDOUTPUT=$(find ./del/ -iname "*.$binext" -type f)
if [ `echo $FINDOUTPUT | wc -l` != 0 ]; then
for singlefile in $FINDOUTPUT; do
codesign -s "${CODE_SIGN_IDENTITY_FOR_ITEMS}" -fvvv -i "${BUNDLEID}" "${singlefile}"
done
fi
done
rm $i
cd del && zip -qr $i ./* && cd ..
cd del && zip -qr $i ./* && cd ..
rm -r ./del/
done
fi
Expand Down

0 comments on commit 55a11a1

Please sign in to comment.