Skip to content

Commit

Permalink
bundle: use inmemory.Download to fetch signed bundle hashes
Browse files Browse the repository at this point in the history
as a result of using the helper the User-Agent for the http request
is `crc/<version>`

this was not the case before, but since we were setting the user-agent
for downloading the `release-info.json` file it makes sense to use the
same User-Agent for downloading the file `sha256sum.txt.sig`
  • Loading branch information
anjannath committed Jun 7, 2023
1 parent 050c1cc commit e478e9f
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pkg/crc/machine/bundle/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"net/http"
"os"
"path"
"path/filepath"
Expand All @@ -20,6 +19,7 @@ import (
"github.com/crc-org/crc/pkg/crc/logging"
"github.com/crc-org/crc/pkg/crc/network/httpproxy"
crcPreset "github.com/crc-org/crc/pkg/crc/preset"
"github.com/crc-org/crc/pkg/crc/version"
"github.com/crc-org/crc/pkg/download"
)

Expand Down Expand Up @@ -299,21 +299,18 @@ func getBundleDownloadInfo(preset crcPreset.Preset) (*download.RemoteFile, error
// then verifies it is signed by redhat release key, if signature is valid it returns the hash
// for the default bundle of preset from the file
func getDefaultBundleVerifiedHash(preset crcPreset.Preset) (string, error) {
client := &http.Client{
Timeout: 5 * time.Second,
Transport: httpproxy.HTTPTransport(),
}
res, err := client.Get(constants.GetDefaultBundleSignedHashURL(preset))
res, err := download.DownloadInMemory(constants.GetDefaultBundleSignedHashURL(preset),
version.UserAgent(),
httpproxy.HTTPTransport(),
)
if err != nil {
return "", err
}
signedHashes, err := io.ReadAll(res.Body)
defer res.Close()
signedHashes, err := io.ReadAll(res)
if err != nil {
return "", err
}
if err := res.Body.Close(); err != nil {
logging.Debug(err)
}

verifiedHashes, err := gpg.GetVerifiedClearsignedMsgV3(constants.RedHatReleaseKey, string(signedHashes))
if err != nil {
Expand Down

0 comments on commit e478e9f

Please sign in to comment.