Skip to content

Commit 59a5b49

Browse files
Test certificates renewal using systray menu
1 parent 8804978 commit 59a5b49

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

systray/systray_real.go

+21
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,18 @@ func (s *Systray) start() {
6767
mGenCerts := systray.AddMenuItem("Generate and Install HTTPS certificates", "HTTPS Certs")
6868
mRemoveCerts := systray.AddMenuItem("Remove HTTPS certificates", "")
6969
mCertsInfo := systray.AddMenuItem("Show HTTPS certificates info", "")
70+
mRenewCerts := systray.AddMenuItem("Check if HTTPS certificates are expired", "")
7071
// On linux/windows chrome/firefox/edge(chromium) the agent works without problems on plain HTTP,
7172
// so we disable the menuItem to generate/install the certificates
7273
if runtime.GOOS != "darwin" {
7374
s.updateMenuItem(mGenCerts, true)
7475
s.updateMenuItem(mRemoveCerts, true)
7576
s.updateMenuItem(mCertsInfo, true)
77+
s.updateMenuItem(mRenewCerts, true)
7678
} else {
7779
s.updateMenuItem(mGenCerts, config.CertsExist())
7880
s.updateMenuItem(mRemoveCerts, !config.CertsExist())
81+
s.updateMenuItem(mRenewCerts, !config.CertsExist())
7982
}
8083

8184
// Add pause/quit
@@ -131,6 +134,24 @@ func (s *Systray) start() {
131134
}
132135
oscmd := exec.Command("osascript", "-e", "display dialog \""+infoMsg+"\" buttons \"OK\" with title \"Arduino Agent: certificates info\"")
133136
_ = oscmd.Run()
137+
case <-mRenewCerts.ClickedCh:
138+
if cert.IsExpired() {
139+
err := cert.UninstallCertificates()
140+
if err != nil {
141+
log.Errorf("cannot uninstall certificates something went wrong: %s", err)
142+
} else {
143+
certDir := config.GetCertificatesDir()
144+
cert.DeleteCertificates(certDir)
145+
cert.GenerateCertificates(certDir)
146+
err := cert.InstallCertificate(certDir.Join("ca.cert.cer"))
147+
// if something goes wrong during the cert install we remove them, so the user is able to retry
148+
if err != nil {
149+
log.Errorf("cannot install certificates something went wrong: %s", err)
150+
cert.DeleteCertificates(certDir)
151+
}
152+
}
153+
}
154+
s.Restart()
134155
case <-mPause.ClickedCh:
135156
s.Pause()
136157
case <-mQuit.ClickedCh:

0 commit comments

Comments
 (0)