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