|
86 | 86 | verbose = iniConf.Bool("v", true, "show debug logging")
|
87 | 87 | crashreport = iniConf.Bool("crashreport", false, "enable crashreport logging")
|
88 | 88 | 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
|
@@ -220,6 +221,34 @@ 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 |
| 225 | + // and eventually install them |
| 226 | + if runtime.GOOS == "darwin" { |
| 227 | + if exist, err := installCertsKeyExists(configPath.String()); err != nil { |
| 228 | + log.Panicf("config.ini cannot be parsed: %s", err) |
| 229 | + } else if !exist { |
| 230 | + if cert.PromptInstallCertsSafari() { |
| 231 | + err = modifyIni(configPath.String(), "true") |
| 232 | + if err != nil { |
| 233 | + log.Panicf("config.ini cannot be parsed: %s", err) |
| 234 | + } |
| 235 | + certDir := config.GetCertificatesDir() |
| 236 | + cert.GenerateCertificates(certDir) |
| 237 | + err := cert.InstallCertificate(certDir.Join("ca.cert.cer")) |
| 238 | + // if something goes wrong during the cert install we remove them, so the user is able to retry |
| 239 | + if err != nil { |
| 240 | + log.Errorf("cannot install certificates something went wrong: %s", err) |
| 241 | + cert.DeleteCertificates(certDir) |
| 242 | + } |
| 243 | + } else { |
| 244 | + err = modifyIni(configPath.String(), "false") |
| 245 | + if err != nil { |
| 246 | + log.Panicf("config.ini cannot be parsed: %s", err) |
| 247 | + } |
| 248 | + } |
| 249 | + } |
| 250 | + } |
| 251 | + |
223 | 252 | // Parse the config.ini
|
224 | 253 | args, err := parseIni(configPath.String())
|
225 | 254 | if err != nil {
|
@@ -342,6 +371,13 @@ func loop() {
|
342 | 371 | }
|
343 | 372 | }
|
344 | 373 |
|
| 374 | + // check if the HTTPS certificates are expired and prompt the user to update them on macOS |
| 375 | + if runtime.GOOS == "darwin" { |
| 376 | + if *installCerts && config.CertsExist() { |
| 377 | + cert.PromptExpiredCerts(config.GetCertificatesDir()) |
| 378 | + } |
| 379 | + } |
| 380 | + |
345 | 381 | // launch the discoveries for the running system
|
346 | 382 | go serialPorts.Run()
|
347 | 383 | // launch the hub routine which is the singleton for the websocket server
|
@@ -487,3 +523,27 @@ func parseIni(filename string) (args []string, err error) {
|
487 | 523 |
|
488 | 524 | return args, nil
|
489 | 525 | }
|
| 526 | + |
| 527 | +func modifyIni(filename string, value string) error { |
| 528 | + cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false, AllowPythonMultilineValues: true}, filename) |
| 529 | + if err != nil { |
| 530 | + return err |
| 531 | + } |
| 532 | + _, err = cfg.Section("").NewKey("installCerts", value) |
| 533 | + if err != nil { |
| 534 | + return err |
| 535 | + } |
| 536 | + err = cfg.SaveTo(filename) |
| 537 | + if err != nil { |
| 538 | + return err |
| 539 | + } |
| 540 | + return nil |
| 541 | +} |
| 542 | + |
| 543 | +func installCertsKeyExists(filename string) (bool, error) { |
| 544 | + cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false, AllowPythonMultilineValues: true}, filename) |
| 545 | + if err != nil { |
| 546 | + return false, err |
| 547 | + } |
| 548 | + return cfg.Section("").HasKey("installCerts"), nil |
| 549 | +} |
0 commit comments