From bf5f88a4417fbd709f0c106eb2ecf736563dd30b Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 30 Oct 2020 18:59:34 +0100 Subject: [PATCH] [Ingest Manager] Fix incorrect hash when upgrading agent (#22322) [Ingest Manager] Fix incorrect hash when upgrading agent (#22322) --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + x-pack/elastic-agent/pkg/artifact/download/fs/verifier.go | 2 +- .../elastic-agent/pkg/artifact/download/http/verifier.go | 7 +++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index bd3983e5716c..aa433f81d70f 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -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 diff --git a/x-pack/elastic-agent/pkg/artifact/download/fs/verifier.go b/x-pack/elastic-agent/pkg/artifact/download/fs/verifier.go index e9e405a5defc..2fc5daedabfd 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/fs/verifier.go +++ b/x-pack/elastic-agent/pkg/artifact/download/fs/verifier.go @@ -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 } diff --git a/x-pack/elastic-agent/pkg/artifact/download/http/verifier.go b/x-pack/elastic-agent/pkg/artifact/download/http/verifier.go index b5b5e628b4a0..da5b6b7d5502 100644 --- a/x-pack/elastic-agent/pkg/artifact/download/http/verifier.go +++ b/x-pack/elastic-agent/pkg/artifact/download/http/verifier.go @@ -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 @@ -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 == "" {