|
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,27 @@ 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()) |
| 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 | + } |
| 243 | + } |
| 244 | + |
223 | 245 | // Parse the config.ini |
224 | 246 | args, err := parseIni(configPath.String()) |
225 | 247 | if err != nil { |
@@ -342,6 +364,13 @@ func loop() { |
342 | 364 | } |
343 | 365 | } |
344 | 366 |
|
| 367 | + // check if the HTTPS certificates are expired and prompt the user to update them on macOS |
| 368 | + if runtime.GOOS == "darwin" { |
| 369 | + if *installCerts && config.CertsExist() { |
| 370 | + cert.PromptExpiredCerts(config.GetCertificatesDir()) |
| 371 | + } |
| 372 | + } |
| 373 | + |
345 | 374 | // launch the discoveries for the running system |
346 | 375 | go serialPorts.Run() |
347 | 376 | // launch the hub routine which is the singleton for the websocket server |
@@ -487,3 +516,27 @@ func parseIni(filename string) (args []string, err error) { |
487 | 516 |
|
488 | 517 | return args, nil |
489 | 518 | } |
| 519 | + |
| 520 | +func modifyIni(filename string) error { |
| 521 | + cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false, AllowPythonMultilineValues: true}, filename) |
| 522 | + if err != nil { |
| 523 | + return err |
| 524 | + } |
| 525 | + _, err = cfg.Section("").NewKey("installCerts", "true") |
| 526 | + if err != nil { |
| 527 | + return err |
| 528 | + } |
| 529 | + err = cfg.SaveTo(filename) |
| 530 | + if err != nil { |
| 531 | + return err |
| 532 | + } |
| 533 | + return nil |
| 534 | +} |
| 535 | + |
| 536 | +func valueIni(filename string) (bool, error) { |
| 537 | + cfg, err := ini.LoadSources(ini.LoadOptions{IgnoreInlineComment: false, AllowPythonMultilineValues: true}, filename) |
| 538 | + if err != nil { |
| 539 | + return false, err |
| 540 | + } |
| 541 | + return cfg.Section("").HasKey("installCerts"), nil |
| 542 | +} |
0 commit comments