This repository has been archived by the owner on Nov 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,002 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,27 @@ | ||
pick | ||
==== | ||
A minimal password manager for OS X and Linux. | ||
|
||
![demo](https://github.com/bndw/pick/raw/master/demo.gif) | ||
|
||
Features | ||
-------- | ||
* GPG for encryption | ||
* JSON formatted data | ||
* Password generation | ||
* Environment Variable configuration | ||
|
||
Dependencies | ||
------------ | ||
#### GPG | ||
* **OS X**: `brew install gpg` | ||
* **Linux**: `sudo apt-get install gnupg` | ||
### Install | ||
```sh | ||
$ go get github.com/bndw/pick | ||
``` | ||
|
||
#### xclip (Linux only) | ||
* **Linux**: `sudo apt-get install xclip` | ||
### Usage | ||
``` | ||
Usage: | ||
pick [command] | ||
Installation | ||
------------ | ||
1. Clone the repository | ||
```sh | ||
git clone https://github.com/bndw/pick.git && cd pick | ||
``` | ||
Available Commands: | ||
add Add a credential | ||
cat Cat a credential | ||
cp Copy a credential to the clipboard | ||
export Export decrypted credentials in JSON format | ||
ls List all credentials | ||
rm Remove a credential | ||
2. Copy the `pick` executable into your PATH | ||
```sh | ||
cp pick /usr/local/bin | ||
``` | ||
Flags: | ||
-h, --help help for pick | ||
Commands | ||
-------- | ||
``` | ||
add [ALIAS] [USERNAME] [PASSWORD] Add a credential to the safe | ||
cat ALIAS Print a credential to STDOUT | ||
cp ALIAS Copy a credential's password to the clipboard | ||
ls List credentials | ||
rm ALIAS Remove a credential | ||
Use "pick [command] --help" for more information about a command. | ||
``` | ||
|
||
Config | ||
------ | ||
* Override the safe location (default: ~/.pick.safe) | ||
```sh | ||
export PICK_SAFE=/path/to/pick.safe | ||
``` | ||
# Similar software | ||
[pwd.sh: Unix shell, GPG-based password manager](https://github.com/drduh/pwd.sh) | ||
[Pass: the standard unix password manager](http://www.passwordstore.org/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bndw/pick/errors" | ||
"github.com/bndw/pick/utils" | ||
) | ||
|
||
const ( | ||
passwordLength = 25 | ||
) | ||
|
||
func addCommand(args ...string) int { | ||
safe, err := loadSafe() | ||
if err != nil { | ||
return handleError(err) | ||
} | ||
|
||
name, username, password, errCode := parseAddArgs(args) | ||
if errCode > 0 { | ||
return errCode | ||
} | ||
|
||
err = safe.Add(name, username, password) | ||
if _, confict := err.(*errors.AccountExists); confict { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
if overwrite(name) { | ||
// Remove the existing credential | ||
rerr := safe.Remove(name) | ||
if rerr != nil { | ||
return handleError(rerr) | ||
} | ||
|
||
addCommand([]string{name, username, password}...) | ||
} | ||
} else if err != nil { | ||
return handleError(err) | ||
} | ||
|
||
fmt.Println("Credential added") | ||
return 0 | ||
} | ||
|
||
func overwrite(name string) bool { | ||
prompt := fmt.Sprintf("%s already exists, overwrite (y/n) ?\n", name) | ||
return utils.GetAnswer(prompt) | ||
} | ||
|
||
func parseAddArgs(args []string) (name, username, password string, errCode int) { | ||
if len(args) > 3 { | ||
fmt.Println("Usage: add [name] [username] [password]") | ||
return "", "", "", 1 | ||
} | ||
|
||
switch len(args) { | ||
case 3: | ||
name = args[0] | ||
username = args[1] | ||
password = args[2] | ||
case 2: | ||
name = args[0] | ||
username = args[1] | ||
case 1: | ||
name = args[0] | ||
} | ||
|
||
errCode = 1 | ||
var err error | ||
|
||
if name == "" { | ||
if name, err = utils.GetInput("Enter a credential name"); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
|
||
if username == "" { | ||
if username, err = utils.GetInput(fmt.Sprintf("Enter a username for %s", name)); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} | ||
|
||
if password == "" { | ||
if utils.GetAnswer("Generate password (y/n)?") { | ||
password, err = utils.GeneratePassword(passwordLength) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
} else { | ||
var _password []byte | ||
if _password, err = utils.GetPasswordInput(fmt.Sprintf("Enter a password for %s", name)); err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
password = string(_password) | ||
} | ||
} | ||
|
||
errCode = 0 | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package backends | ||
|
||
type Backend interface { | ||
Load() ([]byte, error) | ||
Save([]byte) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package backends | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"os/user" | ||
|
||
"github.com/bndw/pick/errors" | ||
) | ||
|
||
const ( | ||
safeDirMode = 0700 | ||
safeMode = 0600 | ||
safeFilename = "pick.safe" | ||
) | ||
|
||
type DiskBackend struct { | ||
path string | ||
} | ||
|
||
func defaultSafePath() *string { | ||
// TODO(): This will not work on Windows. | ||
usr, err := user.Current() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
safeDir := fmt.Sprintf("%s/.pick", usr.HomeDir) | ||
|
||
if _, err := os.Stat(safeDir); os.IsNotExist(err) { | ||
if mkerr := os.Mkdir(safeDir, safeDirMode); mkerr != nil { | ||
panic(mkerr) | ||
} | ||
} | ||
|
||
safePath := fmt.Sprintf("%s/%s", safeDir, safeFilename) | ||
|
||
return &safePath | ||
} | ||
|
||
func NewDiskBackend(path *string) *DiskBackend { | ||
if path == nil { | ||
path = defaultSafePath() | ||
} | ||
|
||
return &DiskBackend{*path} | ||
} | ||
|
||
func (db *DiskBackend) Load() ([]byte, error) { | ||
if _, err := os.Stat(db.path); os.IsNotExist(err) { | ||
return nil, &errors.SafeNotFound{} | ||
} | ||
|
||
return ioutil.ReadFile(db.path) | ||
} | ||
|
||
func (db *DiskBackend) Save(data []byte) error { | ||
return ioutil.WriteFile(db.path, data, safeMode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Building pick..." | ||
mkdir -p bin | ||
go build -o bin/pick . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bndw/pick/utils" | ||
) | ||
|
||
func catCommand(args ...string) int { | ||
safe, err := loadSafe() | ||
if err != nil { | ||
return handleError(err) | ||
} | ||
|
||
account, err := safe.Cat(args[0]) | ||
if err != nil { | ||
return handleError(err) | ||
} | ||
|
||
fmt.Printf(`account: %s | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
username: %s | ||
password: %s | ||
created: %s | ||
`, account.Name, account.Username, account.Password, | ||
utils.FormatUnixTime(account.CreatedOn)) | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -f bin/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
func copyCommand(args ...string) int { | ||
safe, err := loadSafe() | ||
if err != nil { | ||
return handleError(err) | ||
} | ||
|
||
if err := safe.Copy(args[0]); err != nil { | ||
return handleError(err) | ||
} | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package errors | ||
|
||
type SafeNotFound struct { | ||
} | ||
|
||
func (e *SafeNotFound) Error() string { | ||
return "Safe not found" | ||
} | ||
|
||
type SafeCorrupt struct { | ||
} | ||
|
||
func (e *SafeCorrupt) Error() string { | ||
return "Safe currupt" | ||
} | ||
|
||
type AccountExists struct { | ||
} | ||
|
||
func (e *AccountExists) Error() string { | ||
return "Account exists" | ||
} | ||
|
||
type AccountNotFound struct { | ||
} | ||
|
||
func (e *AccountNotFound) Error() string { | ||
return "Account not found" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bndw/pick/utils" | ||
) | ||
|
||
func exportCommand(args ...string) int { | ||
safe, err := loadSafe() | ||
if err != nil { | ||
return handleError(err) | ||
} | ||
|
||
accounts, err := safe.List() | ||
if err != nil { | ||
return handleError(err) | ||
} | ||
|
||
if len(accounts) < 1 { | ||
fmt.Println("No accounts to export") | ||
return 1 | ||
} | ||
|
||
var accountSlice []interface{} | ||
for _, account := range accounts { | ||
accountSlice = append(accountSlice, account) | ||
} | ||
|
||
utils.PrettyPrint(accountSlice) | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
BIN_DIR=${BIN_DIR:-/usr/local/bin} | ||
INSTALL=install | ||
|
||
echo "Installing pick to $BIN_DIR/pick..." | ||
$INSTALL -c bin/pick $BIN_DIR/pick |
Oops, something went wrong.
confict
->conflict
;)