Skip to content

Commit

Permalink
Merge pull request #95 from attilagyorffy/fix/sierra-keychain-fixes
Browse files Browse the repository at this point in the history
Allow TrustCert() to use the right keychain on macOS Sierra
  • Loading branch information
evanphx authored Jan 7, 2017
2 parents 5a0ff50 + 5634568 commit 826e5b1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion dev/ssl_darwin.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
package dev

import (
"errors"
"fmt"
"os"
"os/exec"

"github.com/puma/puma-dev/homedir"
)

const supportDir = "~/Library/Application Support/io.puma.dev"

func LoginKeyChain() (string, error) {

new_keychain_path := homedir.MustExpand("~/Library/Keychains/login.keychain-db")
old_keychain_path := homedir.MustExpand("~/Library/Keychains/login.keychain")

if _, err := os.Stat(new_keychain_path); err == nil {
return new_keychain_path, nil
}

if _, err := os.Stat(old_keychain_path); err == nil {
return old_keychain_path, nil
}

return "", errors.New("Could not find login keychain")
}

func TrustCert(cert string) error {
fmt.Printf("* Adding certification to login keychain as trusted\n")
fmt.Printf("! There is probably a dialog open that you must type your password into\n")

login := homedir.MustExpand("~/Library/Keychains/login.keychain")
login, keychainError := LoginKeyChain()

if keychainError != nil {
return keychainError
}

err := exec.Command("sh", "-c",
fmt.Sprintf(`security add-trusted-cert -d -r trustRoot -k '%s' '%s'`,
Expand Down

0 comments on commit 826e5b1

Please sign in to comment.