You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Manage the HTTPS certificate from the menu and ask Safari users to install it at startup (#941)
* Add function to retrieve certificates expiration date
* Check the certificate expiration date
* Obtain certificates info using the systray icon
* Manage errors that may occur retrieving certificates expiration date
* Obtain default browser name on macOS
* Prompt Safari users to install HTTPS certificates and check if they are outdated when the Agent is started
* Skip some tests on macOS because the user is prompted to install certificates
* Set installCerts value in config.ini if certicates are manually installed
* Always set installCerts if the certificates exist
* Add "Arduino Agent" to the title of dialogs
* Fix check for pressed buttons
* Move osascript execution function to Utilities to avoid code duplication
* Modify certificate management from the systray menu
* Install certificates if they are missing and the flag inside the config is set to true
* Avoid code duplication
* Fix button order and title
* Do not restart the Agent if no action is performed on the certificate
* Do not modify the config if the default browser is not Safari
* Small messages/titles fixes
---------
Co-authored-by: Xayton <30591904+Xayton@users.noreply.github.com>
// isExpired checks if a certificate is expired or about to expire (less than 1 month)
274
+
funcisExpired() (bool, error) {
275
+
bound:=time.Now().AddDate(0, 1, 0)
276
+
dateS, err:=GetExpirationDate()
277
+
iferr!=nil {
278
+
returnfalse, err
279
+
}
280
+
date, _:=time.Parse(time.DateTime, dateS)
281
+
returndate.Before(bound), nil
282
+
}
283
+
284
+
// PromptInstallCertsSafari prompts the user to install the HTTPS certificates if they are using Safari
285
+
funcPromptInstallCertsSafari() bool {
286
+
buttonPressed:=utilities.UserPrompt("display dialog \"The Arduino Agent needs a local HTTPS certificate to work correctly with Safari.\nIf you use Safari, you need to install it.\" buttons {\"Do not install\", \"Install the certificate for Safari\"} default button 2 with title \"Arduino Agent: Install certificate\"")
287
+
returnstrings.Contains(string(buttonPressed), "button returned:Install the certificate for Safari")
288
+
}
289
+
290
+
// PromptExpiredCerts prompts the user to update the HTTPS certificates if they are using Safari
291
+
funcPromptExpiredCerts(certDir*paths.Path) {
292
+
ifexpired, err:=isExpired(); err!=nil {
293
+
log.Errorf("cannot check if certificates are expired something went wrong: %s", err)
294
+
} elseifexpired {
295
+
buttonPressed:=utilities.UserPrompt("display dialog \"The Arduino Agent needs a local HTTPS certificate to work correctly with Safari.\nYour certificate is expired or close to expiration. Do you want to update it?\" buttons {\"Do not update\", \"Update the certificate for Safari\"} default button 2 with title \"Arduino Agent: Update certificate\"")
296
+
ifstrings.Contains(string(buttonPressed), "button returned:Update the certificate for Safari") {
297
+
err:=UninstallCertificates()
298
+
iferr!=nil {
299
+
log.Errorf("cannot uninstall certificates something went wrong: %s", err)
300
+
} else {
301
+
DeleteCertificates(certDir)
302
+
GenerateAndInstallCertificates(certDir)
303
+
}
304
+
}
305
+
}
306
+
}
307
+
308
+
// GenerateAndInstallCertificates generates and installs the certificates
autostartMacOS=iniConf.Bool("autostartMacOS", true, "the Arduino Create Agent is able to start automatically after login on macOS (launchd agent)")
89
+
installCerts=iniConf.Bool("installCerts", false, "install the HTTPS certificate for Safari and keep it updated")
89
90
)
90
91
91
92
// the ports filter provided by the user via the -regex flag, if any
@@ -177,7 +178,7 @@ func loop() {
177
178
// If we are updating manually from 1.2.7 to 1.3.0 we have to uninstall the old agent manually first.
178
179
// This check will inform the user if he needs to run the uninstall first
179
180
ifruntime.GOOS=="darwin"&&oldInstallExists() {
180
-
printDialog("Old agent installation of the Arduino Create Agent found, please uninstall it before launching the new one")
181
+
utilities.UserPrompt("display dialog \"Old agent installation of the Arduino Create Agent found, please uninstall it before launching the new one\" buttons \"OK\" with title \"Error\"")
181
182
os.Exit(0)
182
183
}
183
184
@@ -220,6 +221,32 @@ func loop() {
220
221
configPath=config.GenerateConfig(configDir)
221
222
}
222
223
224
+
// if the default browser is Safari, prompt the user to install HTTPS certificates
0 commit comments