Skip to content

Commit

Permalink
wip: demonstrate the problem with inclusion proof verification
Browse files Browse the repository at this point in the history
Signed-off-by: Asra Ali <asraa@google.com>

update with fix

Signed-off-by: Asra Ali <asraa@google.com>

fix with root resp

Signed-off-by: Asra Ali <asraa@google.com>

fix

Signed-off-by: Asra Ali <asraa@google.com>

fix

Signed-off-by: Asra Ali <asraa@google.com>
  • Loading branch information
asraa committed Aug 5, 2022
1 parent 102dc64 commit a5340bf
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
Binary file added bin/golangci-lint
Binary file not shown.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ services:
timeout: 3s
retries: 3
start_period: 10s
ports:
- "3306:3306"
redis-server:
image: docker.io/redis:5.0.10
command: [
Expand Down
69 changes: 52 additions & 17 deletions pkg/api/trillian_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ type Response struct {
getConsistencyProofResult *trillian.GetConsistencyProofResponse
}

func unmarshalLogRoot(logRoot []byte) (types.LogRootV1, error) {
var root types.LogRootV1
if err := root.UnmarshalBinary(logRoot); err != nil {
return types.LogRootV1{}, err
}
return root, nil
}

func (t *TrillianClient) root() (types.LogRootV1, error) {
rqst := &trillian.GetLatestSignedLogRootRequest{
LogId: t.logID,
Expand All @@ -77,11 +85,7 @@ func (t *TrillianClient) root() (types.LogRootV1, error) {
if err != nil {
return types.LogRootV1{}, err
}
var root types.LogRootV1
if err := root.UnmarshalBinary(resp.SignedLogRoot.LogRoot); err != nil {
return types.LogRootV1{}, err
}
return root, nil
return unmarshalLogRoot(resp.SignedLogRoot.LogRoot)
}

func (t *TrillianClient) addLeaf(byteValue []byte) *Response {
Expand Down Expand Up @@ -210,8 +214,15 @@ func (t *TrillianClient) getLeafAndProofByIndex(index int64) *Response {
ctx, cancel := context.WithTimeout(t.context, 20*time.Second)
defer cancel()

root, err := t.root()
if err != nil {
rootResp := t.getLatest(0)
if rootResp.err != nil {
return &Response{
status: status.Code(rootResp.err),
err: rootResp.err,
}
}
var root types.LogRootV1
if err := root.UnmarshalBinary(rootResp.getLatestResult.SignedLogRoot.LogRoot); err != nil {
return &Response{
status: status.Code(err),
err: err,
Expand All @@ -232,21 +243,36 @@ func (t *TrillianClient) getLeafAndProofByIndex(index int64) *Response {
err: err,
}
}
return &Response{
status: status.Code(err),
err: err,
getLeafAndProofResult: &trillian.GetEntryAndProofResponse{
Proof: resp.Proof,
Leaf: resp.Leaf,
SignedLogRoot: rootResp.getLatestResult.SignedLogRoot,
},
}
}

return &Response{
status: status.Code(err),
err: err,
getLeafAndProofResult: resp,
status: status.Code(err),
err: err,
}
}

func (t *TrillianClient) getProofByHash(hashValue []byte) *Response {
ctx, cancel := context.WithTimeout(t.context, 20*time.Second)
defer cancel()

root, err := t.root()
if err != nil {
rootResp := t.getLatest(0)
if rootResp.err != nil {
return &Response{
status: status.Code(rootResp.err),
err: rootResp.err,
}
}
var root types.LogRootV1
if err := root.UnmarshalBinary(rootResp.getLatestResult.SignedLogRoot.LogRoot); err != nil {
return &Response{
status: status.Code(err),
err: err,
Expand All @@ -263,20 +289,29 @@ func (t *TrillianClient) getProofByHash(hashValue []byte) *Response {
if resp != nil {
v := client.NewLogVerifier(rfc6962.DefaultHasher)
for _, proof := range resp.Proof {

if err := v.VerifyInclusionByHash(&root, hashValue, proof); err != nil {
return &Response{
status: status.Code(err),
err: err,
}
}
}
// Return an inclusion proof response with the requested
return &Response{
status: status.Code(err),
err: err,
getProofResult: &trillian.GetInclusionProofByHashResponse{
Proof: resp.Proof,
SignedLogRoot: rootResp.getLatestResult.SignedLogRoot,
},
}
}

return &Response{
status: status.Code(err),
err: err,
getProofResult: resp,
if err != nil {
return &Response{
status: status.Code(err),
err: err,
}
}
}

Expand Down
Binary file added rekor
Binary file not shown.

0 comments on commit a5340bf

Please sign in to comment.