Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions note/note_cosigv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ func formatMLDSACosignatureV1(cosignerName string, timestamp uint64, logOrigin s
if start > 0 && timestamp > 0 {
return nil, errInvalidTimestamp
}
if len(logOrigin) > 255 || len(cosignerName) > 255 {
return nil, errSignerID
}

// The signed message is a binary TLS presentation encoding of the
// following structure:
Expand Down Expand Up @@ -499,6 +502,9 @@ func (v *SubtreeVerifier) VerifySubtree(timestamp uint64, logOrigin string, star
// isValidName reports whether name is valid.
// It must be non-empty and not have any Unicode spaces or pluses.
func isValidName(name string) bool {
if len(name) >= 255 {
return false
}
return name != "" && utf8.ValidString(name) && strings.IndexFunc(name, unicode.IsSpace) < 0 && !strings.Contains(name, "+")
}

Expand Down
41 changes: 40 additions & 1 deletion note/note_cosigv1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package note

import (
"crypto/rand"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -48,7 +49,41 @@ func TestSignerRoundtrip(t *testing.T) {
}
}

func TestCosignnatureV1RoundTrip(t *testing.T) {
func TestFormatMLDSASignatureV1(t *testing.T) {
for _, test := range []struct {
name string
cosignerName string
logOrigin string
wantErr bool
}{
{
name: "ok",
cosignerName: "mldsa",
logOrigin: "test",
},
{
name: "origin name too long",
cosignerName: "mldsa",
logOrigin: strings.Repeat("t", 256),
wantErr: true,
},
{
name: "cosigner name too long",
cosignerName: "mldsa"+strings.Repeat("a", 255),
logOrigin: "test",
wantErr: true,
},
} {
t.Run(test.name, func(t *testing.T) {
_, err := formatMLDSACosignatureV1(test.cosignerName, 0, test.logOrigin, 0, 0, []byte{})
if gotErr := err != nil; gotErr != test.wantErr {
t.Fatalf("formatMLDSACosignatureV1: got %v", err)
}
})
}
}

func TestCosignatureV1RoundTrip(t *testing.T) {
edSk, edPk := mustGenerateEd25519Key(t, "ed25519")
mlSk, mlPk := mustGenerateMLDSAKey(t, "mldsa")
for _, test := range []struct {
Expand Down Expand Up @@ -340,6 +375,10 @@ func TestGenerateMLDSAKey(t *testing.T) {
name: "invalid name",
wantErr: true,
},
{
name: "name-too-long"+strings.Repeat("g", 255),
wantErr: true,
},
} {
t.Run(test.name, func(t *testing.T) {
skey, vkey, err := GenerateMLDSAKey(test.name)
Expand Down
Loading