Skip to content

Commit

Permalink
[Ingest Manager] Fix incorrect hash when upgrading agent (elastic#22322)
Browse files Browse the repository at this point in the history
[Ingest Manager] Fix incorrect hash when upgrading agent (elastic#22322)
  • Loading branch information
michalpristas committed Oct 30, 2020
1 parent 8bd10a3 commit bf5f88a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Improve GRPC stop to be more relaxed {pull}20118[20118]
- Fix Windows service installation script {pull}20203[20203]
- Fix timeout issue stopping service applications {pull}20256[20256]
- Fix incorrect hash when upgrading agent {pull}22322[22322]

==== New features

Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/artifact/download/fs/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (v *Verifier) verifyHash(filename, fullPath string) (bool, error) {
var expectedHash string
scanner := bufio.NewScanner(hashFileHandler)
for scanner.Scan() {
line := scanner.Text()
line := strings.TrimSpace(scanner.Text())
if !strings.HasSuffix(line, filename) {
continue
}
Expand Down
7 changes: 5 additions & 2 deletions x-pack/elastic-agent/pkg/artifact/download/http/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
const (
publicKeyURI = "https://artifacts.elastic.co/GPG-KEY-elasticsearch"
ascSuffix = ".asc"
sha512Length = 128
)

// Verifier verifies a downloaded package by comparing with public ASC
Expand Down Expand Up @@ -100,12 +101,14 @@ func (v *Verifier) verifyHash(filename, fullPath string) (bool, error) {
var expectedHash string
scanner := bufio.NewScanner(hashFileHandler)
for scanner.Scan() {
line := scanner.Text()
line := strings.TrimSpace(scanner.Text())
if !strings.HasSuffix(line, filename) {
continue
}

expectedHash = strings.TrimSpace(strings.TrimSuffix(line, filename))
if len(line) > sha512Length {
expectedHash = strings.TrimSpace(line[:sha512Length])
}
}

if expectedHash == "" {
Expand Down

0 comments on commit bf5f88a

Please sign in to comment.