Skip to content

Commit f51813c

Browse files
committed
feat: support SQLCipher v4
1 parent 37b937f commit f51813c

6 files changed

Lines changed: 69 additions & 41 deletions

File tree

.github/go/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
FROM golang:1.24
1+
FROM golang:1.25

goreleaser.yml renamed to .github/goreleaser.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
version: 2
2+
13
before:
24
hooks:
35
- go mod download
@@ -11,11 +13,23 @@ builds:
1113
goarch:
1214
- amd64
1315
env:
14-
- CC=gcc
15-
- CXX=g++
16+
- CC=x86_64-linux-gnu-gcc
17+
- CXX=x86_64-linux-gnu-g++
18+
ldflags:
19+
- -s -w -X main.version={{.Version}}
20+
- id: linux-arm64
21+
main: ./cmd/enpasscli/main.go
22+
binary: enpasscli
23+
goos:
24+
- linux
25+
goarch:
26+
- arm64
27+
env:
28+
- CC=aarch64-linux-gnu-gcc
29+
- CXX=aarch64-linux-gnu-g++
1630
ldflags:
1731
- -s -w -X main.version={{.Version}}
18-
- id: darwin64
32+
- id: darwin
1933
main: ./cmd/enpasscli/main.go
2034
binary: enpasscli
2135
goos:
@@ -42,19 +56,20 @@ builds:
4256
- CXX=arm-linux-gnueabihf-g++
4357
ldflags:
4458
- -s -w -X main.version={{.Version}}
59+
4560
archives:
4661
- id: enpass-cli
47-
builds:
48-
- darwin64
49-
- linux64
50-
- linux-armhf
5162
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
52-
format: zip
63+
formats:
64+
- zip
5365
wrap_in_directory: true
66+
5467
checksum:
5568
name_template: 'checksums.txt'
69+
5670
snapshot:
57-
name_template: "{{ .Tag }}"
71+
version_template: "{{ .Tag }}"
72+
5873
changelog:
5974
sort: asc
6075
filters:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ release-dry-run:
2626
-v `pwd`/sysroot:/sysroot \
2727
-w /go/src/$(PACKAGE_NAME) \
2828
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
29-
--clean --skip=publish,validate
29+
--config .github/goreleaser.yml --clean --skip=publish,validate
3030

3131
.PHONY: release
3232
release:
@@ -44,4 +44,4 @@ release:
4444
-v `pwd`/sysroot:/sysroot \
4545
-w /go/src/$(PACKAGE_NAME) \
4646
ghcr.io/goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
47-
release --clean
47+
--config .github/goreleaser.yml release --clean

go.mod

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ toolchain go1.24.3
66

77
require (
88
github.com/atotto/clipboard v0.1.4
9-
github.com/gdamore/tcell/v2 v2.13.7
9+
github.com/gdamore/tcell/v2 v2.13.8
1010
github.com/miquella/ask v1.0.0
11-
github.com/mutecomm/go-sqlcipher v0.0.0-20190227152316-55dbde17881f
11+
github.com/mutecomm/go-sqlcipher/v4 v4.4.2
1212
github.com/pkg/errors v0.9.1
1313
github.com/rivo/tview v0.42.0
14-
github.com/sirupsen/logrus v1.9.3
14+
github.com/sirupsen/logrus v1.9.4
1515
golang.org/x/crypto v0.47.0
1616
)
1717

1818
require (
1919
github.com/gdamore/encoding v1.0.1 // indirect
2020
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
2121
github.com/rivo/uniseg v0.4.7 // indirect
22-
golang.org/x/net v0.49.0 // indirect
2322
golang.org/x/sys v0.40.0 // indirect
2423
golang.org/x/term v0.39.0 // indirect
2524
golang.org/x/text v0.33.0 // indirect

go.sum

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
66
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=
77
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
8-
github.com/gdamore/tcell/v2 v2.13.7 h1:yfHdeC7ODIYCc6dgRos8L1VujQtXHmUpU6UZotzD6os=
9-
github.com/gdamore/tcell/v2 v2.13.7/go.mod h1:+Wfe208WDdB7INEtCsNrAN6O2m+wsTPk1RAovjaILlo=
8+
github.com/gdamore/tcell/v2 v2.13.8 h1:Mys/Kl5wfC/GcC5Cx4C2BIQH9dbnhnkPgS9/wF3RlfU=
9+
github.com/gdamore/tcell/v2 v2.13.8/go.mod h1:+Wfe208WDdB7INEtCsNrAN6O2m+wsTPk1RAovjaILlo=
1010
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
1111
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
1212
github.com/miquella/ask v1.0.0 h1:QrFtpgA7tbDSlPUUwCMaAzZLnWseFZtryAn/pnvd3d8=
1313
github.com/miquella/ask v1.0.0/go.mod h1:5hBixDZi2issKiqBf4oQ5c8BauqAYOOrkFOjG4eiUWk=
14-
github.com/mutecomm/go-sqlcipher v0.0.0-20190227152316-55dbde17881f h1:hd3r+uv9DNLScbOrnlj82rBldHQf3XWmCeXAWbw8euQ=
15-
github.com/mutecomm/go-sqlcipher v0.0.0-20190227152316-55dbde17881f/go.mod h1:MyUWrZlB1aI5bs7j9/pJ8ckLLZ4QcCYcNiSbsAW32D4=
14+
github.com/mutecomm/go-sqlcipher/v4 v4.4.2 h1:eM10bFtI4UvibIsKr10/QT7Yfz+NADfjZYh0GKrXUNc=
15+
github.com/mutecomm/go-sqlcipher/v4 v4.4.2/go.mod h1:mF2UmIpBnzFeBdu/ypTDb/LdbS0nk0dfSN1WUsWTjMA=
1616
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1717
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1818
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -21,34 +21,30 @@ github.com/rivo/tview v0.42.0 h1:b/ftp+RxtDsHSaynXTbJb+/n/BxDEi+W3UfF5jILK6c=
2121
github.com/rivo/tview v0.42.0/go.mod h1:cSfIYfhpSGCjp3r/ECJb+GKS7cGJnqV8vfjQPwoXyfY=
2222
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
2323
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
24-
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
25-
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
24+
github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w=
25+
github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g=
2626
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2727
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
28-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
29-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
28+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
29+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3030
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
3131
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3232
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
3333
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
3434
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
3535
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
3636
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
37-
golang.org/x/net v0.0.0-20190225153610-fe579d43d832/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
3837
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
3938
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
4039
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
4140
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
42-
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
43-
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
4441
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
4542
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
4643
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
4744
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4845
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4946
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5047
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
51-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5248
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5349
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5450
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
@@ -70,6 +66,5 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
7066
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
7167
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
7268
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
73-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
74-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
75-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
69+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
70+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/enpass/vault.go

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010

1111
// sqlcipher is necessary for sqlite crypto support
12-
_ "github.com/mutecomm/go-sqlcipher"
12+
_ "github.com/mutecomm/go-sqlcipher/v4"
1313
"github.com/pkg/errors"
1414
"github.com/sirupsen/logrus"
1515
)
@@ -94,18 +94,37 @@ func NewVault(vaultPath string, logLevel logrus.Level) (*Vault, error) {
9494
func (v *Vault) openEncryptedDatabase(path string, dbKey []byte) (err error) {
9595
// The raw key for the sqlcipher database is given
9696
// by the first 64 characters of the hex-encoded key
97-
dbName := fmt.Sprintf(
98-
"%s?_pragma_key=x'%s'&_pragma_cipher_compatibility=3",
99-
path,
100-
hex.EncodeToString(dbKey)[:masterKeyLength],
101-
)
97+
hexKey := hex.EncodeToString(dbKey)[:masterKeyLength]
98+
99+
// Try SQLCipher v4 first (Enpass 6.8+), then fall back to v3 for older databases
100+
for _, cipherVersion := range []int{4, 3} {
101+
dbName := fmt.Sprintf(
102+
"%s?_pragma_key=x'%s'&_pragma_cipher_compatibility=%d",
103+
path,
104+
hexKey,
105+
cipherVersion,
106+
)
107+
108+
v.db, err = sql.Open("sqlite3", dbName)
109+
if err != nil {
110+
v.logger.WithError(err).WithField("cipher_version", cipherVersion).Debug("could not open database")
111+
continue
112+
}
102113

103-
v.db, err = sql.Open("sqlite3", dbName)
104-
if err != nil {
105-
return errors.Wrap(err, "could not open database")
114+
// Verify the database can actually be read (key/version is correct)
115+
var testResult int
116+
if err = v.db.QueryRow("SELECT count(*) FROM sqlite_master").Scan(&testResult); err != nil {
117+
v.logger.WithError(err).WithField("cipher_version", cipherVersion).Debug("could not query database")
118+
_ = v.db.Close()
119+
v.db = nil
120+
continue
121+
}
122+
123+
v.logger.WithField("cipher_version", cipherVersion).Debug("successfully opened database")
124+
return nil
106125
}
107126

108-
return nil
127+
return errors.New("could not open database: invalid password or unsupported database version")
109128
}
110129

111130
func (v *Vault) checkPaths() error {

0 commit comments

Comments
 (0)