File tree 4 files changed +20
-11
lines changed
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) {
168
168
169
169
// GenerateCertificates will generate the required certificates useful for a HTTPS connection on localhost
170
170
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 ()
175
171
176
172
// Create the key for the certification authority
177
173
caKey , err := generateKey ("P256" )
@@ -285,9 +281,12 @@ func DeleteCertHandler(c *gin.Context) {
285
281
286
282
// DeleteCertificates will delete the certificates
287
283
func DeleteCertificates (certDir * paths.Path ) {
284
+ certDir .Join ("ca.key.pem" ).Remove ()
288
285
certDir .Join ("ca.cert.pem" ).Remove ()
289
286
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 ()
291
290
}
292
291
293
292
const noFirefoxTemplateHTML = `<!DOCTYPE html>
Original file line number Diff line number Diff line change @@ -71,14 +71,16 @@ import (
71
71
"github.com/arduino/go-paths-helper"
72
72
)
73
73
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 {
76
77
log .Infof ("Installing certificate: %s" , cert )
77
78
p := C .installCert (C .CString (cert .String ()))
78
79
s := C .GoString (p )
79
80
if len (s ) != 0 {
80
81
oscmd := exec .Command ("osascript" , "-e" , "display dialog \" " + s + "\" buttons \" OK\" with title \" Error installing certificates\" " )
81
82
_ = oscmd .Run ()
82
- log . Info ( oscmd . String () )
83
+ return errors . New ( s )
83
84
}
85
+ return nil
84
86
}
Original file line number Diff line number Diff line change 18
18
package certificates
19
19
20
20
import (
21
+ "errors"
22
+
21
23
log "github.com/sirupsen/logrus"
22
24
23
25
"github.com/arduino/go-paths-helper"
24
26
)
25
27
26
28
// InstallCertificate won't do anything on unsupported Operative Systems
27
- func InstallCertificate (cert * paths.Path ) {
29
+ func InstallCertificate (cert * paths.Path ) error {
28
30
log .Warn ("platform not supported for the certificate install" )
31
+ return errors .New ("platform not supported for the certificate install" )
29
32
}
Original file line number Diff line number Diff line change @@ -96,8 +96,13 @@ func (s *Systray) start() {
96
96
RemoveCrashes ()
97
97
s .updateMenuItem (mRmCrashes , config .LogsIsEmpty ())
98
98
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
+ }
101
106
s .Restart ()
102
107
case <- mPause .ClickedCh :
103
108
s .Pause ()
You can’t perform that action at this time.
0 commit comments