2024-09-08 12:06:14 +02:00
|
|
|
package auth
|
|
|
|
|
2024-09-11 16:20:30 +02:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
auth "github.com/netbirdio/netbird/relay/auth/hmac"
|
|
|
|
authv2 "github.com/netbirdio/netbird/relay/auth/hmac/v2"
|
|
|
|
)
|
2024-09-08 12:06:14 +02:00
|
|
|
|
|
|
|
// Validator is an interface that defines the Validate method.
|
|
|
|
type Validator interface {
|
2024-09-11 16:20:30 +02:00
|
|
|
Validate(any) error
|
|
|
|
// Deprecated: Use Validate instead.
|
|
|
|
ValidateHelloMsgType(any) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type TimedHMACValidator struct {
|
|
|
|
authenticatorV2 *authv2.Validator
|
|
|
|
authenticator *auth.TimedHMACValidator
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTimedHMACValidator(secret []byte, duration time.Duration) *TimedHMACValidator {
|
|
|
|
return &TimedHMACValidator{
|
|
|
|
authenticatorV2: authv2.NewValidator(secret),
|
|
|
|
authenticator: auth.NewTimedHMACValidator(string(secret), duration),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *TimedHMACValidator) Validate(credentials any) error {
|
|
|
|
return a.authenticatorV2.Validate(credentials)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *TimedHMACValidator) ValidateHelloMsgType(credentials any) error {
|
|
|
|
return a.authenticator.Validate(credentials)
|
2024-09-08 12:06:14 +02:00
|
|
|
}
|