Skip to content

Conversation

@achow101
Copy link
Member

@achow101 achow101 commented Jan 7, 2021

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, 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.

@benthecarman
Copy link
Contributor

Concept ACK

@laanwj
Copy link
Member

laanwj commented Jan 7, 2021

Concept ACK, nice!

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 8, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@jonasschnelli
Copy link
Contributor

Impressive work! Well done @achow101.
I used this tool to sign 0.21.0rc5 (with external codesign_allocate).
Concept ACK (will test soon).

@jonatack
Copy link
Member

jonatack commented Jan 8, 2021

Concept ACK -- nice work!

@DrahtBot
Copy link
Contributor

Guix builds

File commit 7838db1
(master)
commit 3343f320287d6b520b46ed062e26dde51cb329d0
(master and this pull)
*-aarch64-linux-gnu-debug.tar.gz 8093dc2cc77f5e62... 8816ed48879ae85c...
*-aarch64-linux-gnu.tar.gz 96c6dc48f1df87f0... 1da08e1d691ad3ae...
*-arm-linux-gnueabihf-debug.tar.gz 820015874934cc21... 43e8f58df97c4b0a...
*-arm-linux-gnueabihf.tar.gz d4bd4a8809b37004... 0e0be7f0e826b3e6...
*-riscv64-linux-gnu-debug.tar.gz c6fa94dc565668e1... bb6a6f94f75d70a8...
*-riscv64-linux-gnu.tar.gz 96f4ac5d990f244d... d54c423638111834...
*-win-unsigned.tar.gz 760ddb798cec381d... 1f102058f2d1c17e...
*-win64-debug.zip 67a033edbdc22d99... 51a89a6b8df0baed...
*-win64-setup-unsigned.exe 0dea7c57960acdc4... 304123eebfb4fc9a...
*-win64.zip bbd519ae55978259... e8034bf11676bb15...
*-x86_64-linux-gnu-debug.tar.gz 6ecaa1e63630cc45... 5a076f091e0997b1...
*-x86_64-linux-gnu.tar.gz 87c8fcc8cb888efd... 1626bb21ddc9cd4c...
*.tar.gz 69d589c9e9b4152c... c11f84cdf66d2f6f...
guix_build.log 13410f62f1e3176b... 82caa52f891abeb3...
guix_build.log.diff 45becbccac40d0e0...

@DrahtBot
Copy link
Contributor

🕵️ @sipa @practicalswift have been requested to review this pull request as specified in the REVIEWERS file.

@laanwj
Copy link
Member

laanwj commented Jan 14, 2021

Code review ACK 2c40327

Also cursory code review ACK on the signer tool achow101/signapple@c7e73aa—I can't vouch it does exactly the same as Apple's tool, but it definitely follows a similar structure as their code, and modifies the same parts of the binary. It most notably doesn't change any code so it won't introduce a back door itself.

Additionally, the codesign_allocate and pagestuff tools are no longer necessary so they are no longer added to the tarball used in code signing.

+24 −67
Good riddance. Nice cleanups!

@DrahtBot
Copy link
Contributor

Gitian builds

File commit 8ffaf5c
(master)
commit 4044d10f8ed7baff70542ee8b2b3373dcdac3a99
(master and this pull)
*-osx-unsigned.dmg d6287425560ba4c8... 8b5537852524c54d...
*-osx64.tar.gz d2636c99f4f6ae44... 32eb08228f92c5d6...
*.tar.gz ce4d207f0203c991... 12def18cbd5b578f...
bitcoin-core-osx-22-res.yml f565610bc956d740... 0cc5413fe2502acf...
linux-build.log 5ae7d55d43bde935... 141ee861fff8c272...
osx-build.log 14b6de642b3613a1... e5dd5bebc9d57036...
win-build.log 7c2f349972850c1b... 748a218c0ca36b13...
bitcoin-core-osx-22-res.yml.diff d54e47a630f5db9a...
linux-build.log.diff e8972241a1433c14...
osx-build.log.diff 7939aa708a2ee391...
win-build.log.diff f188f742572cd1a7...

@laanwj laanwj merged commit f7fd76b into bitcoin:master Jan 18, 2021
@maflcko
Copy link
Member

maflcko commented Jan 20, 2021

Does this need backport?

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 20, 2021
achow101 added a commit to achow101/bitcoin that referenced this pull request Jun 8, 2021
achow101 added a commit to achow101/bitcoin that referenced this pull request Jun 8, 2021
achow101 added a commit to achow101/bitcoin that referenced this pull request Jun 8, 2021
achow101 added a commit to achow101/bitcoin that referenced this pull request Jun 8, 2021
achow101 added a commit to achow101/bitcoin that referenced this pull request Jun 8, 2021
achow101 added a commit to achow101/bitcoin that referenced this pull request Jun 8, 2021
achow101 added a commit to achow101/bitcoin that referenced this pull request Jun 8, 2021
achow101 added a commit to achow101/bitcoin that referenced this pull request Jun 8, 2021
maflcko pushed a commit that referenced this pull request Jun 19, 2021
0fe60a8 Use latest signapple commit (Andrew Chow)
5313d6a gitian: Remove codesign_allocate and pagestuff from MacOS build (Andrew Chow)
27d691b gitian: use signapple to create the MacOS code signature (Andrew Chow)
2f33e33 gitian: use signapple to apply the MacOS code signature (Andrew Chow)
65ce833 gitian: install signapple in gitian-osx-signer.yml (Andrew Chow)

Pull request description:

  Backport of #20880 and #22190

ACKs for top commit:
  MarcoFalke:
    cherry-pick-only ACK 0fe60a8 🍀

Tree-SHA512: e864048fab02a1857161602dd53abba552ca3f859c133a47a5e62c28d3e4de9cd099bce86123a1b5892042b09f51cc1ddd2ed1b0c71bfba162710eaee3f5bf91
maflcko pushed a commit that referenced this pull request Jun 19, 2021
890397c Use latest signapple commit (Andrew Chow)
a17041e gitian: Remove codesign_allocate and pagestuff from MacOS build (Andrew Chow)
9c7c0e6 gitian: use signapple to create the MacOS code signature (Andrew Chow)
f834485 gitian: use signapple to apply the MacOS code signature (Andrew Chow)
a2650f6 gitian: install signapple in gitian-osx-signer.yml (Andrew Chow)

Pull request description:

  Backport of #20880 and #22190

ACKs for top commit:
  MarcoFalke:
    cherry-pick-only ACK 890397c 💢

Tree-SHA512: 7467f664f1673152118c19f6cc31dabf05a34f37d7ea0e687ff5f740f9dfa5aab57a4b90d24c0cbb919830e6ab2dd131af147789576fcd9d3d444e7d61bd14ea
UNSIGNED=bitcoin-osx-unsigned.tar.gz
# Install signapple
cd signapple
python3 -m pip install -U pip setuptools
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using LXC (LXC 4.0.6 on Ubuntu Focal) this line fails with the following error:

...
+ python3 -m pip install -U pip setuptools
Collecting pip
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f82adc3a860>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pip/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f82adc3a978>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pip/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f82adc3aa58>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pip/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f82adc3ab38>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pip/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f82adc3abe0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',)': /simple/pip/
  Could not find a version that satisfies the requirement pip (from versions: )
No matching distribution found for pip
...

UdjinM6 pushed a commit to UdjinM6/dash that referenced this pull request Aug 17, 2022
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants