···55 "crypto/sha256"66 "encoding/base64"77 "fmt"88- "strings"98109 "github.com/hiddeco/sshsig"1110 "golang.org/x/crypto/ssh"1212- "tangled.org/core/types"1311)14121513func VerifySignature(pubKey, signature, payload []byte) (error, bool) {···2628 // multiple algorithms but sha-512 is most secure, and git's ssh signing defaults2729 // to sha-512 for all key types anyway.2830 err = sshsig.Verify(buf, sig, pub, sshsig.HashSHA512, "git")3131+2932 return err, err == nil3030-}3131-3232-// VerifyCommitSignature reconstructs the payload used to sign a commit. This is3333-// essentially the git cat-file output but without the gpgsig header.3434-//3535-// Caveats: signature verification will fail on commits with more than one parent,3636-// i.e. merge commits, because types.NiceDiff doesn't carry more than one Parent field3737-// and we are unable to reconstruct the payload correctly.3838-//3939-// Ideally this should directly operate on an *object.Commit.4040-func VerifyCommitSignature(pubKey string, commit types.NiceDiff) (error, bool) {4141- signature := commit.Commit.PGPSignature4242-4343- author := bytes.NewBuffer([]byte{})4444- committer := bytes.NewBuffer([]byte{})4545- commit.Commit.Author.Encode(author)4646- commit.Commit.Committer.Encode(committer)4747-4848- payload := strings.Builder{}4949-5050- fmt.Fprintf(&payload, "tree %s\n", commit.Commit.Tree)5151- if commit.Commit.Parent != "" {5252- fmt.Fprintf(&payload, "parent %s\n", commit.Commit.Parent)5353- }5454- fmt.Fprintf(&payload, "author %s\n", author.String())5555- fmt.Fprintf(&payload, "committer %s\n", committer.String())5656- if commit.Commit.ChangedId != "" {5757- fmt.Fprintf(&payload, "change-id %s\n", commit.Commit.ChangedId)5858- }5959- fmt.Fprintf(&payload, "\n%s", commit.Commit.Message)6060-6161- return VerifySignature([]byte(pubKey), []byte(signature), []byte(payload.String()))6233}63346435// SSHFingerprint computes the fingerprint of the supplied ssh pubkey.