Skip to content

Commit

Permalink
Merge pull request #32 from pteich/fix-lock-warning
Browse files Browse the repository at this point in the history
Fix lock warning
  • Loading branch information
pteich authored Sep 9, 2024
2 parents dfa3d9a + 3dc2c5c commit d585db3
Show file tree
Hide file tree
Showing 7 changed files with 464 additions and 1,729 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18 AS builder
FROM golang:1.23 AS builder

WORKDIR /workspace
RUN echo 'package main\n\
Expand All @@ -11,7 +11,7 @@ func main() {\n\
caddycmd.Main()\n\
}' > main.go && \
go env -w GOPROXY="https://goproxy.io,direct" && \
go mod init caddy && go get github.com/caddyserver/caddy/v2@v2.5.1 && go get && \
go mod init caddy && go get github.com/pteich/caddy-tlsconsul@fix-lock-warning && go get github.com/caddyserver/caddy/v2@v2.8.4 && go get && \
CGO_ENABLED=0 go build -trimpath -tags netgo -ldflags '-extldflags "-static" -s -w' -o /usr/bin/caddy


Expand Down
22 changes: 11 additions & 11 deletions crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"crypto/cipher"
"crypto/rand"
"encoding/json"
"errors"
"fmt"
"io"

"github.com/pteich/errors"
)

func (cs *ConsulStorage) encrypt(bytes []byte) ([]byte, error) {
Expand All @@ -18,18 +18,18 @@ func (cs *ConsulStorage) encrypt(bytes []byte) ([]byte, error) {

c, err := aes.NewCipher(cs.AESKey)
if err != nil {
return nil, errors.Wrap(err, "unable to create AES cipher")
return nil, fmt.Errorf("unable to create AES cipher: %w", err)
}

gcm, err := cipher.NewGCM(c)
if err != nil {
return nil, errors.Wrap(err, "unable to create GCM cipher")
return nil, fmt.Errorf("unable to create GCM cipher: %w", err)
}

nonce := make([]byte, gcm.NonceSize())
_, err = io.ReadFull(rand.Reader, nonce)
if err != nil {
return nil, errors.Wrap(err, "unable to generate nonce")
return nil, fmt.Errorf("unable to generate nonce: %w", err)
}

return gcm.Seal(nonce, nonce, bytes, nil), nil
Expand All @@ -39,7 +39,7 @@ func (cs *ConsulStorage) EncryptStorageData(data *StorageData) ([]byte, error) {
// JSON marshal, then encrypt if key is there
bytes, err := json.Marshal(data)
if err != nil {
return nil, errors.Wrap(err, "unable to marshal")
return nil, fmt.Errorf("unable to marshal: %w", err)
}

// Prefix with simple prefix and then encrypt
Expand All @@ -58,17 +58,17 @@ func (cs *ConsulStorage) decrypt(bytes []byte) ([]byte, error) {

block, err := aes.NewCipher(cs.AESKey)
if err != nil {
return nil, errors.Wrap(err, "unable to create AES cipher")
return nil, fmt.Errorf("unable to create AES cipher: %w", err)
}

gcm, err := cipher.NewGCM(block)
if err != nil {
return nil, errors.Wrap(err, "unable to create GCM cipher")
return nil, fmt.Errorf("unable to create GCM cipher: %w", err)
}

out, err := gcm.Open(nil, bytes[:gcm.NonceSize()], bytes[gcm.NonceSize():], nil)
if err != nil {
return nil, errors.Wrap(err, "decryption failure")
return nil, fmt.Errorf("decryption failure: %w", err)
}

return out, nil
Expand All @@ -78,7 +78,7 @@ func (cs *ConsulStorage) DecryptStorageData(bytes []byte) (*StorageData, error)
// We have to decrypt if there is an AES key and then JSON unmarshal
bytes, err := cs.decrypt(bytes)
if err != nil {
return nil, errors.Wrap(err, "unable to decrypt data")
return nil, fmt.Errorf("unable to decrypt data: %w", err)
}

// Simple sanity check of the beginning of the byte array just to check
Expand All @@ -89,7 +89,7 @@ func (cs *ConsulStorage) DecryptStorageData(bytes []byte) (*StorageData, error)
// Now just json unmarshal
data := &StorageData{}
if err := json.Unmarshal(bytes[len(cs.ValuePrefix):], data); err != nil {
return nil, errors.Wrap(err, "unable to unmarshal result")
return nil, fmt.Errorf("unable to unmarshal result: %w", err)
}
return data, nil
}
123 changes: 102 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,27 +1,108 @@
module github.com/pteich/caddy-tlsconsul

go 1.16
go 1.22.0

toolchain go1.22.5

require (
github.com/caddyserver/caddy/v2 v2.8.4
github.com/caddyserver/certmagic v0.21.3
github.com/hashicorp/consul/api v1.29.4
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go/modules/consul v0.33.0
go.uber.org/zap v1.27.0
)

require (
github.com/armon/go-metrics v0.4.0 // indirect
github.com/caddyserver/caddy/v2 v2.5.1
github.com/caddyserver/certmagic v0.16.1
github.com/fatih/color v1.13.0 // indirect
github.com/hashicorp/consul/api v1.13.0
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/serf v0.9.8 // indirect
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/miekg/dns v1.1.49 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/caddyserver/zerossl v0.1.3 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/pprof v0.0.0-20240903155634-a8630aee4ab9 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/libdns/libdns v0.2.2 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mholt/acmez/v2 v2.0.2 // indirect
github.com/miekg/dns v1.1.62 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/pteich/errors v1.0.1
github.com/stretchr/testify v1.7.1
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/net v0.0.0-20220531201128-c960675eff93 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/protobuf v1.28.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/onsi/ginkgo/v2 v2.20.2 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/client_golang v1.20.3 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.47.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/testcontainers/testcontainers-go v0.33.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
github.com/zeebo/blake3 v0.2.4 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap/exp v0.2.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.24.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit d585db3

Please sign in to comment.