Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8707687

Browse files
committedApr 21, 2023
remove the certs if the install process errors. The user is able to retry
1 parent 4dde91e commit 8707687

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed
 

‎certificates/certificates.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ func MigrateCertificatesGeneratedWithOldAgentVersions(certsDir *paths.Path) {
168168

169169
// GenerateCertificates will generate the required certificates useful for a HTTPS connection on localhost
170170
func GenerateCertificates(certsDir *paths.Path) {
171-
certsDir.Join("ca.cert.pem").Remove()
172-
certsDir.Join("ca.key.pem").Remove()
173-
certsDir.Join("cert.pem").Remove()
174-
certsDir.Join("key.pem").Remove()
175171

176172
// Create the key for the certification authority
177173
caKey, err := generateKey("P256")
@@ -285,9 +281,12 @@ func DeleteCertHandler(c *gin.Context) {
285281

286282
// DeleteCertificates will delete the certificates
287283
func DeleteCertificates(certDir *paths.Path) {
284+
certDir.Join("ca.key.pem").Remove()
288285
certDir.Join("ca.cert.pem").Remove()
289286
certDir.Join("ca.cert.cer").Remove()
290-
certDir.Join("ca.key.pem").Remove()
287+
certDir.Join("key.pem").Remove()
288+
certDir.Join("cert.pem").Remove()
289+
certDir.Join("cert.cer").Remove()
291290
}
292291

293292
const noFirefoxTemplateHTML = `<!DOCTYPE html>

‎certificates/install_darwin.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ import (
7171
"github.com/arduino/go-paths-helper"
7272
)
7373

74-
// InstallCertificate will install the certificates in the system keychain on macos
75-
func InstallCertificate(cert *paths.Path) {
74+
// InstallCertificate will install the certificates in the system keychain on macos,
75+
// if something goes wrong will show a dialog with the error and return an error
76+
func InstallCertificate(cert *paths.Path) error {
7677
log.Infof("Installing certificate: %s", cert)
7778
p := C.installCert(C.CString(cert.String()))
7879
s := C.GoString(p)
7980
if len(s) != 0 {
8081
oscmd := exec.Command("osascript", "-e", "display dialog \""+s+"\" buttons \"OK\" with title \"Error installing certificates\"")
8182
_ = oscmd.Run()
82-
log.Info(oscmd.String())
83+
return errors.New(s)
8384
}
85+
return nil
8486
}

‎certificates/install_default.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
package certificates
1919

2020
import (
21+
"errors"
22+
2123
log "github.com/sirupsen/logrus"
2224

2325
"github.com/arduino/go-paths-helper"
2426
)
2527

2628
// InstallCertificate won't do anything on unsupported Operative Systems
27-
func InstallCertificate(cert *paths.Path) {
29+
func InstallCertificate(cert *paths.Path) error {
2830
log.Warn("platform not supported for the certificate install")
31+
return errors.New("platform not supported for the certificate install")
2932
}

‎systray/systray_real.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,13 @@ func (s *Systray) start() {
9696
RemoveCrashes()
9797
s.updateMenuItem(mRmCrashes, config.LogsIsEmpty())
9898
case <-mGenCerts.ClickedCh:
99-
cert.GenerateCertificates(config.GetCertificatesDir())
100-
cert.InstallCertificate(config.GetCertificatesDir().Join("ca.cert.cer"))
99+
certDir := config.GetCertificatesDir()
100+
cert.GenerateCertificates(certDir)
101+
err := cert.InstallCertificate(certDir.Join("ca.cert.cer"))
102+
// if something goes wrong during the cert install we remove them, so the user is able to retry
103+
if err != nil {
104+
cert.DeleteCertificates(certDir)
105+
}
101106
s.Restart()
102107
case <-mPause.ClickedCh:
103108
s.Pause()

0 commit comments

Comments
 (0)
Please sign in to comment.