Skip to content

Commit 072ed25

Browse files
committed
torchwood: fix cosignatures of checkpoints with extension lines
Reported by @rozbb.
1 parent bdd7268 commit 072ed25

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## v0.6.1
2+
3+
### torchwood
4+
5+
- Fix `CosignatureSigner`/`CosignatureVerifier` to correctly sign and verify
6+
checkpoints with extension lines, according to c2sp.org/tlog-cosignature.
7+
18
## v0.6.0
29

310
Switched to Go project LICENSE (BSD-3-Clause).

cosignature.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,18 @@ func formatCosignatureV1(t uint64, msg []byte) ([]byte, error) {
7777
//
7878
// cosignature/v1
7979
// time TTTTTTTTTT
80-
// origin line
81-
// NNNNNNNNN
82-
// tree hash
80+
// [checkpoint]
8381
//
84-
// where TTTTTTTTTT is the current UNIX timestamp, and the following
85-
// three lines are the first three lines of the note. All other
86-
// lines are not processed by the witness, so are not signed.
82+
// where TTTTTTTTTT is the current UNIX timestamp.
8783

8884
c, err := ParseCheckpoint(string(msg))
8985
if err != nil {
9086
return nil, fmt.Errorf("message being signed is not a valid checkpoint: %w", err)
9187
}
92-
return []byte(fmt.Sprintf(
93-
"cosignature/v1\ntime %d\n%s\n%d\n%s\n",
94-
t, c.Origin, c.N, base64.StdEncoding.EncodeToString(c.Hash[:]))), nil
88+
if string(msg) != c.String() {
89+
return nil, errors.New("message being signed does not match parsed checkpoint")
90+
}
91+
return []byte(fmt.Sprintf("cosignature/v1\ntime %d\n%s", t, msg)), nil
9592
}
9693

9794
// CosignatureSigner is a [note.Signer] that produces timestamped

cosignature_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package torchwood_test
22

33
import (
4+
"bytes"
45
"crypto/ed25519"
56
"crypto/rand"
67
"testing"
@@ -20,7 +21,7 @@ func TestSignerRoundtrip(t *testing.T) {
2021
t.Fatal(err)
2122
}
2223

23-
msg := "test\n123\nf+7CoKgXKE/tNys9TTXcr/ad6U/K3xvznmzew9y6SP0=\n"
24+
msg := "test\n123\nf+7CoKgXKE/tNys9TTXcr/ad6U/K3xvznmzew9y6SP0=\nextension 1\nextension 2\n"
2425
n, err := note.Sign(&note.Note{Text: msg}, s)
2526
if err != nil {
2627
t.Fatal(err)
@@ -29,4 +30,9 @@ func TestSignerRoundtrip(t *testing.T) {
2930
if _, err := note.Open(n, note.VerifierList(s.Verifier())); err != nil {
3031
t.Fatal(err)
3132
}
33+
34+
nn := bytes.Replace(n, []byte("extension 2"), []byte("extension X"), 1)
35+
if _, err := note.Open(nn, note.VerifierList(s.Verifier())); err == nil {
36+
t.Fatal("expected error verifying modified note, got nil")
37+
}
3238
}

0 commit comments

Comments
 (0)