Skip to content

Client for KeePassHTTP to fetch and edit credentials from Golang

License

Notifications You must be signed in to change notification settings

cyrbil/go_keepasshttp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go KeePassHTTP

version.svg godoc.svg report.svg stability.svg

license.svg travis_build.svg codecov.svg code_size.svg

Go client for KeePassHTTP to interact with KeePass's credentials.

Installation

$ go get -u github.com/cyrbil/go_keepasshttp/keepasshttp

Usage

Initialisation

package main

import (
	"fmt"
	"github.com/cyrbil/go_keepasshttp/keepasshttp"
)

func main() {
	kph := keepasshttp.New()
	...

Get single credential

credential, err := kph.Get(&keepasshttp.Filter{Url: "my_credential_name_or_url"})
if err != nil { panic(err) }
fmt.Printf("Login: %#v - Password: %#v", credential.Login, credential.Password)

Find all credentials's name

credentials, err := kph.List()
if err != nil { panic(err) }
for _, credential = range credentials {
    fmt.Printf("Login: %#v", credential.Login)
}

Fetch all partially matching credentials

credentials, err = kph.Search(&keepasshttp.Filter{
    SubmitUrl: "github.com", // Filter has other useful fields
})
if err != nil { panic(err) }
for _, credential := range credentials {
    fmt.Printf("Login: %#v - Password: %#v", credential.Login, credential.Password)
}

Create a new KeePassHTTP entry

err = kph.Create(&keepasshttp.Credential{
    Login: "hello",
    Password: "world",
    Url: "github.com",
})
if err != nil { panic(err) }

Update a KeePassHTTP entry

credential.Password = "new password"
err = credential.Commit()
if err != nil { panic(err) }
// or
err = kph.Update(&keepasshttp.Credential{
    Uuid: credential.Uuid,
    Login: "hello",
    Password: "world",
    Url: "github.com",
})
if err != nil { panic(err) }

Configuration

By default, this module will write AES association key to ~/.go_keepass_http and use http://localhost:19455/ to connect to the KeePassHTTP server.

To change theses parameters, instantiate keepasshttp.KeePassHTTP with different values.

kph := keepasshttp.New()
kph.Storage = "file.bin"
kph.Url = "http://remote/keepasshttp/server"

Testing

You can simply run the tests using:

$ cd keepasshttp
$ go test

KeePassHTTP calls are mocked, to run the tests against a real server, you need to:

  • open tests/test_database.kdbx in KeePass password is test
  • set TEST_WITH_KEEPASS environment variable
  • run test normally
  • KeePassHTTP will ask to store new key (enter unittest as name and press yes to overwrite) and yield various messages, this is all normal

Coverage

To run tests with coverage:

$ go get golang.org/x/tools/cmd/cover
$ go test -cover

About

Client for KeePassHTTP to fetch and edit credentials from Golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages