diff --git a/pkg/api/tlog.go b/pkg/api/tlog.go index 2cfa5c896650122d5e428c9027591d79087f4b0b..c3fa516e752f740280a312225a0ff08a88de6e8d 100644 --- a/pkg/api/tlog.go +++ b/pkg/api/tlog.go @@ -51,9 +51,9 @@ func GetLogInfoHandler(params tlog.GetLogInfoParams) middleware.Responder { treeSize := int64(root.TreeSize) sth, err := util.CreateSignedCheckpoint(util.Checkpoint{ - Ecosystem: "Rekor", - Size: root.TreeSize, - Hash: root.RootHash, + Origin: "Rekor", + Size: root.TreeSize, + Hash: root.RootHash, }) if err != nil { return handleRekorAPIError(params, http.StatusInternalServerError, fmt.Errorf("marshalling error: %w", err), sthGenerateError) diff --git a/pkg/util/checkpoint.go b/pkg/util/checkpoint.go index 9bb171400debaebdb6094680b73b5ab9d9bf1181..47ca308b81b16c0670219cfd0f3ded4a3ab1fd25 100644 --- a/pkg/util/checkpoint.go +++ b/pkg/util/checkpoint.go @@ -28,8 +28,8 @@ import ( // heavily borrowed from https://github.com/google/trillian-examples/blob/master/formats/log/checkpoint.go type Checkpoint struct { - // Ecosystem is the ecosystem/version string - Ecosystem string + // Origin is the unique identifier/version string + Origin string // Size is the number of entries in the log at this checkpoint. Size uint64 // Hash is the hash which commits to the contents of the entire log. @@ -41,7 +41,7 @@ type Checkpoint struct { // String returns the String representation of the Checkpoint func (c Checkpoint) String() string { var b strings.Builder - fmt.Fprintf(&b, "%s\n%d\n%s\n", c.Ecosystem, c.Size, base64.StdEncoding.EncodeToString(c.Hash)) + fmt.Fprintf(&b, "%s\n%d\n%s\n", c.Origin, c.Size, base64.StdEncoding.EncodeToString(c.Hash)) for _, line := range c.OtherContent { fmt.Fprintf(&b, "%s\n", line) } @@ -70,8 +70,8 @@ func (c *Checkpoint) UnmarshalCheckpoint(data []byte) error { if len(l) < 4 { return errors.New("invalid checkpoint - too few newlines") } - eco := string(l[0]) - if len(eco) == 0 { + origin := string(l[0]) + if len(origin) == 0 { return errors.New("invalid checkpoint - empty ecosystem") } size, err := strconv.ParseUint(string(l[1]), 10, 64) @@ -83,9 +83,9 @@ func (c *Checkpoint) UnmarshalCheckpoint(data []byte) error { return fmt.Errorf("invalid checkpoint - invalid hash: %w", err) } *c = Checkpoint{ - Ecosystem: eco, - Size: size, - Hash: h, + Origin: origin, + Size: size, + Hash: h, } if len(l) >= 3 { for _, line := range l[3:] { diff --git a/pkg/util/checkpoint_test.go b/pkg/util/checkpoint_test.go index 3d6d3eb0953c8e9ad517111485a72d003f4849d3..008c0aa1edb96310c896ac7905814c61a62e8b3c 100644 --- a/pkg/util/checkpoint_test.go +++ b/pkg/util/checkpoint_test.go @@ -40,21 +40,21 @@ func TestMarshalCheckpoint(t *testing.T) { }{ { c: Checkpoint{ - Ecosystem: "Log Checkpoint v0", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint v0", + Size: 123, + Hash: []byte("bananas"), }, want: "Log Checkpoint v0\n123\nYmFuYW5hcw==\n", }, { c: Checkpoint{ - Ecosystem: "Banana Checkpoint v5", - Size: 9944, - Hash: []byte("the view from the tree tops is great!"), + Origin: "Banana Checkpoint v5", + Size: 9944, + Hash: []byte("the view from the tree tops is great!"), }, want: "Banana Checkpoint v5\n9944\ndGhlIHZpZXcgZnJvbSB0aGUgdHJlZSB0b3BzIGlzIGdyZWF0IQ==\n", }, { c: Checkpoint{ - Ecosystem: "Banana Checkpoint v7", + Origin: "Banana Checkpoint v7", Size: 9943, Hash: []byte("the view from the tree tops is great!"), OtherContent: []string{"foo", "bar"}, @@ -85,23 +85,23 @@ func TestUnmarshalCheckpoint(t *testing.T) { desc: "valid one", m: "Log Checkpoint v0\n123\nYmFuYW5hcw==\n", want: Checkpoint{ - Ecosystem: "Log Checkpoint v0", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint v0", + Size: 123, + Hash: []byte("bananas"), }, }, { desc: "valid with different ecosystem", m: "Banana Checkpoint v1\n9944\ndGhlIHZpZXcgZnJvbSB0aGUgdHJlZSB0b3BzIGlzIGdyZWF0IQ==\n", want: Checkpoint{ - Ecosystem: "Banana Checkpoint v1", - Size: 9944, - Hash: []byte("the view from the tree tops is great!"), + Origin: "Banana Checkpoint v1", + Size: 9944, + Hash: []byte("the view from the tree tops is great!"), }, }, { desc: "valid with trailing data", m: "Log Checkpoint v0\n9944\ndGhlIHZpZXcgZnJvbSB0aGUgdHJlZSB0b3BzIGlzIGdyZWF0IQ==\nHere's some associated data.\n", want: Checkpoint{ - Ecosystem: "Log Checkpoint v0", + Origin: "Log Checkpoint v0", Size: 9944, Hash: []byte("the view from the tree tops is great!"), OtherContent: []string{"Here's some associated data."}, @@ -110,7 +110,7 @@ func TestUnmarshalCheckpoint(t *testing.T) { desc: "valid with multiple trailing data lines", m: "Log Checkpoint v0\n9944\ndGhlIHZpZXcgZnJvbSB0aGUgdHJlZSB0b3BzIGlzIGdyZWF0IQ==\nlots\nof\nlines\n", want: Checkpoint{ - Ecosystem: "Log Checkpoint v0", + Origin: "Log Checkpoint v0", Size: 9944, Hash: []byte("the view from the tree tops is great!"), OtherContent: []string{"lots", "of", "lines"}, @@ -119,9 +119,9 @@ func TestUnmarshalCheckpoint(t *testing.T) { desc: "valid with trailing newlines", m: "Log Checkpoint v0\n9944\ndGhlIHZpZXcgZnJvbSB0aGUgdHJlZSB0b3BzIGlzIGdyZWF0IQ==\n\n\n\n", want: Checkpoint{ - Ecosystem: "Log Checkpoint v0", - Size: 9944, - Hash: []byte("the view from the tree tops is great!"), + Origin: "Log Checkpoint v0", + Size: 9944, + Hash: []byte("the view from the tree tops is great!"), }, }, { desc: "invalid - insufficient lines", @@ -184,9 +184,9 @@ func TestSigningRoundtripCheckpoint(t *testing.T) { }{ { c: Checkpoint{ - Ecosystem: "Log Checkpoint RSA v0", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint RSA v0", + Size: 123, + Hash: []byte("bananas"), }, identity: "someone", signer: rsaKey, @@ -197,9 +197,9 @@ func TestSigningRoundtripCheckpoint(t *testing.T) { }, { c: Checkpoint{ - Ecosystem: "Log Checkpoint ECDSA v0", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint ECDSA v0", + Size: 123, + Hash: []byte("bananas"), }, identity: "someone", signer: ecdsaKey, @@ -210,9 +210,9 @@ func TestSigningRoundtripCheckpoint(t *testing.T) { }, { c: Checkpoint{ - Ecosystem: "Log Checkpoint Ed25519 v0", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint Ed25519 v0", + Size: 123, + Hash: []byte("bananas"), }, identity: "someone", signer: edPrivKey, @@ -223,9 +223,9 @@ func TestSigningRoundtripCheckpoint(t *testing.T) { }, { c: Checkpoint{ - Ecosystem: "Log Checkpoint Mismatch v0", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint Mismatch v0", + Size: 123, + Hash: []byte("bananas"), }, identity: "someone", signer: edPrivKey, @@ -236,9 +236,9 @@ func TestSigningRoundtripCheckpoint(t *testing.T) { }, { c: Checkpoint{ - Ecosystem: "Log Checkpoint Mismatch v1", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint Mismatch v1", + Size: 123, + Hash: []byte("bananas"), }, identity: "someone", signer: ecdsaKey, @@ -249,9 +249,9 @@ func TestSigningRoundtripCheckpoint(t *testing.T) { }, { c: Checkpoint{ - Ecosystem: "Log Checkpoint Mismatch v2", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint Mismatch v2", + Size: 123, + Hash: []byte("bananas"), }, identity: "someone", signer: edPrivKey, @@ -262,9 +262,9 @@ func TestSigningRoundtripCheckpoint(t *testing.T) { }, { c: Checkpoint{ - Ecosystem: "Log Checkpoint Mismatch v3", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint Mismatch v3", + Size: 123, + Hash: []byte("bananas"), }, identity: "someone", signer: ecdsaKey, @@ -274,7 +274,7 @@ func TestSigningRoundtripCheckpoint(t *testing.T) { wantVerifyErr: true, }, } { - t.Run(string(test.c.Ecosystem), func(t *testing.T) { + t.Run(string(test.c.Origin), func(t *testing.T) { sth, err := CreateSignedCheckpoint(test.c) if err != nil { t.Fatalf("error creating signed checkpoint") @@ -332,9 +332,9 @@ func TestInvalidSigVerification(t *testing.T) { }{ { checkpoint: Checkpoint{ - Ecosystem: "Log Checkpoint v0", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint v0", + Size: 123, + Hash: []byte("bananas"), }, s: []note.Signature{}, pubKey: ecdsaKey.Public(), @@ -343,9 +343,9 @@ func TestInvalidSigVerification(t *testing.T) { { checkpoint: Checkpoint{ - Ecosystem: "Log Checkpoint v0 not base64", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint v0 not base64", + Size: 123, + Hash: []byte("bananas"), }, pubKey: ecdsaKey.Public(), s: []note.Signature{ @@ -359,9 +359,9 @@ func TestInvalidSigVerification(t *testing.T) { }, { checkpoint: Checkpoint{ - Ecosystem: "Log Checkpoint v0 invalid signature", - Size: 123, - Hash: []byte("bananas"), + Origin: "Log Checkpoint v0 invalid signature", + Size: 123, + Hash: []byte("bananas"), }, pubKey: ecdsaKey.Public(), s: []note.Signature{ @@ -374,7 +374,7 @@ func TestInvalidSigVerification(t *testing.T) { expectedResult: false, }, } { - t.Run(string(test.checkpoint.Ecosystem), func(t *testing.T) { + t.Run(string(test.checkpoint.Origin), func(t *testing.T) { text, _ := test.checkpoint.MarshalCheckpoint() sc := SignedNote{ Note: string(text), diff --git a/pkg/util/timestamp_note.go b/pkg/util/timestamp_note.go index 0f2961e584b3f74d5e01aa6cfcc84cd27f1cea15..801ba704fc67622e0e8955fbac225e1328e27be6 100644 --- a/pkg/util/timestamp_note.go +++ b/pkg/util/timestamp_note.go @@ -30,8 +30,8 @@ import ( // Signed note based timestamp responses type TimestampNote struct { - // Ecosystem is the ecosystem/version string - Ecosystem string + // Origin is the unique identifier/version string + Origin string // MessageImprint is the hash of the message to timestamp, of the form sha256:<sha> MessageImprint string // Nonce is a short random bytes to prove response freshness @@ -50,7 +50,7 @@ type TimestampNote struct { func (t TimestampNote) String() string { var b strings.Builder time, _ := t.Time.MarshalText() - fmt.Fprintf(&b, "%s\n%s\n%s\n%s\n%d\n%s\n", t.Ecosystem, t.MessageImprint, base64.StdEncoding.EncodeToString(t.Nonce), + fmt.Fprintf(&b, "%s\n%s\n%s\n%s\n%d\n%s\n", t.Origin, t.MessageImprint, base64.StdEncoding.EncodeToString(t.Nonce), time, t.Radius, t.CertChainRef) for _, line := range t.OtherContent { fmt.Fprintf(&b, "%s\n", line) @@ -83,8 +83,8 @@ func (t *TimestampNote) UnmarshalText(data []byte) error { if len(l) < 7 { return errors.New("invalid timestamp note - too few newlines") } - eco := string(l[0]) - if len(eco) == 0 { + origin := string(l[0]) + if len(origin) == 0 { return errors.New("invalid timestamp note - empty ecosystem") } h := string(l[1]) @@ -110,7 +110,7 @@ func (t *TimestampNote) UnmarshalText(data []byte) error { } *t = TimestampNote{ - Ecosystem: eco, + Origin: origin, MessageImprint: h, Nonce: nonce, Time: timestamp, diff --git a/pkg/util/timestamp_note_test.go b/pkg/util/timestamp_note_test.go index 5f6e6c47800355c73abfe87ff821f4350ce68fe3..f263e1d8544b897519c511e773ba3db751dac4c5 100644 --- a/pkg/util/timestamp_note_test.go +++ b/pkg/util/timestamp_note_test.go @@ -55,7 +55,7 @@ func TestMarshalTimestampNote(t *testing.T) { { msg: []byte("bananas"), t: TimestampNote{ - Ecosystem: "Timestamp Note v0", + Origin: "Timestamp Note v0", Nonce: big.NewInt(123).Bytes(), Time: someTime, Radius: 123, @@ -66,7 +66,7 @@ func TestMarshalTimestampNote(t *testing.T) { { msg: []byte("the view from the tree tops is great!"), t: TimestampNote{ - Ecosystem: "Timestamp Note v1", + Origin: "Timestamp Note v1", Nonce: big.NewInt(12345678).Bytes(), Time: someTime, Radius: 1, @@ -76,7 +76,7 @@ func TestMarshalTimestampNote(t *testing.T) { }, { msg: []byte("bananas"), t: TimestampNote{ - Ecosystem: "Timestamp Note v7", + Origin: "Timestamp Note v7", Nonce: big.NewInt(123).Bytes(), Time: someTime, Radius: 123, @@ -86,7 +86,7 @@ func TestMarshalTimestampNote(t *testing.T) { want: "Timestamp Note v7\nsha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904\new==\n2021-07-26T00:00:00Z\n123\nhttp://localhost:3000/api/v1/timestamp/certchain\nfoo\nbar\n", }, } { - t.Run(string(test.t.Ecosystem), func(t *testing.T) { + t.Run(string(test.t.Origin), func(t *testing.T) { h := sha256.Sum256([]byte(test.msg)) test.t.MessageImprint = "sha256:" + hex.EncodeToString(h[:]) got, err := test.t.MarshalText() @@ -120,7 +120,7 @@ func TestUnmarshalTimestampNote(t *testing.T) { desc: "valid one", m: "Timestamp Note v0\nsha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904\new==\n2021-07-26T00:00:00Z\n123\nhttp://localhost:3000/api/v1/timestamp/certchain\n", want: TimestampNote{ - Ecosystem: "Timestamp Note v0", + Origin: "Timestamp Note v0", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -132,7 +132,7 @@ func TestUnmarshalTimestampNote(t *testing.T) { desc: "valid with different ecosystem", m: "Timestamp Note v1\nsha256:17fb2e8cbf5f60f881c075b1fd0cad32913f2f08b35053fed1c5a785dff90e8e\nvGFO\n2021-07-26T00:00:00Z\n1\nhttp://localhost:3000/api/v1/timestamp/certchain\n", want: TimestampNote{ - Ecosystem: "Timestamp Note v1", + Origin: "Timestamp Note v1", MessageImprint: "sha256:17fb2e8cbf5f60f881c075b1fd0cad32913f2f08b35053fed1c5a785dff90e8e", Nonce: big.NewInt(12345678).Bytes(), Time: someTime, @@ -143,7 +143,7 @@ func TestUnmarshalTimestampNote(t *testing.T) { desc: "valid with trailing data", m: "Timestamp Note v7\nsha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904\new==\n2021-07-26T00:00:00Z\n123\nhttp://localhost:3000/api/v1/timestamp/certchain\nfoo\nbar\n", want: TimestampNote{ - Ecosystem: "Timestamp Note v7", + Origin: "Timestamp Note v7", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -155,7 +155,7 @@ func TestUnmarshalTimestampNote(t *testing.T) { desc: "valid with trailing newlines", m: "Timestamp Note v1\nsha256:17fb2e8cbf5f60f881c075b1fd0cad32913f2f08b35053fed1c5a785dff90e8e\nvGFO\n2021-07-26T00:00:00Z\n1\nhttp://localhost:3000/api/v1/timestamp/certchain\n\n\n\n", want: TimestampNote{ - Ecosystem: "Timestamp Note v1", + Origin: "Timestamp Note v1", MessageImprint: "sha256:17fb2e8cbf5f60f881c075b1fd0cad32913f2f08b35053fed1c5a785dff90e8e", Nonce: big.NewInt(12345678).Bytes(), Time: someTime, @@ -237,7 +237,7 @@ func TestSigningRoundtripTimestampNote(t *testing.T) { }{ { t: TimestampNote{ - Ecosystem: "Timestamp Note RSA v0", + Origin: "Timestamp Note RSA v0", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -253,7 +253,7 @@ func TestSigningRoundtripTimestampNote(t *testing.T) { }, { t: TimestampNote{ - Ecosystem: "Timestamp Note ECDSA v0", + Origin: "Timestamp Note ECDSA v0", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -269,7 +269,7 @@ func TestSigningRoundtripTimestampNote(t *testing.T) { }, { t: TimestampNote{ - Ecosystem: "Timestamp Note ED25519 v0", + Origin: "Timestamp Note ED25519 v0", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -285,7 +285,7 @@ func TestSigningRoundtripTimestampNote(t *testing.T) { }, { t: TimestampNote{ - Ecosystem: "Timestamp Note Mismatch v0", + Origin: "Timestamp Note Mismatch v0", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -301,7 +301,7 @@ func TestSigningRoundtripTimestampNote(t *testing.T) { }, { t: TimestampNote{ - Ecosystem: "Timestamp Note Mismatch v1", + Origin: "Timestamp Note Mismatch v1", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -317,7 +317,7 @@ func TestSigningRoundtripTimestampNote(t *testing.T) { }, { t: TimestampNote{ - Ecosystem: "Timestamp Note Mismatch v2", + Origin: "Timestamp Note Mismatch v2", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -333,7 +333,7 @@ func TestSigningRoundtripTimestampNote(t *testing.T) { }, { t: TimestampNote{ - Ecosystem: "Timestamp Note Mismatch v3", + Origin: "Timestamp Note Mismatch v3", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -348,7 +348,7 @@ func TestSigningRoundtripTimestampNote(t *testing.T) { wantVerifyErr: true, }, } { - t.Run(string(test.t.Ecosystem), func(t *testing.T) { + t.Run(string(test.t.Origin), func(t *testing.T) { text, _ := test.t.MarshalText() sc := &SignedNote{ Note: string(text), @@ -416,7 +416,7 @@ func TestInvalidSigVerificationTimestampNote(t *testing.T) { }{ { t: TimestampNote{ - Ecosystem: "Timestamp Note v0", + Origin: "Timestamp Note v0", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -429,7 +429,7 @@ func TestInvalidSigVerificationTimestampNote(t *testing.T) { }, { t: TimestampNote{ - Ecosystem: "Timestamp Note v0 - not base 64", + Origin: "Timestamp Note v0 - not base 64", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -448,7 +448,7 @@ func TestInvalidSigVerificationTimestampNote(t *testing.T) { }, { t: TimestampNote{ - Ecosystem: "Timestamp Note v0 invalid signature", + Origin: "Timestamp Note v0 invalid signature", MessageImprint: "sha256:e4ba5cbd251c98e6cd1c23f126a3b81d8d8328abc95387229850952b3ef9f904", Nonce: big.NewInt(123).Bytes(), Time: someTime, @@ -466,7 +466,7 @@ func TestInvalidSigVerificationTimestampNote(t *testing.T) { expectedResult: false, }, } { - t.Run(string(test.t.Ecosystem), func(t *testing.T) { + t.Run(string(test.t.Origin), func(t *testing.T) { text, _ := test.t.MarshalText() sc := SignedNote{ Note: string(text),