From 8a97c99c1e4cff8ef55ef1fdaaba7b892a7055e1 Mon Sep 17 00:00:00 2001 From: David Lawrence Date: Wed, 22 Jul 2015 19:37:23 -0700 Subject: [PATCH] updating gotuf Signed-off-by: David Lawrence (github: endophage) --- Godeps/Godeps.json | 2 +- .../endophage/gotuf/client/client.go | 23 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index f5e10ab126..3d5385b2a1 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -63,7 +63,7 @@ }, { "ImportPath": "github.com/endophage/gotuf", - "Rev": "b3e9e71b832b7f497f141fca938cad7208cef6e1" + "Rev": "c5ce5d38779dff6653e1b74905302656502e6d48" }, { "ImportPath": "github.com/go-sql-driver/mysql", diff --git a/Godeps/_workspace/src/github.com/endophage/gotuf/client/client.go b/Godeps/_workspace/src/github.com/endophage/gotuf/client/client.go index 649f51bb8a..0e5e59d26a 100644 --- a/Godeps/_workspace/src/github.com/endophage/gotuf/client/client.go +++ b/Godeps/_workspace/src/github.com/endophage/gotuf/client/client.go @@ -20,7 +20,7 @@ import ( "github.com/endophage/gotuf/utils" ) -const maxSize = 5 << 20 +const maxSize int64 = 5 << 20 type Client struct { local *tuf.TufRepo @@ -120,16 +120,27 @@ func (c Client) checkRoot() error { // downloadRoot is responsible for downloading the root.json func (c *Client) downloadRoot() error { role := data.RoleName("root") - size := c.local.Snapshot.Signed.Meta[role].Length - expectedSha256 := c.local.Snapshot.Signed.Meta[role].Hashes["sha256"] + size := maxSize + var expectedSha256 []byte = nil + if c.local.Snapshot != nil { + size = c.local.Snapshot.Signed.Meta[role].Length + expectedSha256 = c.local.Snapshot.Signed.Meta[role].Hashes["sha256"] + } // if we're bootstrapping we may not have a cached root, an // error will result in the "previous root version" being // interpreted as 0. var download bool + var err error + var cachedRoot []byte = nil old := &data.Signed{} - cachedRoot, err := c.cache.GetMeta(role, maxSize) version := 0 + + if expectedSha256 != nil { + // can only trust cache if we have an expected sha256 to trust + cachedRoot, err = c.cache.GetMeta(role, size) + } + if cachedRoot == nil || err != nil { logrus.Debug("didn't find a cached root, must download") download = true @@ -162,7 +173,9 @@ func (c *Client) downloadRoot() error { return err } hash := sha256.Sum256(raw) - if !bytes.Equal(hash[:], expectedSha256) { + if expectedSha256 != nil && !bytes.Equal(hash[:], expectedSha256) { + // if we don't have an expected sha256, we're going to trust the root + // based purely on signature and expiry time validation return fmt.Errorf("Remote root sha256 did not match snapshot root sha256: %#x vs. %#x", hash, []byte(expectedSha256)) } s = &data.Signed{}