Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
shorten Kryptonite Core to Krypton Core
Browse files Browse the repository at this point in the history
  • Loading branch information
kcking committed Jan 6, 2018
1 parent 10f70c1 commit a632afe
Show file tree
Hide file tree
Showing 24 changed files with 196 additions and 150 deletions.
8 changes: 4 additions & 4 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
)

var ErrNotPaired = fmt.Errorf("Workstation not yet paired. Please run \"kr pair\" and scan the QRCode with the Kryptonite mobile app.")
var ErrTimedOut = fmt.Errorf("Request timed out. Make sure your phone and workstation are paired and connected to the internet and the Kryptonite app is running.")
var ErrSigning = fmt.Errorf("Kryptonite was unable to perform SSH login. Please restart the Kryptonite app on your phone.")
var ErrNotPaired = fmt.Errorf("Workstation not yet paired. Please run \"kr pair\" and scan the QRCode with the Krypton mobile app.")
var ErrTimedOut = fmt.Errorf("Request timed out. Make sure your phone and workstation are paired and connected to the internet and the Krypton app is running.")
var ErrSigning = fmt.Errorf("Krypton was unable to perform SSH login. Please restart the Krypton app on your phone.")
var ErrRejected = fmt.Errorf("Request Rejected ✘")
var ErrConnectingToDaemon = fmt.Errorf("Could not connect to Kryptonite daemon. Make sure it is running by typing \"kr restart\".")
var ErrConnectingToDaemon = fmt.Errorf("Could not connect to Krypton daemon. Make sure it is running by typing \"kr restart\".")
2 changes: 1 addition & 1 deletion file_persister.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (fp FilePersister) SaveMySSHPubKey(me Profile) (err error) {
if err != nil {
return
}
err = ioutil.WriteFile(filepath.Join(fp.SSHDir, ID_KRYPTONITE_FILENAME), []byte(authString), 0700)
err = ioutil.WriteFile(filepath.Join(fp.SSHDir, ID_KRYPTON_FILENAME), []byte(authString), 0700)
return
}

Expand Down
55 changes: 28 additions & 27 deletions kr/kr.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func pairCommand(c *cli.Context) (err error) {
}
err = autoEditSSHConfig()
if err != nil {
PrintErr(os.Stderr, kr.Red("Kryptonite ▶ Error verifying SSH config: "+err.Error()))
PrintErr(os.Stderr, kr.Red("Krypton ▶ Error verifying SSH config: "+err.Error()))
<-time.After(2 * time.Second)
PrintErr(os.Stderr, kr.Red("Kryptonite ▶ Continuing with pairing..."))
PrintErr(os.Stderr, kr.Red("Krypton ▶ Continuing with pairing..."))
<-time.After(2 * time.Second)
}
name := c.String("name")
Expand All @@ -94,9 +94,9 @@ func pairCommandForce() (err error) {
}
err = autoEditSSHConfig()
if err != nil {
PrintErr(os.Stderr, kr.Red("Kryptonite ▶ Error verifying SSH config: "+err.Error()))
PrintErr(os.Stderr, kr.Red("Krypton ▶ Error verifying SSH config: "+err.Error()))
<-time.After(2 * time.Second)
PrintErr(os.Stderr, kr.Red("Kryptonite ▶ Continuing with pairing..."))
PrintErr(os.Stderr, kr.Red("Krypton ▶ Continuing with pairing..."))
<-time.After(2 * time.Second)
}

Expand Down Expand Up @@ -132,7 +132,7 @@ func pairOver(unixFile string, forceUnpair bool, name *string, stdout io.ReadWri
if !forceUnpair {
meConn, err := kr.DaemonDialWithTimeout(unixFile)
if err != nil {
PrintFatal(stderr, "Could not connect to Kryptonite daemon. Make sure it is running by typing \"kr restart\".")
PrintFatal(stderr, "Could not connect to Krypton daemon. Make sure it is running by typing \"kr restart\".")
}
_, err = krdclient.RequestMeOver(meConn)
if err == nil {
Expand All @@ -141,7 +141,7 @@ func pairOver(unixFile string, forceUnpair bool, name *string, stdout io.ReadWri
}
putConn, err := kr.DaemonDialWithTimeout(unixFile)
if err != nil {
PrintFatal(stderr, "Could not connect to Kryptonite daemon. Make sure it is running by typing \"kr restart\".")
PrintFatal(stderr, "Could not connect to Krypton daemon. Make sure it is running by typing \"kr restart\".")
}
defer putConn.Close()

Expand Down Expand Up @@ -183,13 +183,13 @@ func pairOver(unixFile string, forceUnpair bool, name *string, stdout io.ReadWri
stdout.Write([]byte("\r\n"))
stdout.Write([]byte(qr.Terminal))
stdout.Write([]byte("\r\n"))
stdout.Write([]byte("Scan this QR Code with the Kryptonite mobile app to connect it with this workstation. Maximize the window and/or lower your font size if the QR code does not fit."))
stdout.Write([]byte("Scan this QR Code with the Krypton mobile app to connect it with this workstation. Maximize the window and/or lower your font size if the QR code does not fit."))
stdout.Write([]byte("\r\n"))

// Check/wait for pairing
getConn, err := kr.DaemonDialWithTimeout(unixFile)
if err != nil {
PrintFatal(stderr, "Could not connect to Kryptonite daemon. Make sure it is running by typing \"kr restart\".")
PrintFatal(stderr, "Could not connect to Krypton daemon. Make sure it is running by typing \"kr restart\".")
}
defer putConn.Close()
me, err := krdclient.RequestMeForceRefreshOver(getConn, nil)
Expand Down Expand Up @@ -241,12 +241,12 @@ func unpairOver(unixFile string, stdout io.ReadWriter, stderr io.ReadWriter) (er
}
switch response.StatusCode {
case http.StatusNotFound, http.StatusInternalServerError:
PrintFatal(stderr, "Unpair failed, ensure the Kryptonite daemon is running with \"kr restart\".")
PrintFatal(stderr, "Unpair failed, ensure the Krypton daemon is running with \"kr restart\".")
case http.StatusOK:
default:
PrintFatal(stderr, "Unpair failed with error %d", response.StatusCode)
}
stdout.Write([]byte("Unpaired Kryptonite.\r\n"))
stdout.Write([]byte("Unpaired Krypton.\r\n"))
return
}

Expand Down Expand Up @@ -275,7 +275,7 @@ func mePGPCommand(c *cli.Context) (err error) {

pgp, err := me.AsciiArmorPGPPublicKey()
if err != nil {
PrintFatal(os.Stderr, "You do not yet have a PGP public key. Make sure you have the latest version of the Kryptonite app and that you have run "+kr.Cyan("kr codesign")+" successfully.")
PrintFatal(os.Stderr, "You do not yet have a PGP public key. Make sure you have the latest version of the Krypton app and that you have run "+kr.Cyan("kr codesign")+" successfully.")
}
fmt.Println(pgp)

Expand Down Expand Up @@ -338,7 +338,7 @@ func copyPGPKeyNonFatalOnClipboardError() (me kr.Profile, pk string, err error)
}
pk, err = me.AsciiArmorPGPPublicKey()
if err != nil {
PrintFatal(os.Stderr, "You do not yet have a PGP public key. Make sure you have the latest version of the Kryptonite app and that you have run "+kr.Cyan("kr codesign")+" successfully.")
PrintFatal(os.Stderr, "You do not yet have a PGP public key. Make sure you have the latest version of the Krypton app and that you have run "+kr.Cyan("kr codesign")+" successfully.")
}
err = clipboard.WriteAll(pk)
return
Expand Down Expand Up @@ -493,7 +493,7 @@ func herokuCommand(c *cli.Context) (err error) {
PrintFatal(os.Stderr, "Failed to retrieve your public key:", err)
}
PrintErr(os.Stderr, "Adding your SSH public key using heroku toolbelt.")
addKeyCmd := exec.Command("heroku", "keys:add", filepath.Join(os.Getenv("HOME"), ".ssh", kr.ID_KRYPTONITE_FILENAME))
addKeyCmd := exec.Command("heroku", "keys:add", filepath.Join(os.Getenv("HOME"), ".ssh", kr.ID_KRYPTON_FILENAME))
addKeyCmd.Stdin = os.Stdin
addKeyCmd.Stdout = os.Stdout
addKeyCmd.Stderr = os.Stderr
Expand Down Expand Up @@ -552,19 +552,20 @@ func transferCommand(c *cli.Context) (err error) {
}

func restartCommand(c *cli.Context) (err error) {
upgradeSSHConfig()
return restartCommandOptions(c, true)
}

func main() {
app := cli.NewApp()
app.Name = "kr"
app.Usage = "communicate with Kryptonite and krd - the Kryptonite daemon"
app.Usage = "communicate with Krypton and krd - the Krypton daemon"
app.Version = kr.CURRENT_VERSION.String()
app.Flags = []cli.Flag{}
app.Commands = []cli.Command{
cli.Command{
Name: "pair",
Usage: "Initiate pairing of this workstation with a phone running Kryptonite.",
Usage: "Initiate pairing of this workstation with a phone running Krypton.",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force",
Expand All @@ -591,7 +592,7 @@ func main() {
},
cli.Command{
Name: "codesign",
Usage: "Setup Kryptonite to sign git commits.",
Usage: "Setup Krypton to sign git commits.",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "interactive,i",
Expand All @@ -602,12 +603,12 @@ func main() {
Subcommands: []cli.Command{
cli.Command{
Name: "uninstall",
Usage: "Uninstall Kryptonite codesigning.",
Usage: "Uninstall Krypton codesigning.",
Action: codesignUninstallCommand,
},
cli.Command{
Name: "test",
Usage: "Test Kryptonite codesigning.",
Usage: "Test Krypton codesigning.",
Action: codesignTestCommand,
},
cli.Command{
Expand Down Expand Up @@ -641,22 +642,22 @@ func main() {
},
cli.Command{
Name: "sshconfig",
Usage: "Verify SSH is configured to use Kryptonite.",
Usage: "Verify SSH is configured to use Krypton.",
Action: sshConfigCommand,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "print",
Usage: "Print Kryptonite SSH config block.",
Usage: "Print Krypton SSH config block.",
},
cli.BoolFlag{
Name: "force",
Usage: "Force append the Kryptonite SSH config block even if other Kryptonite-related lines are present.",
Usage: "Force append the Krypton SSH config block even if other Krypton-related lines are present.",
},
},
},
cli.Command{
Name: "transfer",
Usage: "Transfer authority to a new Kryptonite public key (authorize a new Kryptonite device's public key to servers)",
Usage: "Transfer authority to a new Krypton public key (authorize a new Krypton device's public key to servers)",
Action: transferCommand,
Flags: []cli.Flag{
cli.BoolFlag{
Expand Down Expand Up @@ -751,7 +752,7 @@ func main() {
},
cli.Command{
Name: "add",
Usage: "kr add <user@server or SSH alias> -- add your Kryptonite SSH public key to the server.",
Usage: "kr add <user@server or SSH alias> -- add your Krypton SSH public key to the server.",
Action: addCommand,
Flags: []cli.Flag{
cli.StringFlag{
Expand All @@ -762,22 +763,22 @@ func main() {
},
cli.Command{
Name: "restart",
Usage: "Restart the Kryptonite daemon.",
Usage: "Restart the Krypton daemon.",
Action: restartCommand,
},
cli.Command{
Name: "upgrade",
Usage: "Upgrade Kryptonite on this workstation.",
Usage: "Upgrade Krypton on this workstation.",
Action: upgradeCommand,
},
cli.Command{
Name: "unpair",
Usage: "Unpair this workstation from a phone running Kryptonite.",
Usage: "Unpair this workstation from a phone running Krypton.",
Action: unpairCommand,
},
cli.Command{
Name: "uninstall",
Usage: "Uninstall Kryptonite from this workstation.",
Usage: "Uninstall Krypton from this workstation.",
Action: uninstallCommand,
},
cli.Command{
Expand Down
21 changes: 11 additions & 10 deletions kr/kr_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ const PLIST_TEMPLATE = `<?xml version="1.0" encoding="UTF-8"?>
func copyPlist() (err error) {
output, err := exec.Command("which", "krd").Output()
if err != nil {
PrintErr(os.Stderr, kr.Red("Kryptonite ▶ Could not find krd on PATH, make sure krd is installed"))
PrintErr(os.Stderr, kr.Red("Krypton ▶ Could not find krd on PATH, make sure krd is installed"))
return
}
krdir, err := kr.KrDir()
if err != nil {
PrintErr(os.Stderr, kr.Red("Kryptonite ▶ Error finding ~/.kr folder: "+err.Error()))
PrintErr(os.Stderr, kr.Red("Krypton ▶ Error finding ~/.kr folder: "+err.Error()))
return
}
plistContents := fmt.Sprintf(PLIST_TEMPLATE, strings.TrimSpace(string(output)), krdir, krdir)
_ = os.MkdirAll(homePlistDir, 0700)
err = ioutil.WriteFile(homePlist, []byte(plistContents), 0700)
if err != nil {
PrintErr(os.Stderr, kr.Red("Kryptonite ▶ Error writing krd plist: "+err.Error()))
PrintErr(os.Stderr, kr.Red("Krypton ▶ Error writing krd plist: "+err.Error()))
return
}
return
Expand All @@ -77,7 +77,7 @@ func runCommandTmuxFriendly(cmd string, args ...string) (output string, err erro
outputBytes, err = exec.Command("reattach-to-user-namespace", "-l", "bash", "-c", subcommandArgs).CombinedOutput()
if err != nil {
if execErr, ok := err.(*exec.Error); ok && execErr.Err == exec.ErrNotFound {
PrintFatal(os.Stderr, kr.Red("Kryptonite ▶ Running tmux-friendly command failed. Make sure \"reattach-to-user-namespace\" is installed with \"brew install reattach-to-user-namespace\"\r\n"))
PrintFatal(os.Stderr, kr.Red("Krypton ▶ Running tmux-friendly command failed. Make sure \"reattach-to-user-namespace\" is installed with \"brew install reattach-to-user-namespace\"\r\n"))
}
}
} else {
Expand All @@ -98,7 +98,7 @@ func startKrd() (err error) {
_, _ = runCommandTmuxFriendly("launchctl", "unload", homePlist)
output, err := runCommandTmuxFriendly("launchctl", "load", homePlist)
if len(output) > 0 || err != nil {
err = fmt.Errorf(kr.Red("Kryptonite ▶ Error starting krd with launchctl: " + string(output)))
err = fmt.Errorf(kr.Red("Krypton ▶ Error starting krd with launchctl: " + string(output)))
PrintErr(os.Stderr, err.Error())
return
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func restartCommandOptions(c *cli.Context, isUserInitiated bool) (err error) {
}

if isUserInitiated {
fmt.Println("Restarted Kryptonite daemon.")
fmt.Println("Restarted Krypton daemon.")
}
return
}
Expand All @@ -153,7 +153,7 @@ func openBrowser(url string) {
}

func cleanSSHConfig() (err error) {
configBlock := []byte(getKryptoniteSSHConfigBlock())
configBlock := []byte(getKrSSHConfigBlock())
sshDirPath := os.Getenv("HOME") + "/.ssh"
sshConfigPath := sshDirPath + "/config"
sshConfigBackupPath := sshConfigPath + ".bak.kr.uninstall"
Expand All @@ -162,6 +162,7 @@ func cleanSSHConfig() (err error) {
if err != nil {
return
}
defer sshConfigFile.Close()
currentConfigContents, err := ioutil.ReadAll(sshConfigFile)
if err != nil {
return
Expand All @@ -185,7 +186,7 @@ func uninstallCommand(c *cli.Context) (err error) {
go func() {
kr.Analytics{}.PostEventUsingPersistedTrackingID("kr", "uninstall", nil, nil)
}()
confirmOrFatal(os.Stderr, "Uninstall Kryptonite from this workstation?")
confirmOrFatal(os.Stderr, "Uninstall Krypton from this workstation?")
_, _ = runCommandTmuxFriendly("brew", "uninstall", "kr")
_, _ = runCommandTmuxFriendly("npm", "uninstall", "-g", "krd")
prefix := getPrefix()
Expand All @@ -202,7 +203,7 @@ func uninstallCommand(c *cli.Context) (err error) {
os.Remove(homePlist)
cleanSSHConfig()
uninstallCodesigning()
PrintErr(os.Stderr, "Kryptonite uninstalled.")
PrintErr(os.Stderr, "Krypton uninstalled.")
return
}

Expand All @@ -220,7 +221,7 @@ func upgradeCommand(c *cli.Context) (err error) {
go func() {
kr.Analytics{}.PostEventUsingPersistedTrackingID("kr", "upgrade", nil, nil)
}()
confirmOrFatal(os.Stderr, "Upgrade Kryptonite on this workstation?")
confirmOrFatal(os.Stderr, "Upgrade Krypton on this workstation?")
var cmd *exec.Cmd
if installedWithBrew() {
cmd = exec.Command("brew", "upgrade", "kryptco/tap/kr")
Expand Down
14 changes: 7 additions & 7 deletions kr/kr_pgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func codesignCommand(c *cli.Context) (err error) {

pk, err := me.AsciiArmorPGPPublicKey()
if err != nil {
PrintFatal(stderr, "You do not yet have a PGP public key. Make sure you have the latest version of the Kryptonite app and try again.")
PrintFatal(stderr, "You do not yet have a PGP public key. Make sure you have the latest version of the Krypton app and try again.")
}

whichKrGPG, err := exec.Command("which", "krgpg").Output()
Expand Down Expand Up @@ -117,13 +117,13 @@ func codesignTestCommand(c *cli.Context) (err error) {
os.Setenv("GIT_WORK_DIR", dir+"/repo")
runCommandWithOutputOrFatal(exec.Command("git", "init", dir+"/repo"))
runCommandWithOutputOrFatal(exec.Command("git", "commit", "-S", "--allow-empty", "-m", "Testing your first signed commit"))
PrintErr(os.Stderr, kr.Green("Kryptonite ▶ Codesigning successful ✔"))
PrintErr(os.Stderr, kr.Green("Krypton ▶ Codesigning successful ✔"))
return
}

func codesignUninstallCommand(c *cli.Context) (err error) {
uninstallCodesigning()
os.Stderr.WriteString("Kryptonite codesigning uninstalled... run " + kr.Cyan("kr codesign") + " to reinstall.\r\n")
os.Stderr.WriteString("Krypton codesigning uninstalled... run " + kr.Cyan("kr codesign") + " to reinstall.\r\n")
return
}

Expand All @@ -134,7 +134,7 @@ func onboardGithub(pk string) {
if in[0] == 'y' {
copyPGPKey()
<-time.After(1000 * time.Millisecond)
os.Stderr.WriteString("Press " + kr.Cyan("ENTER") + " to open your browser to GitHub settings. Then click " + kr.Cyan("New GPG key") + " and paste your Kryptonite PGP public key.\r\n")
os.Stderr.WriteString("Press " + kr.Cyan("ENTER") + " to open your browser to GitHub settings. Then click " + kr.Cyan("New GPG key") + " and paste your Krypton PGP public key.\r\n")
os.Stdin.Read([]byte{0})
openBrowser("https://github.com/settings/keys")
}
Expand Down Expand Up @@ -217,7 +217,7 @@ func addGPG_TTYExportToCurrentShellIfNotPresent() (path, cmd string) {
}
// seek to end
rcFile.Seek(0, 2)
rcFile.WriteString("\n# Added by Kryptonite\n" + cmd + "\n")
rcFile.WriteString("\n# Added by Krypton\n" + cmd + "\n")
rcFile.Close()
return
}
Expand All @@ -226,7 +226,7 @@ func onboardGPG_TTY(interactive bool) {
cmd := "export GPG_TTY=$(tty); "
if os.Getenv("GPG_TTY") == "" {
if interactive {
os.Stderr.WriteString("\r\n" + kr.Red("WARNING:") + " In order to see Kryptonite log messages when requesting a git signature, add " + kr.Yellow("export GPG_TTY=$(tty)") + " to your shell startup (~/.bash_profile, ~/.zshrc, etc.) and restart your terminal.\r\n")
os.Stderr.WriteString("\r\n" + kr.Red("WARNING:") + " In order to see Krypton log messages when requesting a git signature, add " + kr.Yellow("export GPG_TTY=$(tty)") + " to your shell startup (~/.bash_profile, ~/.zshrc, etc.) and restart your terminal.\r\n")
os.Stderr.WriteString("Press " + kr.Cyan("ENTER") + " to continue")
os.Stdin.Read([]byte{0})
os.Stderr.WriteString("\r\n")
Expand Down Expand Up @@ -318,7 +318,7 @@ func checkGitLocation() {
}
gitLocationStr := strings.TrimSpace(string(gitLocation))

PrintErr(os.Stderr, "git must be linked to /usr/bin or /usr/local/bin to work with Kryptonite (current location "+gitLocationStr+")")
PrintErr(os.Stderr, "git must be linked to /usr/bin or /usr/local/bin to work with Krypton (current location "+gitLocationStr+")")
if confirm(os.Stderr, "Link git to /usr/local/bin?") {

linkGitCmd := exec.Command("ln", "-s", gitLocationStr, "/usr/local/bin/git")
Expand Down
Loading

0 comments on commit a632afe

Please sign in to comment.