@@ -22,7 +22,6 @@ import (
2222 "encoding/pem"
2323 "errors"
2424 "fmt"
25- "strings"
2625 "time"
2726
2827 "github.com/google/trillian/merkle/logverifier"
@@ -34,7 +33,7 @@ import (
3433 "github.com/sigstore/rekor/cmd/rekor-cli/app/state"
3534 "github.com/sigstore/rekor/pkg/generated/client/tlog"
3635 "github.com/sigstore/rekor/pkg/log"
37- "github.com/sigstore/rekor/pkg/verify "
36+ "github.com/sigstore/rekor/pkg/util "
3837)
3938
4039type logInfoCmdOutput struct {
@@ -72,14 +71,11 @@ var logInfoCmd = &cobra.Command{
7271
7372 logInfo := result .GetPayload ()
7473
75- logRoot := * logInfo .SignedTreeHead .LogRoot
76- if logRoot == nil {
77- return nil , errors .New ("logroot should not be nil" )
78- }
79- signature := * logInfo .SignedTreeHead .Signature
80- if signature == nil {
81- return nil , errors .New ("signature should not be nil" )
74+ sth := util.RekorSTH {}
75+ if err := sth .UnmarshalText ([]byte (* logInfo .SignedTreeHead )); err != nil {
76+ return nil , err
8277 }
78+
8379 publicKey := viper .GetString ("rekor_server_public_key" )
8480 if publicKey == "" {
8581 // fetch key from server
@@ -100,33 +96,25 @@ var logInfoCmd = &cobra.Command{
10096 return nil , err
10197 }
10298
103- lr , err := verify .SignedLogRoot (pub , logRoot , signature )
104- if err != nil {
105- return nil , err
99+ if ! sth .Verify (pub ) {
100+ return nil , errors .New ("signature on tree head did not verify" )
106101 }
102+
107103 cmdOutput := & logInfoCmdOutput {
108104 TreeSize : * logInfo .TreeSize ,
109105 RootHash : * logInfo .RootHash ,
110- TimestampNanos : lr .TimestampNanos ,
111- }
112-
113- if lr .TreeSize != uint64 (* logInfo .TreeSize ) {
114- return nil , errors .New ("tree size in signed tree head does not match value returned in API call" )
115- }
116-
117- if ! strings .EqualFold (hex .EncodeToString (lr .RootHash ), * logInfo .RootHash ) {
118- return nil , errors .New ("root hash in signed tree head does not match value returned in API call" )
106+ TimestampNanos : sth .GetTimestamp (),
119107 }
120108
121109 oldState := state .Load (serverURL )
122110 if oldState != nil {
123- persistedSize := oldState .TreeSize
124- if persistedSize < lr . TreeSize {
125- log .CliLogger .Infof ("Found previous log state, proving consistency between %d and %d" , oldState .TreeSize , lr . TreeSize )
111+ persistedSize := oldState .Size
112+ if persistedSize < sth . Size {
113+ log .CliLogger .Infof ("Found previous log state, proving consistency between %d and %d" , oldState .Size , sth . Size )
126114 params := tlog .NewGetLogProofParams ()
127115 firstSize := int64 (persistedSize )
128116 params .FirstSize = & firstSize
129- params .LastSize = int64 (lr . TreeSize )
117+ params .LastSize = int64 (sth . Size )
130118 proof , err := rekorClient .Tlog .GetLogProof (params )
131119 if err != nil {
132120 return nil , err
@@ -137,25 +125,25 @@ var logInfoCmd = &cobra.Command{
137125 hashes = append (hashes , b )
138126 }
139127 v := logverifier .New (rfc6962 .DefaultHasher )
140- if err := v .VerifyConsistencyProof (firstSize , int64 (lr . TreeSize ), oldState .RootHash ,
141- lr . RootHash , hashes ); err != nil {
128+ if err := v .VerifyConsistencyProof (firstSize , int64 (sth . Size ), oldState .Hash ,
129+ sth . Hash , hashes ); err != nil {
142130 return nil , err
143131 }
144132 log .CliLogger .Infof ("Consistency proof valid!" )
145- } else if persistedSize == lr . TreeSize {
146- if ! bytes .Equal (oldState .RootHash , lr . RootHash ) {
133+ } else if persistedSize == sth . Size {
134+ if ! bytes .Equal (oldState .Hash , sth . Hash ) {
147135 return nil , errors .New ("root hash returned from server does not match previously persisted state" )
148136 }
149137 log .CliLogger .Infof ("Persisted log state matches the current state of the log" )
150- } else if persistedSize > lr . TreeSize {
151- return nil , fmt .Errorf ("current size of tree reported from server %d is less than previously persisted state %d" , lr . TreeSize , persistedSize )
138+ } else if persistedSize > sth . Size {
139+ return nil , fmt .Errorf ("current size of tree reported from server %d is less than previously persisted state %d" , sth . Size , persistedSize )
152140 }
153141 } else {
154142 log .CliLogger .Infof ("No previous log state stored, unable to prove consistency" )
155143 }
156144
157145 if viper .GetBool ("store_tree_state" ) {
158- if err := state .Dump (serverURL , lr ); err != nil {
146+ if err := state .Dump (serverURL , & sth ); err != nil {
159147 log .CliLogger .Infof ("Unable to store previous state: %v" , err )
160148 }
161149 }
0 commit comments