From 8f8fbc745d35fa5956dfcca92179abeedeb93e44 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Fri, 17 Apr 2020 16:25:01 +0200 Subject: [PATCH] fix: correctly install tls certs with osascript --- Changelog.md | 3 +++ pkg/config/tls.go | 13 ++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index 76d6e15d..5b58614c 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,6 +17,9 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) * GODT-124 bump go-appdir from v1.0.0 to v1.1.0 * CSB-72 Skip processing message update event if http statuscode is 422 +### Fixed +* Use correct binary name when finding location of addcert.scpt + ## [v1.2.6] Donghai - beta (2020-03-31) ### Added diff --git a/pkg/config/tls.go b/pkg/config/tls.go index 910080d7..180b63e3 100644 --- a/pkg/config/tls.go +++ b/pkg/config/tls.go @@ -29,11 +29,9 @@ import ( "net" "os" "os/exec" + "path/filepath" "runtime" - "strings" "time" - - "github.com/kardianos/osext" ) type tlsConfiger interface { @@ -74,10 +72,11 @@ func GetTLSConfig(cfg tlsConfiger) (tlsConfig *tls.Config, err error) { if runtime.GOOS == "darwin" { // If this fails, log the error but continue to load. - if p, err := osext.Executable(); err == nil { - p = strings.TrimSuffix(p, "MacOS/Desktop-Bridge") // This needs to match the executable name. - p += "Resources/addcert.scpt" - if err := exec.Command("/usr/bin/osascript", p).Run(); err != nil { // nolint[gosec] + if binaryPath, err := os.Executable(); err == nil { + macOSPath := filepath.Dir(binaryPath) + contentsPath := filepath.Dir(macOSPath) + resourcesPath := filepath.Join(contentsPath, "Resources", "addcert.scpt") + if err := exec.Command("/usr/bin/osascript", resourcesPath).Run(); err != nil { // nolint[gosec] log.WithError(err).Error("Failed to add cert to system keychain") } }