Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release: create and verify detached signatures, fix hashing command on MacOS #5019

Merged
merged 4 commits into from
Feb 15, 2021

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Feb 12, 2021

Fixes #4966.

This PR updates the verification script to now look for detached signatures instead of clear signed ones.
Can be tested on v0.12.1-beta.rc3, I've uploaded a detached signature.

Also fixes an issue with the sha256sum command not being available on MacOS.

@guggero guggero added golang/build system Related to the go language and compiler verification labels Feb 12, 2021
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

Good catch, LGTM 👍

cat "$signature"
exit 1
fi

if ! grep -q "$LNCLI_SUM" "$signature"; then
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, so we could actually be signing different manifests, but the signatures would verify anyway?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We used the --clear-sign flag before which overwrote the --detach-sign flag. So we didn't actually produce detached signatures.

If we start creating detached signatures, then the manifest they signed must be specified when verifying. So the manifest must match exactly and be present on the file system. The .sig file will only contain the raw signature, nothing more.
That's why we now have to look in the manifest text file for the hash.

I didn't do this at first because the manifest text file wasn't yet fully reproducible (because of the vendor mismatch and the sorting of the file itself). But now that that problem is out of the way we can actually start all signing the same manifest file and just upload the detached signature.

docs/release.md Outdated Show resolved Hide resolved
if ! grep -q "$LND_SUM" "$signature"; then
echo "ERROR: Hash $LND_SUM for lnd not found in $signature: "
# manifest.
if ! grep -q "$LND_SUM" "$MANIFEST"; then
Copy link
Contributor

Choose a reason for hiding this comment

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

prbably out of scope for this PR, but could be useful to verify arbitrary lnd binary without having to install it.

Usecase is I build the release and verify the signatures without having to install it (I might have a dev build installed that I'm running)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good idea! Created a separate PR: #5021

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to make the check stricter by grepping for ”^<hash> “ so it is extracted from the first column?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, good idea. Done.

scripts/verify-install.sh Outdated Show resolved Hide resolved
@halseth
Copy link
Contributor

halseth commented Feb 12, 2021

Tested, and works on macOS 👍

Only thing I noticed is that the signature is printed in binary if verification fails.

Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

Nice diff! This looks like it’s almost ready to go.

One other doc that needs to be updated is the auto populated release notes and the manifest verification command displayed there

if ! grep -q "$LND_SUM" "$signature"; then
echo "ERROR: Hash $LND_SUM for lnd not found in $signature: "
# manifest.
if ! grep -q "$LND_SUM" "$MANIFEST"; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to make the check stricter by grepping for ”^<hash> “ so it is extracted from the first column?

docs/release.md Outdated Show resolved Hide resolved
exit 1
fi

echo "Verified lnd and lncli hashes against $signature"
echo "Verified lnd and lncli hashes against $MANIFEST"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think the hashes only need to be verified once now, e.g.:

for sig in signatures:
    verify sig
#everyone agrees on manifest
check lnd hash
check lncli hash

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed! Though if the hashes don't match we don't need to look at the signatures. So I put the hash check first.

Copy link
Contributor

@cfromknecht cfromknecht Feb 12, 2021

Choose a reason for hiding this comment

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

My bad, on mobile it looked like this check was still happening per signature. However I still think we want the hash checking should occur after the signature verification.

Though if the hashes don't match we don't need to look at the signatures. So I put the hash check first.

As an optimization, that's true. This is more about what surfacing what is actually wrong with the verification.

If we check hashes first, you don't know whether the manifest is actually agreed upon by all developers. If all the developers signed the correct manifest, but the manifest on github is invalid the user will see that the hash wasn't included. They might think that they've built the wrong binary, but the error that user should see is that the signatures disagree with the github manifest.

Once we know everyone agrees, then we can return whether the hash of your binary is not in the signed manifest.

Signature disagreement represents a faulty/backdoored release process, the latter just means you don't have the correct binary. Perhaps we should also be more specific about these failure modes in the error messages, e.g. "the expected release binaries have been verified with the developer signatures, but you seem to have an invalid binary." vs "the developer signatures disagree on the expected release binaries, the release may have been faulty or backdoored"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the hash check was still in the loop over each signature in the version you initially reviewed.

I now moved it to after the signature check. It totally makes sense with the scenario you describe, I just didn't think of this and hence the premature optimization 😅

I also updated some of the error messages to reflect your suggestion.

@guggero
Copy link
Collaborator Author

guggero commented Feb 12, 2021

One other doc that needs to be updated is the auto populated release notes and the manifest verification command displayed there

Yes, fixed as well.

Because the sha256sum binary isn't available on MacOS we instead use the
shasum -a 256 command that was used before.
To make sure we've actually calculated the hash correctly, we make sure
it's 64 characters long.
Due to a misunderstanding of how the gpg command line options work, we
didn't actually create detached signatures because the --clear-sign
flag would overwrite that. We update our verification script to now only
download the detached signatures and verify them against the main
manifest file.
We also update the signing instructions.
We want to be more precise in what exactly went wrong and what the cause
could be.
Copy link
Contributor

@cfromknecht cfromknecht left a comment

Choose a reason for hiding this comment

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

Great changes @guggero, LGTM! 🔏

@cfromknecht cfromknecht merged commit 12182d0 into lightningnetwork:master Feb 15, 2021
@cfromknecht cfromknecht mentioned this pull request Feb 15, 2021
@guggero guggero deleted the detach-sign branch February 23, 2021 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
golang/build system Related to the go language and compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide detached binary signatures
3 participants