drop unused session secrets

This commit is contained in:
Finn 2024-04-23 19:05:37 -07:00
parent 538864697d
commit 3791b5ee48
5 changed files with 5 additions and 31 deletions

View file

@ -17,7 +17,7 @@
FROM library/golang:1.21 AS build
ADD . /go/lockserver
WORKDIR /go/lockserver
RUN CGO_ENABLED=0 go build .
RUN CGO_ENABLED=0 go build ./cmd/lockserver
FROM scratch
COPY --from=build /go/lockserver/lockserver /lockserver

View file

@ -1,27 +1,23 @@
package config
import (
"encoding/base64"
"encoding/json"
"errors"
"os"
"github.com/gorilla/securecookie"
"github.com/sirupsen/logrus"
)
type Config struct {
ZWaveJSServer string `json:"zwave-js-server"`
SqliteDatabase string `json:"sqlite-database"`
HTTPBind string `json:"http-bind"`
SessionSecrets []JSONBytes `json:"session-secrets"`
ZWaveJSServer string `json:"zwave-js-server"`
SqliteDatabase string `json:"sqlite-database"`
HTTPBind string `json:"http-bind"`
}
var C = Config{
ZWaveJSServer: "ws://home-assistant:3000",
SqliteDatabase: "lockserver.db",
HTTPBind: ":8080",
SessionSecrets: []JSONBytes{},
}
var configFiles = []string{"lockserver.json", "/etc/lockserver.json"}
@ -38,14 +34,6 @@ func Load() error {
logrus.WithField("file", path).Info("loaded config")
}
if len(C.SessionSecrets) == 0 {
logrus.WithFields(logrus.Fields{
"rand_64": base64.URLEncoding.EncodeToString(securecookie.GenerateRandomKey(64)),
"rand_32": base64.URLEncoding.EncodeToString(securecookie.GenerateRandomKey(32)),
}).Info("some potential session secrets for you (hint: use both)")
return errors.New("no session secrets defined, some possible values have been logged")
}
return nil
}
@ -62,11 +50,3 @@ func load(path string) error {
return nil
}
func (c Config) GetSessionSecrets() [][]byte {
var resp [][]byte
for _, s := range c.SessionSecrets {
resp = append(resp, s.AsByteArrayArray())
}
return resp
}

1
go.mod
View file

@ -6,7 +6,6 @@ require (
github.com/failsafe-go/failsafe-go v0.6.2
github.com/getkin/kin-openapi v0.124.0
github.com/google/uuid v1.6.0
github.com/gorilla/securecookie v1.1.2
github.com/gorilla/websocket v1.5.1
github.com/labstack/echo/v4 v4.11.4
github.com/mattn/go-sqlite3 v1.14.22

4
go.sum
View file

@ -62,14 +62,10 @@ github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOW
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=

View file

@ -1,6 +1,5 @@
{
"zwave-js-server": "ws://home-assistant:3000",
"sqlite-database": "lockserver.db",
"http-bind": ":8080",
"session-secrets": []
"http-bind": ":8080"
}