This library allows to interact with KeepassXC Browser Integration server. It's protocol not documented well but can be found in source code. This repository also contains additional "adapter" utilities for storing credentials in KeepassXC database.
Protocol uses "request-response" model but also contains some asynchronous notifications. Typical workflow: 0. Create client
- Request database hash using
Client.GetDatabaseHash
. - Lookup association credentials by received hash and use it
Client.SetAssociationCredentials
. - Request a new association if such credentials was not found on step 2 using
Client.Associate
. Then get them usingClient.AssociationCredentials
and store in safe place. - Optionally subscribe to asynchronous events.
- Make requests.
- Close client.
package main
import (
"context"
"fmt"
"github.com/xakep666/gkpxc"
)
func main() {
client, err := gkpxc.NewClient(context.Background(), gkpxc.WithLockChangeHandler(func(locked bool) {
fmt.Printf("lock changed: %t\n", locked)
}))
if err != nil {
panic(err)
}
defer client.Close()
dbHash, err := client.GetDatabaseHash(context.Background(), false)
if err != nil {
panic(err)
}
fmt.Printf("KeepassXC version: %s, Database hash: %s\n", dbHash.Version, dbHash.Hash)
err = client.Associate(context.Background())
if err != nil {
panic(err)
}
associationCreds := client.AssociationCredentials()
// store them somewhere
fmt.Printf("Association ID: %s, Association private key: %v\n", associationCreds.ID, associationCreds.PrivateKey)
groups, err := client.GetDatabaseGroups(context.Background())
if err != nil {
panic(err)
}
for _, group := range groups.Groups.Groups {
fmt.Printf("Group UUID: %s, name: %s\n", group.UUID, group.Name)
}
}
This library contains two kind of tests: unit and integration.
Unit-tests runs with just go test
.
Integration tests adds some requirements:
- KeepassXC at least 2.7.0 installed on your system
- KeepassXC is not running
- Requirements for additional utilities (see in corresponding README's).
To specify custom KeepassXC executable location use KEEPASSXC_EXECUTABLE
environment variable (i.e. testing.yml).
To run integration tests use go test -tags integration ./...
.
Note that some tests contain long sleeps used to wait for KeepassXC startup.