feat: better way to add trusted cert in macOS

This commit is contained in:
James Houlahan
2020-07-24 13:44:25 +02:00
parent 1711442878
commit be20714842
4 changed files with 12 additions and 10 deletions

View File

@ -6,6 +6,8 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/)
### Changed ### Changed
* GODT-409 Set flags have to replace all flags. * GODT-409 Set flags have to replace all flags.
* GODT-531 Better way to add trusted certificate in macOS.
## [v1.3.x] Emma (beta 2020-07-XXX) ## [v1.3.x] Emma (beta 2020-07-XXX)

View File

@ -55,7 +55,6 @@ ${DEPLOY_DIR}/linux: ${EXE_TARGET}
${DEPLOY_DIR}/darwin: ${EXE_TARGET} ${DEPLOY_DIR}/darwin: ${EXE_TARGET}
cp ./internal/frontend/share/icons/Bridge.icns ${DARWINAPP_CONTENTS}/Resources/ cp ./internal/frontend/share/icons/Bridge.icns ${DARWINAPP_CONTENTS}/Resources/
cp -r "utils/addcert.scpt" ${DARWINAPP_CONTENTS}/Resources/
cp LICENSE ${DARWINAPP_CONTENTS}/Resources/ cp LICENSE ${DARWINAPP_CONTENTS}/Resources/
rm -rf "${DARWINAPP_CONTENTS}/Frameworks/QtWebEngine.framework" rm -rf "${DARWINAPP_CONTENTS}/Frameworks/QtWebEngine.framework"
rm -rf "${DARWINAPP_CONTENTS}/Frameworks/QtWebView.framework" rm -rf "${DARWINAPP_CONTENTS}/Frameworks/QtWebView.framework"

View File

@ -29,7 +29,6 @@ import (
"net" "net"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"runtime" "runtime"
"time" "time"
) )
@ -71,17 +70,19 @@ func GetTLSConfig(cfg tlsConfiger) (tlsConfig *tls.Config, err error) {
} }
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
// If this fails, log the error but continue to load. if err := exec.Command( // nolint[gosec]
if binaryPath, err := os.Executable(); err == nil { "execute-with-privileges",
macOSPath := filepath.Dir(binaryPath) "/usr/bin/security",
contentsPath := filepath.Dir(macOSPath) "add-trusted-cert",
resourcesPath := filepath.Join(contentsPath, "Resources", "addcert.scpt") "-r", "trustRoot",
if err := exec.Command("/usr/bin/osascript", resourcesPath).Run(); err != nil { // nolint[gosec] "-p", "ssl",
"-k", "/Library/Keychains/System.keychain",
certPath,
).Run(); err != nil {
log.WithError(err).Error("Failed to add cert to system keychain") log.WithError(err).Error("Failed to add cert to system keychain")
} }
} }
} }
}
tlsConfig.ServerName = "127.0.0.1" tlsConfig.ServerName = "127.0.0.1"
tlsConfig.ClientAuth = tls.VerifyClientCertIfGiven tlsConfig.ClientAuth = tls.VerifyClientCertIfGiven

Binary file not shown.