Skip to content

Commit f7fd76b

Browse files
committed
Merge #20880: gitian: Use custom MacOS code signing tool
2c40327 gitian: Remove codesign_allocate and pagestuff from MacOS build (Andrew Chow) f55eed2 gitian: use signapple to create the MacOS code signature (Andrew Chow) 95b06d2 gitian: use signapple to apply the MacOS code signature (Andrew Chow) 42bb1ea gitian: install signapple in gitian-osx-signer.yml (Andrew Chow) Pull request description: The MacOS code signing issues that were encountered during the 0.21.0 release cycle have shown that it is necessary for us to use a code signing tool for which the source code is available and modifiable by us. Given that there appears to not be such a tool available, I have written such a tool, [signapple](https://github.com/achow101/signapple), that we can use. This tool is able to create a valid MacOS code signature, detach it in a way that we were doing previously, and attach it to the unsigned binary. This tool can also verify that the signature is correct. This PR implements the usage of that tool in the gitian build for the code signed MacOS binary. The code signer will use this tool to create the detached signature. Gitian builders will use this tool to apply the detached signature. The `gitian-osx-signer.yml` descriptor has been modified to install this tool so that the `detached-sig-apply.sh` script can use it. Additionally, the `codesign_allocate` and `pagestuff` tools are no longer necessary so they are no longer added to the tarball used in code signing. Lastly, both the `detached-sig-create.sh` and `detached-sig-apply.sh` scripts are made to be significantly less complex and to not do unexpected things such as unpacking an already unpacked tarball. The detached code signature that signapple creates is almost identical to that which we were previously creating. The only difference is that the cpu architecture name is included in the extension (e.g. we have `bitcoin-qt.x86_64sign` instead of `bitcoin-qt.sign`). This was done in order to support signing universal binaries which we may want to do in the future. However signapple can still apply existing code signatures as it will accept the `.sign` extension. If it is desired, it can be modified to produce signatures with just the `.sign` extension. However I do not think it is necessary to maintain compatibility with the old process. ACKs for top commit: laanwj: Code review ACK 2c40327 Tree-SHA512: 2a0e01e9133f8859b9de26e7e8fe1d2610d2cbdee2845e6008b12c083c7e3622cbb2d9b83c50a269e2c3074ab95914a8225d3cd4108017f58b77a62bf10951e0
2 parents ca82183 + 2c40327 commit f7fd76b

File tree

4 files changed

+24
-67
lines changed

4 files changed

+24
-67
lines changed

contrib/gitian-descriptors/gitian-osx-signer.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ architectures:
88
packages:
99
- "faketime"
1010
- "xorriso"
11+
- "python3-pip"
1112
remotes:
1213
- "url": "https://github.com/bitcoin-core/bitcoin-detached-sigs.git"
1314
"dir": "signature"
15+
- "url": "https://github.com/achow101/signapple.git"
16+
"dir": "signapple"
17+
"commit": "c7e73aa27a7615ac9506559173f787e2906b25eb"
1418
files:
1519
- "bitcoin-osx-unsigned.tar.gz"
1620
script: |
@@ -31,11 +35,19 @@ script: |
3135
chmod +x ${WRAP_DIR}/${prog}
3236
done
3337
34-
UNSIGNED=bitcoin-osx-unsigned.tar.gz
38+
# Install signapple
39+
cd signapple
40+
python3 -m pip install -U pip setuptools
41+
python3 -m pip install .
42+
export PATH="$HOME/.local/bin":$PATH
43+
cd ..
44+
45+
UNSIGNED_TARBALL=bitcoin-osx-unsigned.tar.gz
46+
UNSIGNED_APP=dist/Bitcoin-Qt.app
3547
SIGNED=bitcoin-osx-signed.dmg
3648
37-
tar -xf ${UNSIGNED}
49+
tar -xf ${UNSIGNED_TARBALL}
3850
OSX_VOLNAME="$(cat osx_volname)"
39-
./detached-sig-apply.sh ${UNSIGNED} signature/osx
51+
./detached-sig-apply.sh ${UNSIGNED_APP} signature/osx/dist
4052
${WRAP_DIR}/xorrisofs -D -l -V "${OSX_VOLNAME}" -no-pad -r -dir-mode 0755 -o uncompressed.dmg signed-app
4153
${WRAP_DIR}/dmg dmg uncompressed.dmg ${OUTDIR}/${SIGNED}

contrib/gitian-descriptors/gitian-osx.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ script: |
138138
cp contrib/macdeploy/detached-sig-apply.sh unsigned-app-${i}
139139
cp contrib/macdeploy/detached-sig-create.sh unsigned-app-${i}
140140
cp ${BASEPREFIX}/${i}/native/bin/dmg unsigned-app-${i}
141-
cp ${BASEPREFIX}/${i}/native/bin/${i}-codesign_allocate unsigned-app-${i}/codesign_allocate
142-
cp ${BASEPREFIX}/${i}/native/bin/${i}-pagestuff unsigned-app-${i}/pagestuff
143141
mv dist unsigned-app-${i}
144142
pushd unsigned-app-${i}
145143
find . | sort | tar --mtime="$REFERENCE_DATETIME" --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-osx-unsigned.tar.gz

contrib/macdeploy/detached-sig-apply.sh

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ set -e
88

99
UNSIGNED="$1"
1010
SIGNATURE="$2"
11-
ARCH=x86_64
1211
ROOTDIR=dist
13-
TEMPDIR=signed.temp
1412
OUTDIR=signed-app
13+
SIGNAPPLE=signapple
1514

1615
if [ -z "$UNSIGNED" ]; then
1716
echo "usage: $0 <unsigned app> <signature>"
@@ -23,35 +22,6 @@ if [ -z "$SIGNATURE" ]; then
2322
exit 1
2423
fi
2524

26-
rm -rf ${TEMPDIR} && mkdir -p ${TEMPDIR}
27-
tar -C ${TEMPDIR} -xf ${UNSIGNED}
28-
cp -rf "${SIGNATURE}"/* ${TEMPDIR}
29-
30-
if [ -z "${PAGESTUFF}" ]; then
31-
PAGESTUFF=${TEMPDIR}/pagestuff
32-
fi
33-
34-
if [ -z "${CODESIGN_ALLOCATE}" ]; then
35-
CODESIGN_ALLOCATE=${TEMPDIR}/codesign_allocate
36-
fi
37-
38-
find ${TEMPDIR} -name "*.sign" | while read i; do
39-
SIZE=$(stat -c %s "${i}")
40-
TARGET_FILE="$(echo "${i}" | sed 's/\.sign$//')"
41-
42-
echo "Allocating space for the signature of size ${SIZE} in ${TARGET_FILE}"
43-
${CODESIGN_ALLOCATE} -i "${TARGET_FILE}" -a ${ARCH} ${SIZE} -o "${i}.tmp"
44-
45-
OFFSET=$(${PAGESTUFF} "${i}.tmp" -p | tail -2 | grep offset | sed 's/[^0-9]*//g')
46-
if [ -z ${QUIET} ]; then
47-
echo "Attaching signature at offset ${OFFSET}"
48-
fi
49-
50-
dd if="$i" of="${i}.tmp" bs=1 seek=${OFFSET} count=${SIZE} 2>/dev/null
51-
mv "${i}.tmp" "${TARGET_FILE}"
52-
rm "${i}"
53-
echo "Success."
54-
done
55-
mv ${TEMPDIR}/${ROOTDIR} ${OUTDIR}
56-
rm -rf ${TEMPDIR}
25+
${SIGNAPPLE} apply ${UNSIGNED} ${SIGNATURE}
26+
mv ${ROOTDIR} ${OUTDIR}
5727
echo "Signed: ${OUTDIR}"

contrib/macdeploy/detached-sig-create.sh

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,21 @@ set -e
88

99
ROOTDIR=dist
1010
BUNDLE="${ROOTDIR}/Bitcoin-Qt.app"
11-
CODESIGN=codesign
11+
SIGNAPPLE=signapple
1212
TEMPDIR=sign.temp
13-
TEMPLIST=${TEMPDIR}/signatures.txt
1413
OUT=signature-osx.tar.gz
15-
OUTROOT=osx
14+
OUTROOT=osx/dist
1615

1716
if [ -z "$1" ]; then
18-
echo "usage: $0 <codesign args>"
19-
echo "example: $0 -s MyIdentity"
17+
echo "usage: $0 <signapple args>"
18+
echo "example: $0 <path to key>"
2019
exit 1
2120
fi
2221

23-
rm -rf ${TEMPDIR} ${TEMPLIST}
22+
rm -rf ${TEMPDIR}
2423
mkdir -p ${TEMPDIR}
2524

26-
${CODESIGN} -f --file-list ${TEMPLIST} "$@" "${BUNDLE}"
27-
28-
grep -v CodeResources < "${TEMPLIST}" | while read i; do
29-
TARGETFILE="${BUNDLE}/$(echo "${i}" | sed "s|.*${BUNDLE}/||")"
30-
SIZE=$(pagestuff "$i" -p | tail -2 | grep size | sed 's/[^0-9]*//g')
31-
OFFSET=$(pagestuff "$i" -p | tail -2 | grep offset | sed 's/[^0-9]*//g')
32-
SIGNFILE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}.sign"
33-
DIRNAME="$(dirname "${SIGNFILE}")"
34-
mkdir -p "${DIRNAME}"
35-
echo "Adding detached signature for: ${TARGETFILE}. Size: ${SIZE}. Offset: ${OFFSET}"
36-
dd if="$i" of="${SIGNFILE}" bs=1 skip=${OFFSET} count=${SIZE} 2>/dev/null
37-
done
38-
39-
grep CodeResources < "${TEMPLIST}" | while read i; do
40-
TARGETFILE="${BUNDLE}/$(echo "${i}" | sed "s|.*${BUNDLE}/||")"
41-
RESOURCE="${TEMPDIR}/${OUTROOT}/${TARGETFILE}"
42-
DIRNAME="$(dirname "${RESOURCE}")"
43-
mkdir -p "${DIRNAME}"
44-
echo "Adding resource for: \"${TARGETFILE}\""
45-
cp "${i}" "${RESOURCE}"
46-
done
47-
48-
rm ${TEMPLIST}
25+
${SIGNAPPLE} sign -f --detach "${TEMPDIR}/${OUTROOT}" "$@" "${BUNDLE}"
4926

5027
tar -C "${TEMPDIR}" -czf "${OUT}" .
5128
rm -rf "${TEMPDIR}"

0 commit comments

Comments
 (0)