Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ on:
push:

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v8

test:
runs-on: ubuntu-latest
strategy:
Expand All @@ -20,7 +28,7 @@ jobs:
- '1.24'
name: Go ${{ matrix.go }} test
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup go
Expand Down
30 changes: 30 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "2"

run:
issues-exit-code: 1

formatters:
enable:
- gofmt
- gci

linters:
enable:
- wrapcheck
settings:
wrapcheck:
ignore-package-globs:
# We already make sure your own packages wrap errors properly
- github.com/symfony-cli/*
errcheck:
exclude-functions:
- github.com/symfony-cli/terminal.Printf
- github.com/symfony-cli/terminal.Println
- github.com/symfony-cli/terminal.Printfln
- github.com/symfony-cli/terminal.Eprintf
- github.com/symfony-cli/terminal.Eprintln
- github.com/symfony-cli/terminal.Eprintfln
- github.com/symfony-cli/terminal.Eprint
- fmt.Fprintln
- fmt.Fprintf
- fmt.Fprint
10 changes: 7 additions & 3 deletions cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (ca *CA) Install(force bool) error {
return err
}
f, _ := os.OpenFile(ca.trustedpath, os.O_RDONLY|os.O_CREATE, 0644)
f.Close()
_ = f.Close()
terminal.Println("The local CA is now installed in the system trust store!")
}
if hasNSS() && (force || !ca.checkNSS()) {
Expand All @@ -168,7 +168,9 @@ func (ca *CA) Uninstall() error {
hasCertutil := certutilPath() != ""
if hasNSS() {
if hasCertutil {
ca.uninstallNSS()
if err := ca.uninstallNSS(); err != nil {
terminal.Printf("<warning>WARNING</> an error happened during CA uninstallation from %s: %s!\n", NSSBrowsers, err)
}
} else if CertutilInstallHelp != "" {
terminal.Printf("<warning>WARNING</> \"certutil\" is not available, so the CA can't be automatically uninstalled from %s (if it was ever installed)!\n", NSSBrowsers)
terminal.Printf("You can install \"certutil\" with \"%s\" and re-run the command\n", CertutilInstallHelp)
Expand Down Expand Up @@ -204,7 +206,9 @@ func Cert(filename string) (tls.Certificate, error) {
if err != nil {
return tls.Certificate{}, errors.WithStack(err)
}
defer ioutil.WriteFile(filename, pfxData, 0644)
if err := errors.WithStack(ioutil.WriteFile(filename, pfxData, 0644)); err != nil {
return tls.Certificate{}, err
}

certs := [][]byte{domainCert.Raw}
for _, c := range caCerts {
Expand Down
5 changes: 4 additions & 1 deletion truststore_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ func (ca *CA) installPlatform() error {
return errors.Wrap(err, "failed to create temp file")
}

defer os.Remove(plistFile.Name())
defer func(name string) {
// a failure during removal of this file is not important
_ = os.Remove(name)
}(plistFile.Name())

cmd = commandWithSudo("security", "trust-settings-export", "-d", plistFile.Name())
if out, err := cmd.CombinedOutput(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion truststore_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func getSystemTrust() (string, []string) {
}

func (ca *CA) systemTrustFilename(systemTrustFilenamePattern string) string {
return fmt.Sprintf(systemTrustFilenamePattern, strings.Replace(ca.caUniqueName(), " ", "_", -1))
return fmt.Sprintf(systemTrustFilenamePattern, strings.ReplaceAll(ca.caUniqueName(), " ", "_"))
}

func (ca *CA) installPlatform() error {
Expand Down
8 changes: 5 additions & 3 deletions truststore_nss.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ func (ca *CA) installNSS() error {
return nil
}

func (ca *CA) uninstallNSS() {
func (ca *CA) uninstallNSS() error {
certutilPath := certutilPath()
ca.forEachNSSProfile(func(profile string) error {
_, err := ca.forEachNSSProfile(func(profile string) error {
err := exec.Command(certutilPath, "-V", "-d", profile, "-u", "L", "-n", ca.caUniqueName()).Run()
if err != nil {
return nil
Expand All @@ -115,6 +115,8 @@ func (ca *CA) uninstallNSS() {
}
return nil
})

return err
}

func (ca *CA) forEachNSSProfile(f func(profile string) error) (int, error) {
Expand Down Expand Up @@ -156,5 +158,5 @@ func execCertutil(cmd *exec.Cmd) ([]byte, error) {
cmd.Args = append(cmd.Args, origArgs...)
out, err = cmd.CombinedOutput()
}
return out, err
return out, errors.WithStack(err)
}