Skip to content

Commit

Permalink
util: Rename import to mtls
Browse files Browse the repository at this point in the history
  • Loading branch information
johanstokking committed Jun 20, 2024
1 parent 5478f3b commit 547f977
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"syscall"

"go.opentelemetry.io/otel/trace"
mtlsauth "go.thethings.network/lorawan-stack/v3/pkg/auth/mtls"
"go.thethings.network/lorawan-stack/v3/pkg/auth/mtls"
"go.thethings.network/lorawan-stack/v3/pkg/auth/rights"
"go.thethings.network/lorawan-stack/v3/pkg/cluster"
"go.thethings.network/lorawan-stack/v3/pkg/config"
Expand Down Expand Up @@ -97,7 +97,7 @@ type Component struct {
taskStarter task.Starter
taskConfigs []*task.Config

caStore *mtlsauth.CAStore
caStore *mtls.CAStore

limiter ratelimit.Interface
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func New(logger log.Stack, config *Config, opts ...Option) (c *Component, err er
if err != nil {
return nil, err
}
c.caStore, err = mtlsauth.NewCAStore(ctx, caStoreFetcher)
c.caStore, err = mtls.NewCAStore(ctx, caStoreFetcher)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -455,6 +455,6 @@ func (c *Component) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

// CAStore returns the component's CA Store.
func (c *Component) CAStore() *mtlsauth.CAStore {
func (c *Component) CAStore() *mtls.CAStore {
return c.caStore
}
8 changes: 4 additions & 4 deletions pkg/gatewayserver/gatewayserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"time"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
mtlsauth "go.thethings.network/lorawan-stack/v3/pkg/auth/mtls"
"go.thethings.network/lorawan-stack/v3/pkg/auth/mtls"
"go.thethings.network/lorawan-stack/v3/pkg/cluster"
"go.thethings.network/lorawan-stack/v3/pkg/component"
"go.thethings.network/lorawan-stack/v3/pkg/config"
Expand Down Expand Up @@ -113,7 +113,7 @@ func (gs *GatewayServer) Context() context.Context {

// CertificateVerifier abstracts certificate verification functions.
type CertificateVerifier interface {
Verify(ctx context.Context, clientType mtlsauth.ClientType, cn string, cert *x509.Certificate) error
Verify(ctx context.Context, clientType mtls.ClientType, cn string, cert *x509.Certificate) error
}

var (
Expand Down Expand Up @@ -439,9 +439,9 @@ func (gs *GatewayServer) FillGatewayContext(ctx context.Context, ids *ttnpb.Gate
return nil, nil, err
}
}
if cert := mtlsauth.ClientCertificateFromContext(ctx); cert != nil {
if cert := mtls.ClientCertificateFromContext(ctx); cert != nil {
// Verify the client certificate.
err := gs.certVerifier.Verify(ctx, mtlsauth.ClientTypeGateway, types.MustEUI64(ids.Eui).String(), cert)
err := gs.certVerifier.Verify(ctx, mtls.ClientTypeGateway, types.MustEUI64(ids.Eui).String(), cert)
if err != nil {
return nil, nil, errUnauthenticatedGatewayConnection.WithCause(err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/rpcmiddleware/proxy_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
mtlsauth "go.thethings.network/lorawan-stack/v3/pkg/auth/mtls"
"go.thethings.network/lorawan-stack/v3/pkg/auth/mtls"
"go.thethings.network/lorawan-stack/v3/pkg/log"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -126,10 +126,10 @@ func (h *ProxyHeaders) intercept(ctx context.Context) (context.Context, metadata
if forwardedFor != "" {
md.Set(headerXRealIP, strings.TrimSpace(strings.Split(forwardedFor, ",")[0]))
}
if cert, ok, err := mtlsauth.FromProxyHeaders(getLastFromMD(md)); err != nil {
if cert, ok, err := mtls.FromProxyHeaders(getLastFromMD(md)); err != nil {
log.FromContext(ctx).WithError(err).Warn("Failed to parse client certificate from proxy headers")
} else if ok {
ctx = mtlsauth.NewContextWithClientCertificate(ctx, cert)
ctx = mtls.NewContextWithClientCertificate(ctx, cert)
}
} else {
// We don't trust the proxy, remove its headers.
Expand Down
6 changes: 3 additions & 3 deletions pkg/webmiddleware/proxy_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"regexp"
"strings"

mtlsauth "go.thethings.network/lorawan-stack/v3/pkg/auth/mtls"
"go.thethings.network/lorawan-stack/v3/pkg/auth/mtls"
"go.thethings.network/lorawan-stack/v3/pkg/log"
)

Expand Down Expand Up @@ -103,10 +103,10 @@ func ProxyHeaders(config ProxyConfiguration) MiddlewareFunc {
if forwardedHost != "" {
r.URL.Host = forwardedHost
}
if cert, ok, err := mtlsauth.FromProxyHeaders(r.Header); err != nil {
if cert, ok, err := mtls.FromProxyHeaders(r.Header); err != nil {
log.FromContext(ctx).WithError(err).Warn("Failed to parse client certificate from proxy headers")
} else if ok {
ctx = mtlsauth.NewContextWithClientCertificate(ctx, cert)
ctx = mtls.NewContextWithClientCertificate(ctx, cert)
}
} else {
// We don't trust the proxy, remove its headers.
Expand Down

0 comments on commit 547f977

Please sign in to comment.