@@ -3,7 +3,7 @@ package updater
33import (
44 "bytes"
55 "context"
6- "crypto/md5 "
6+ "crypto/sha256 "
77 "encoding/hex"
88 "fmt"
99 "io"
@@ -19,7 +19,7 @@ type Manifest struct {
1919 Latest struct {
2020 Version string `json:"version"`
2121 Url string `json:"url"`
22- Md5sum string `json:"md5sum "`
22+ Sha256 string `json:"sha256 "`
2323 } `json:"latest"`
2424}
2525
@@ -122,16 +122,16 @@ func DownloadImage(client *Client, targetVersion string, upgradeConfirmCb Downlo
122122
123123 // Download and keep track of the progress
124124 src := & PassThru {Reader : download , length : size , progressCB : func (f float64 ) { feedback .Printf ("Download progress: %.2f %%" , f ) }}
125- md5 := md5 .New ()
126- if _ , err := io .Copy (io .MultiWriter (md5 , tmpZipFile ), src ); err != nil {
125+ checksum := sha256 .New ()
126+ if _ , err := io .Copy (io .MultiWriter (checksum , tmpZipFile ), src ); err != nil {
127127 return nil , "" , err
128128 }
129129
130130 // Check the hash
131- if md5Byte , err := hex .DecodeString (manifest .Latest .Md5sum ); err != nil {
132- return nil , "" , fmt .Errorf ("could not convert md5 from hex to bytes: %w" , err )
133- } else if s := md5 .Sum (nil ); ! bytes .Equal (s , md5Byte ) {
134- return nil , "" , fmt .Errorf ("bad hash: %x (expected %x)" , s , md5Byte )
131+ if sha256Byte , err := hex .DecodeString (manifest .Latest .Sha256 ); err != nil {
132+ return nil , "" , fmt .Errorf ("could not convert sha256 from hex to bytes: %w" , err )
133+ } else if s := checksum .Sum (nil ); ! bytes .Equal (s , sha256Byte ) {
134+ return nil , "" , fmt .Errorf ("bad hash: %x (expected %x)" , s , sha256Byte )
135135 }
136136
137137 slog .Info ("Download of Debian image completed" , "path" , temp )
0 commit comments