aboutsummaryrefslogtreecommitdiff
path: root/trillian.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-30 16:09:11 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-30 16:09:11 +0100
commit14f2ed32f13b55dbce0f417f21ccf7b68056ae05 (patch)
tree1d89fd0ac07141d629048b4ff8233f1ab508b3f6 /trillian.go
parentb8a8e56d4a311f15060efcd455c444949b2d20b9 (diff)
added max range and get-entries sanity checking
Diffstat (limited to 'trillian.go')
-rw-r--r--trillian.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/trillian.go b/trillian.go
new file mode 100644
index 0000000..e5117da
--- /dev/null
+++ b/trillian.go
@@ -0,0 +1,32 @@
+package stfe
+
+import (
+ "fmt"
+
+ "net/http"
+
+ "github.com/google/trillian"
+ "github.com/google/trillian/types"
+)
+
+// checkGetLeavesByRange does santity-checking on a Trillian response
+func checkGetLeavesByRange(rsp *trillian.GetLeavesByRangeResponse, req GetEntriesRequest) (int, error) {
+ if len(rsp.Leaves) > int(req.End-req.Start+1) {
+ return http.StatusInternalServerError, fmt.Errorf("backend GetLeavesByRange returned too many leaves: %d for [%d,%d]", len(rsp.Leaves), req.Start, req.End)
+ }
+
+ var lr types.LogRootV1
+ if err := lr.UnmarshalBinary(rsp.GetSignedLogRoot().GetLogRoot()); err != nil {
+ return http.StatusInternalServerError, fmt.Errorf("failed unmarshaling log root: %v", err)
+ }
+ if uint64(req.Start) >= lr.TreeSize {
+ return http.StatusBadRequest, fmt.Errorf("invalid start(%d): tree size is %d", req.Start, lr.TreeSize)
+ }
+
+ for i, leaf := range rsp.Leaves {
+ if leaf.LeafIndex != req.Start+int64(i) {
+ return http.StatusInternalServerError, fmt.Errorf("backend GetLeavesByRange returned unexpected leaf index: wanted %d, got %d", req.Start+int64(i), leaf.LeafIndex)
+ }
+ }
+ return 0, nil
+}