mirror of
https://github.com/coredns/coredns.git
synced 2026-08-27 07:07:05 -04:00
Store the normalized key name in the request context only after successful TSIG verification. This lets downstream plugins distinguish unsigned requests from authenticated requests and authorize by key without relying on the stripped TSIG RR or exposing secret material. Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
18 lines
527 B
Go
18 lines
527 B
Go
package tsig
|
|
|
|
import "context"
|
|
|
|
type validatedKeyNameKey struct{}
|
|
|
|
// ValidatedKeyName returns the normalized name of the TSIG key validated by
|
|
// the tsig plugin. The boolean is false for unsigned requests and requests the
|
|
// plugin did not validate.
|
|
func ValidatedKeyName(ctx context.Context) (string, bool) {
|
|
name, ok := ctx.Value(validatedKeyNameKey{}).(string)
|
|
return name, ok
|
|
}
|
|
|
|
func withValidatedKeyName(ctx context.Context, name string) context.Context {
|
|
return context.WithValue(ctx, validatedKeyNameKey{}, name)
|
|
}
|