Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundle: dont sign manifest when empty #4730

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 18 additions & 14 deletions bundle/bundle.go
Expand Up @@ -851,25 +851,29 @@ func hashBundleFiles(hash SignatureHasher, b *Bundle) ([]FileInfo, error) {
files = append(files, NewFile(strings.TrimPrefix(planmodule.Path, "/"), hex.EncodeToString(bs), defaultHashingAlg))
}

// Parse the manifest into a JSON structure;
// If the manifest is essentially empty, don't add it to the signatures since it
// won't be written to the bundle. Otherwise:
// parse the manifest into a JSON structure;
// then recursively order the fields of all objects alphabetically and then apply
// the hash function to result to compute the hash.
mbs, err := json.Marshal(b.Manifest)
if err != nil {
return files, err
}
if !b.Manifest.Equal(Manifest{}) {
mbs, err := json.Marshal(b.Manifest)
if err != nil {
return files, err
}

var result map[string]interface{}
if err := util.Unmarshal(mbs, &result); err != nil {
return files, err
}
var result map[string]interface{}
if err := util.Unmarshal(mbs, &result); err != nil {
return files, err
}

bs, err = hash.HashFile(result)
if err != nil {
return files, err
}
bs, err = hash.HashFile(result)
if err != nil {
return files, err
}

files = append(files, NewFile(strings.TrimPrefix(ManifestExt, "/"), hex.EncodeToString(bs), defaultHashingAlg))
files = append(files, NewFile(strings.TrimPrefix(ManifestExt, "/"), hex.EncodeToString(bs), defaultHashingAlg))
}

return files, err
}
Expand Down
4 changes: 2 additions & 2 deletions bundle/bundle_test.go
Expand Up @@ -1338,8 +1338,8 @@ func TestHashBundleFiles(t *testing.T) {
plan []byte
exp int
}{
"no_content": {map[string]interface{}{}, Manifest{}, nil, nil, 2},
"data": {map[string]interface{}{"foo": "bar"}, Manifest{}, nil, nil, 2},
"no_content": {map[string]interface{}{}, Manifest{}, nil, nil, 1},
"data": {map[string]interface{}{"foo": "bar"}, Manifest{}, nil, nil, 1},
"data_and_manifest": {map[string]interface{}{"foo": "bar"}, Manifest{Revision: "quickbrownfaux"}, []byte{}, nil, 2},
"data_and_manifest_and_wasm": {map[string]interface{}{"foo": "bar"}, Manifest{Revision: "quickbrownfaux"}, []byte("modules-compiled-as-wasm-binary"), nil, 3},
"data_and_plan": {map[string]interface{}{"foo": "bar"}, Manifest{Revision: "quickbrownfaux"}, nil, []byte("not a plan but good enough"), 3},
Expand Down