From e6e021906584398848ac73025e0d456577f98437 Mon Sep 17 00:00:00 2001 From: Stephen J Day Date: Mon, 1 Dec 2014 17:10:33 -0800 Subject: [PATCH] Avoid manifest verification errors by using Raw Because json.Marshal does compaction on returned results, applications must directly use SignedManifest.Raw when the marshaled value is required. Otherwise, the returned manifest will fail signature checks. --- api_test.go | 14 ++++++++++---- storage/manifest.go | 9 ++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/api_test.go b/api_test.go index cc27e5b0..cce4a251 100644 --- a/api_test.go +++ b/api_test.go @@ -277,7 +277,7 @@ func TestManifestAPI(t *testing.T) { resp = putManifest(t, "putting signed manifest", manifestURL, signedManifest) - checkResponse(t, "putting manifest", resp, http.StatusOK) + checkResponse(t, "putting signed manifest", resp, http.StatusOK) resp, err = http.Get(manifestURL) if err != nil { @@ -299,9 +299,15 @@ func TestManifestAPI(t *testing.T) { } func putManifest(t *testing.T, msg, url string, v interface{}) *http.Response { - body, err := json.Marshal(v) - if err != nil { - t.Fatalf("unexpected error marshaling %v: %v", v, err) + var body []byte + if sm, ok := v.(*storage.SignedManifest); ok { + body = sm.Raw + } else { + var err error + body, err = json.MarshalIndent(v, "", " ") + if err != nil { + t.Fatalf("unexpected error marshaling %v: %v", v, err) + } } req, err := http.NewRequest("PUT", url, bytes.NewReader(body)) diff --git a/storage/manifest.go b/storage/manifest.go index 000bc617..daeaa39b 100644 --- a/storage/manifest.go +++ b/storage/manifest.go @@ -140,8 +140,9 @@ type SignedManifest struct { Manifest // Raw is the byte representation of the ImageManifest, used for signature - // verification. The manifest byte representation cannot change or it will - // have to be re-signed. + // verification. The value of Raw must be used directly during + // serialization, or the signature check will fail. The manifest byte + // representation cannot change or it will have to be re-signed. Raw []byte `json:"-"` } @@ -184,7 +185,9 @@ func (sm *SignedManifest) UnmarshalJSON(b []byte) error { } // MarshalJSON returns the contents of raw. If Raw is nil, marshals the inner -// contents. +// contents. Applications requiring a marshaled signed manifest should simply +// use Raw directly, since the the content produced by json.Marshal will +// compacted and will fail signature checks. func (sm *SignedManifest) MarshalJSON() ([]byte, error) { if len(sm.Raw) > 0 { return sm.Raw, nil