Subject: Re: RFC: Cryptographic attestation for email-based patch workflows

From: [email-masked]
Date: Fri, 27 Sep 2019 08:24:37 -0700

On 10.09.2019 08:13, Konstantin Ryabitsev wrote:
># Proposed approach
>
>I recommend that we provide a way to include cryptographic signature
>information natively using git-format-patch, using roughly the following
>process:
>
>- generate a signify-compatible cryptographic signature of the verbatim
>  patch content, perhaps slightly normalized for things like LF vs. CRLF
>  line endings (see minisign/libsodium for crypto details)
>- include both the signature and the public key in the area below '---',
>  using "Minisig:" and "Minikey:" taglines

I like where you're heading with this suggestion however there are some
issues. It is not clear what bytes the signature was calculated over.
Does it include the "From:" line of the email? How about the
"Signed-off-by"? If there is no binding of the identity of the submitter
to the key pair then you'll have problems with the TOFU policy you
describe further down (explained later). Also, since we're trying to
move to a Git that supports signatures from multiple different signing
tools and to also support multi-sig sign-offs (e.g. first the author,
then the reviewer, then the merger) these taglines need to be more
compex. At the very least either there needs to be a signature type
tagline or the type of the signature needs to be baked into the key and
signture values (see Secure Scuttlebutt encoding of keys/sigs). Also, if
we want to do chained multisign there should be some framing of what is
signed by each signature. If you're looking for something email like, we
could borrow from mime email attachment encoding to provide framing.

>For example:
>
>---8<---
>>From b41a2a0f817caddc9a76f43c3c9ed7d8edd6b2de Mon Sep 17 00:00:00 2001
>From: Konstantin Ryabitsev <[email-masked]>
>Date: Tue, 10 Sep 2019 06:15:36 -0400
>Subject: [PATCH] Second commit
>
>Change the greeting.
>
>Signed-off-by: Konstantin Ryabitsev <[email-masked]>
>---
> foo.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Minisig: RWT9fcUvSnHPLiqWgXEnn98sgk8nl4FteDRkD+9lVK+He//eLOxNZ5QjCROoKJgPGpL4uzoHicN+f6gB54qmtO1cQtfvjS+++QU=
> Minikey: RWT9fcUvSnHPLqqyfLbkGBMEscBWciFFp2iBj2XnZPzW69OVIoYwZ25q
>
>diff --git a/foo.c b/foo.c
>index d40a2b9..dcfad55 100644
>--- a/foo.c
>+++ b/foo.c
>@@ -1,5 +1,5 @@
> #include <stdio.h>
> int main()
> {
>-    printf("Hello, World!");
>+    printf("Hello, Signed World!");
> }
>--ᐞ
>2.21.0
>---8<---

I would instead have at the very least the signature tool in the value:

	Key: minisign|RWT9fcUvSnHPLqqyfLbkGBMEscBWciFFp2iBj2XnZPzW69OVIoYwZ25q
  Sig: minisign|RWT9fcUvSnHPLiqWgXEnn98sgk8nl4FteDRkD+9lVK+He//eLOxNZ5QjCROoKJgPGpL4uzoHicN+f6gB54qmtO1cQtfvjS+++QU=

But this doesn't solve multi-sig. 

>When git-am encounters a signed patch, it should:
>
>1. check if the email in From: matches existing entries in git's TOFU
>   (trust on first use) database, which is a simple key-value store
>   like:
>
>   [email-masked]: RWT9fcUvSnHPLqqyfLbkGBMEscBWciFFp2iBj2XnZPzW69OVIoYwZ25q
>
>2. if no matches, add a new entry to the TOFU tracking database and
>   consider the key automatically trusted (perhaps configurable)
>3. if there are existing matches:
>
>   a. compare the keys to make sure they haven't changed
>   b. if keys changed, emit a warning and let developer decide if they
>      trust the key change
>   c. if keys did not change, validate the signature
>   d. if validation failed, alert the developer and error out
>
>4. if the TOFU db exists at all, git-am should check if the email
>   address in From: matches any existing records and alert if the patch
>   carries no signature (in case it's been removed by a malicious
>   attacker).
>
>All of these operations should be sufficiently fast, since both ECC
>crypto and key-value lookups are fast operations that don't require a
>lot of resources.

TOFU has the problem of not providing cryptographic provenance over keys
while maintaining provenance on the binding between other identity
attributes and those keys (e.g. author string). In step 3 above there's
no way to know for sure that the submitter is actually who they claim to
be. Reviewers have no way of knowing that the new key used with the
patch is a legitimate key update. The only option with this design is to
do some out-of-band key verification (i.e. call the submitter and have
them read the key to you over the phone). Out-of-band key validation
hasn't scaled for GPG and it won't scale here either.

Instead of TOFU, a more secure design would require key enrollment, key
rotation, key recovery, and key revocation to all be separate,
cryptographically verified updates to the attribute-to-key database in
the repo. Your instinct for storing the attribute+key data in the repo
itself (i.e. in-band) is correct because it makes Git repos
self-verifiable in that cloning is all you need to do to get all of the
data necessary for verifying all of the digital signatures.

Key enrollment should be a separate patch submission that adds the
author and public key to the database file. The patch must be signed
using the key that is being added to the database. This provides the
provenance anchor for the key and also binds the attribute to the key.
The record in the data should also contain some data that enables secure
key recovery/rotation. A simple hashed secret passphrase and nonce
works. In the future, key recovery/rotation can be done by the owner by
submitting a new patch that updates the database record with a new key
and recovery data, signed with the new key and also including the nonce
and secret passphrase used to generate the previous key recovery hash.
Key revocation is a patch that removes the record from the database that
is signed by the key that is being removed or a new key plus the
recovery secret passphrase and nonce.

So back to the original proposal, I like the simplicity but with a few
tweaks, it could be an air tight digital signature scheme for emailed
patches. If air tight provenance is not what you're aiming for, then why
are you even using cryptography?

That's my 2p on this. I like where you're head is at Kontantin.

Cheers!
Dave