Skip to content

Commit

Permalink
Merge tag '0.9.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nbari committed Mar 3, 2017
2 parents 5ec1cb7 + 395c764 commit 83cc4e4
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 10 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ get:
${GO} get

build: get
#${GO} get -u github.com/keybase/go-keychain
#${GO} get -u github.com/kr/pty
#${GO} get -u github.com/ssh-vault/crypto
#${GO} get -u github.com/ssh-vault/crypto/aead
#${GO} get -u github.com/ssh-vault/crypto/oaep
#${GO} get -u github.com/ssh-vault/ssh2pem
#${GO} get -u golang.org/x/crypto/ssh/terminal
${GO} get -u github.com/keybase/go-keychain
${GO} get -u github.com/kr/pty
${GO} get -u github.com/ssh-vault/crypto
${GO} get -u github.com/ssh-vault/crypto/aead
${GO} get -u github.com/ssh-vault/crypto/oaep
${GO} get -u github.com/ssh-vault/ssh2pem
${GO} get -u golang.org/x/crypto/ssh/terminal
${GO} build -ldflags "-X main.version=${VERSION}" -o ${BIN_NAME} cmd/ssh-vault/main.go;

clean:
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Usage:

$ ssh-vault -h

Example:

$ echo "secret" | ssh-vault -u <github.com/user> create


## Compile from source

Expand All @@ -38,4 +42,10 @@ Build by just typing make:
$ make


**ssh-vault** is at an early development stage, please feel free to raise any issue, feature requirement or a simple comment [here](https://github.com/ssh-vault/ssh-vault/issues).
## Issues

Please feel free to raise any issue, feature requirement or a simple comment [here](https://github.com/ssh-vault/ssh-vault/issues).

## Donate

If you like this project, please do consider becoming a [patron!](https://www.patreon.com/nbari).
6 changes: 4 additions & 2 deletions cmd/ssh-vault/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ func main() {
)

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [-k key] [-u user] [create|edit|view] vault\n\n%s\n%s\n%s\n%s\n\n",
fmt.Fprintf(os.Stderr, "Usage: %s [-k key] [-u user] [create|edit|view] vault\n\n%s\n%s\n%s\n%s\n%s\n%s\n\n",
os.Args[0],
" Options:",
" create Creates a new vault",
" create Creates a new vault, if no vault defined outputs to stdout.",
" Can read from stdin, example:",
" echo \"secret\" | ssh-vault -u <user> create",
" edit Edit an existing vault",
" view View an existing vault")
flag.PrintDefaults()
Expand Down
56 changes: 56 additions & 0 deletions vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,62 @@ func TestVaultFunctions(t *testing.T) {
}
}

func TestVaultFunctionsSTDOUT(t *testing.T) {
dir, err := ioutil.TempDir("", "vault")
if err != nil {
t.Error(err)
}
defer os.RemoveAll(dir) // clean up

vault, err := New("test_data/id_rsa.pub", "", "create", "")
if err != nil {
t.Error(err)
}

if err = vault.PKCS8(); err != nil {
t.Error(err)
}

if vault.Password, err = crypto.GenerateNonce(32); err != nil {
t.Error(err)
}

// Skip vault.Create because we don't need/want to interact with an editor
in := []byte("The quick brown fox jumps over the lazy dog")

out, err := aead.Encrypt(vault.Password, in, []byte(vault.Fingerprint))
if err != nil {
t.Error(err)
}

rescueStdout := os.Stdout // keep backup of the real stdout
r, w, _ := os.Pipe()
os.Stdout = w

if err = vault.Close(out); err != nil {
t.Error(err)
}

w.Close()
outStdout, _ := ioutil.ReadAll(r)
os.Stdout = rescueStdout
tmpfile, err := ioutil.TempFile("", "stdout")
if err != nil {
t.Error(err)
}
tmpfile.Write([]byte(outStdout))
vault.vault = tmpfile.Name()

plaintext, err := vault.View()
if err != nil {
t.Error(err)
}

if !bytes.Equal(in, plaintext) {
t.Error("in != out")
}
}

func TestVaultNew(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
expect(t, "ssh-vault", r.Header.Get("User-agent"))
Expand Down

0 comments on commit 83cc4e4

Please sign in to comment.