Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go-cache-plugin: add installSigningCert for Darwin #7

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
37 changes: 37 additions & 0 deletions cmd/go-cache-plugin/addca_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause

package main

import (
"os"
"os/exec"

"github.com/creachadair/command"
"github.com/creachadair/tlsutil"
)

func installSigningCert(env *command.Env, cert tlsutil.Certificate) error {
tf, err := os.CreateTemp("", "addca.*")
if err != nil {
return err
}
defer os.Remove(tf.Name())
defer tf.Close()

if _, err := tf.Write(cert.CertPEM()); err != nil {
return err
} else if err := tf.Close(); err != nil {
return err
}

const systemKeychain = "/Library/Keychains/System.keychain"
return sudo("security", "add-trusted-cert", "-d", "-k", systemKeychain, tf.Name())
}

func sudo(args ...string) error {
cmd := exec.Command("sudo", args...)
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
return cmd.Run()
}
6 changes: 2 additions & 4 deletions cmd/go-cache-plugin/addca_default.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause

//go:build !linux
//go:build !(linux || darwin)

package main

Expand All @@ -13,9 +13,7 @@ import (
)

func installSigningCert(env *command.Env, cert tlsutil.Certificate) error {
// TODO(creachadair): Maybe crib some other cases from mkcert, if we need
// them, for example:
// https://github.com/FiloSottile/mkcert/blob/master/truststore_darwin.go
// TODO(creachadair): Maybe crib other cases from mkcert, if we need them.

return errors.New("unable to install a certificate on this system")
}