MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / verifySource

Function verifySource

pkg/auth/cluster/cluster.go:58–77  ·  view source on GitHub ↗
(ctx context.Context, validKeys [][]byte)

Source from the content-addressed store, hash-verified

56}
57
58func verifySource(ctx context.Context, validKeys [][]byte) error {
59 md := rpcmetadata.FromIncomingContext(ctx)
60 switch md.AuthType {
61 case AuthType:
62 case "":
63 return errNoClusterKey.New()
64 default:
65 return errUnsupportedAuthType.WithAttributes("auth_type", md.AuthType)
66 }
67 key, err := hex.DecodeString(md.AuthValue)
68 if err != nil {
69 return errInvalidClusterKey.WithCause(err)
70 }
71 for _, acceptedKey := range validKeys {
72 if subtle.ConstantTimeCompare(acceptedKey, key) == 1 {
73 return nil
74 }
75 }
76 return errInvalidClusterKey.New()
77}
78
79// Authorized returns whether the context has been identified as a cluster call.
80// It panics if it does not inherit from `NewContext`.

Callers 1

VerifySourceFunction · 0.85

Calls 4

FromIncomingContextFunction · 0.92
NewMethod · 0.65
WithAttributesMethod · 0.45
WithCauseMethod · 0.45

Tested by

no test coverage detected