From c7b202662732409fdf466265cbc6224e6ba906f8 Mon Sep 17 00:00:00 2001 From: Zoelie Charpentier Date: Fri, 22 Jun 2018 11:45:58 -0400 Subject: [PATCH] added proper warning regarding CA import --- certificate.go | 38 +++++++++++++++++++++++--------------- lang.go | 4 ++-- utils.go | 4 ++-- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/certificate.go b/certificate.go index 23dbb3c..eaeada1 100644 --- a/certificate.go +++ b/certificate.go @@ -132,22 +132,30 @@ func addCAToMachine(eapType uint64, caFileBinary string, CERTUTIL_PROGRAM_PATH s var err error var ERROR_CANCELED int64 ERROR_CANCELED = 2147943623 - sum := 0 - addCA := exec.Command(CERTUTIL_PROGRAM_PATH, "-addstore", "-user", "Root", caFileBinary) - // use Start() and Wait() to specify exit status 1 error - addCA.Start() - // error handling - if err := addCA.Wait(); err != nil { - if exitErr, ok := err.(*exec.ExitError); ok { - for i := 0; i < 2; i++ { + runCommand := true + for runCommand { + runCommand = false + addCA := exec.Command(CERTUTIL_PROGRAM_PATH, "-addstore", "-user", "Root", caFileBinary) + // use Start() and Wait() instead of Run() to specify exit status 1 error + addCA.Start() + // error handling + if err := addCA.Wait(); err != nil { + if exitErr, ok := err.(*exec.ExitError); ok { if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { if status.ExitStatus() == int(ERROR_CANCELED) { // reprompt user to add certificate to windows - walk.MsgBox(windowMsgBox, T("errorWindowTitle"), T("caErrorCanceled"), walk.MsgBoxOK) - os.Remove(caFileBinary) - os.Remove("profile.xml") - log.Fatal("Failed installing certificate: ", err) - sum += i + retryOrCancel := walk.MsgBox(windowMsgBox, T("errorWindowTitle"), T("caErrorCanceled"), walk.MsgBoxRetryCancel) + log.Println(retryOrCancel) // Retry = 4, Cancel = 2 + if retryOrCancel == 4 { + log.Print("Failed installing certificate: ", err) + os.Remove(caFileBinary) + os.Remove("profile.xml") + runCommand = true + } else { + log.Fatal("Failed installing certificate: ", err) + os.Remove(caFileBinary) + os.Remove("profile.xml") + } } else { walk.MsgBox(windowMsgBox, T("errorWindowTitle"), T("cannotInstallCA"), walk.MsgBoxOK) os.Remove(caFileBinary) @@ -156,9 +164,9 @@ func addCAToMachine(eapType uint64, caFileBinary string, CERTUTIL_PROGRAM_PATH s } } } + } else { + log.Println(T("successWindowTitle"), T("caInstallationSuccess")) } - } else { - log.Println(T("successWindowTitle"), T("caInstallationSuccess")) } return err } diff --git a/lang.go b/lang.go index 0a20811..7d627d7 100644 --- a/lang.go +++ b/lang.go @@ -95,7 +95,7 @@ const ENGLISH_TRANSLATION = `[ }, { "id": "caErrorCanceled", - "translation": "The Certificate of Authority could not be installed on your machine.\nPlease select 'Yes' if prompted to install the Certificate of Authority." + "translation": "The Certificate of Authority could not be installed on your machine.\nIf you chose not to install the Certificate of Authority, the program will terminate." }, { "id": "cannotInstallCA", @@ -242,7 +242,7 @@ const FRENCH_TRANSLATION = `[ }, { "id": "caErrorCanceled", - "translation": "L'Autorité de Certification n'a pas pu être installée sur votre machine.\nVeuillez sélectionner «Oui» si vous êtes invité à installer l'Autorité de Certification'." + "translation": "L'Autorité de Certification n'a pas pu être installée sur votre machine.\nSi vous choisissez de ne pas l'installer, le programme se terminera." }, { "id": "cannotInstallCA", diff --git a/utils.go b/utils.go index 7df8ab5..0fc87b1 100644 --- a/utils.go +++ b/utils.go @@ -38,14 +38,14 @@ func createLanguageFile(currentDir, translationLanguage, languageFileName string // Converts base 64 background image to pf_bg.png func base64ToPng(BACKGROUND_IMAGE_PF, tempPath string) (error, string) { - reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(BACKGROUND_IMAGE_PF)) + reader := base64.NewDecoder(base64.StdEncoding, strings.NewReader(BACKGROUND_IMAGE_PF)) decodeBase64ToPng, _, err := image.Decode(reader) if err != nil { log.Fatal("Unable to decode base 64 background image: ", err) } //Encode from image format to writer pngFilename := "pf_bg.png" - pngFilePath := tempPath + "\\" + pngFilename + pngFilePath := tempPath + "\\" + pngFilename backgroundFile, err := os.Create(pngFilePath) if err != nil { log.Fatal("Unable to open or create background image: ", err)