2022-03-03 11:20:43 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
|
|
|
"github.com/authelia/authelia/v4/internal/utils"
|
|
|
|
)
|
|
|
|
|
2023-04-11 04:40:09 +00:00
|
|
|
// ValidateWebAuthn validates and update WebAuthn configuration.
|
|
|
|
func ValidateWebAuthn(config *schema.Configuration, validator *schema.StructValidator) {
|
|
|
|
if config.WebAuthn.DisplayName == "" {
|
|
|
|
config.WebAuthn.DisplayName = schema.DefaultWebAuthnConfiguration.DisplayName
|
2022-03-03 11:20:43 +00:00
|
|
|
}
|
|
|
|
|
2023-04-11 04:40:09 +00:00
|
|
|
if config.WebAuthn.Timeout <= 0 {
|
|
|
|
config.WebAuthn.Timeout = schema.DefaultWebAuthnConfiguration.Timeout
|
2022-03-03 11:20:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
2023-04-11 04:40:09 +00:00
|
|
|
case config.WebAuthn.ConveyancePreference == "":
|
|
|
|
config.WebAuthn.ConveyancePreference = schema.DefaultWebAuthnConfiguration.ConveyancePreference
|
|
|
|
case !utils.IsStringInSlice(string(config.WebAuthn.ConveyancePreference), validWebAuthnConveyancePreferences):
|
2023-04-14 10:58:49 +00:00
|
|
|
validator.Push(fmt.Errorf(errFmtWebAuthnConveyancePreference, strJoinOr(validWebAuthnConveyancePreferences), config.WebAuthn.ConveyancePreference))
|
2022-03-03 11:20:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
2023-04-11 04:40:09 +00:00
|
|
|
case config.WebAuthn.UserVerification == "":
|
|
|
|
config.WebAuthn.UserVerification = schema.DefaultWebAuthnConfiguration.UserVerification
|
|
|
|
case !utils.IsStringInSlice(string(config.WebAuthn.UserVerification), validWebAuthnUserVerificationRequirement):
|
2023-04-14 10:58:49 +00:00
|
|
|
validator.Push(fmt.Errorf(errFmtWebAuthnUserVerification, strJoinOr(validWebAuthnConveyancePreferences), config.WebAuthn.UserVerification))
|
2022-03-03 11:20:43 +00:00
|
|
|
}
|
|
|
|
}
|