Skip to content

Commit d4bf51c

Browse files
committed
add cert install on macos
1 parent 92e6b24 commit d4bf51c

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

certificates/certificates.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"math/big"
2020
"net"
2121
"os"
22+
"os/exec"
23+
"runtime"
2224
"strings"
2325
"text/template"
2426
"time"
@@ -261,6 +263,20 @@ func GenerateCertificates(certsDir *paths.Path) {
261263
}
262264
}
263265

266+
// InstallCertificates will install the certificates in the system keychain
267+
func InstallCertificates(certsDir *paths.Path) {
268+
switch runtime.GOOS {
269+
case "darwin":
270+
stdoutStderr, err := exec.Command("sudo", "/usr/bin/osascript", "-e", `'do shell script "security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain `, certsDir.String(), `/ca.cert.pem" with administration privileges'`).CombinedOutput()
271+
if err != nil {
272+
log.Errorf("cannot install certificate in the system keychain: %s", err)
273+
}
274+
log.Infof("stdout: %s", stdoutStderr)
275+
default:
276+
log.Infof("cannot install certificate: OS not supported")
277+
}
278+
}
279+
264280
// CertHandler will expone the certificate (we do not know why this was required)
265281
func CertHandler(c *gin.Context) {
266282
if strings.Contains(c.Request.UserAgent(), "Firefox") {

systray/systray_real.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (s *Systray) start() {
6464
mRmCrashes := systray.AddMenuItem("Remove crash reports", "")
6565
s.updateMenuItem(mRmCrashes, config.LogsIsEmpty())
6666

67-
mGenCerts := systray.AddMenuItem("Generate HTTPS certificates", "HTTPS Certs")
67+
mGenCerts := systray.AddMenuItem("Generate and Install HTTPS certificates", "HTTPS Certs")
6868
s.updateMenuItem(mGenCerts, config.CertsExist())
6969

7070
// Add pause/quit
@@ -90,6 +90,7 @@ func (s *Systray) start() {
9090
s.updateMenuItem(mRmCrashes, config.LogsIsEmpty())
9191
case <-mGenCerts.ClickedCh:
9292
cert.GenerateCertificates(config.GetCertificatesDir())
93+
cert.InstallCertificates(config.GetCertificatesDir())
9394
s.Restart()
9495
case <-mPause.ClickedCh:
9596
s.Pause()

0 commit comments

Comments
 (0)