File tree Expand file tree Collapse file tree 4 files changed +20
-11
lines changed
Expand file tree Collapse file tree 4 files changed +20
-11
lines changed Original file line number Diff line number Diff 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
170170func 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
287283func 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
293292const noFirefoxTemplateHTML = `<!DOCTYPE html>
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 1818package certificates
1919
2020import (
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}
Original file line number Diff line number Diff 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 ()
You can’t perform that action at this time.
0 commit comments