2019-04-24 21:52:08 +00:00
|
|
|
package handlers
|
|
|
|
|
2021-12-02 02:21:46 +00:00
|
|
|
import (
|
2022-03-02 06:40:26 +00:00
|
|
|
"time"
|
|
|
|
|
2021-12-02 02:21:46 +00:00
|
|
|
"github.com/valyala/fasthttp"
|
|
|
|
)
|
|
|
|
|
2021-07-22 03:52:37 +00:00
|
|
|
const (
|
|
|
|
// ActionTOTPRegistration is the string representation of the action for which the token has been produced.
|
|
|
|
ActionTOTPRegistration = "RegisterTOTPDevice"
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2022-03-03 11:20:43 +00:00
|
|
|
// ActionWebauthnRegistration is the string representation of the action for which the token has been produced.
|
|
|
|
ActionWebauthnRegistration = "RegisterWebauthnDevice"
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2021-07-22 03:52:37 +00:00
|
|
|
// ActionResetPassword is the string representation of the action for which the token has been produced.
|
|
|
|
ActionResetPassword = "ResetPassword"
|
|
|
|
)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2021-12-02 02:21:46 +00:00
|
|
|
var (
|
|
|
|
headerAuthorization = []byte(fasthttp.HeaderAuthorization)
|
|
|
|
headerProxyAuthorization = []byte(fasthttp.HeaderProxyAuthorization)
|
2020-12-01 23:03:44 +00:00
|
|
|
|
2021-12-02 02:21:46 +00:00
|
|
|
headerSessionUsername = []byte("Session-Username")
|
|
|
|
headerRemoteUser = []byte("Remote-User")
|
|
|
|
headerRemoteGroups = []byte("Remote-Groups")
|
|
|
|
headerRemoteName = []byte("Remote-Name")
|
|
|
|
headerRemoteEmail = []byte("Remote-Email")
|
2021-07-22 03:52:37 +00:00
|
|
|
)
|
2019-04-24 21:52:08 +00:00
|
|
|
|
2022-06-14 07:20:13 +00:00
|
|
|
var (
|
2022-07-08 12:18:52 +00:00
|
|
|
headerContentTypeValueTextPlain = []byte("text/plain; charset=utf-8")
|
2022-06-14 07:20:13 +00:00
|
|
|
)
|
|
|
|
|
2019-04-24 21:52:08 +00:00
|
|
|
const (
|
2020-04-20 21:03:38 +00:00
|
|
|
// Forbidden means the user is forbidden the access to a resource.
|
2019-04-24 21:52:08 +00:00
|
|
|
Forbidden authorizationMatching = iota
|
|
|
|
// NotAuthorized means the user can access the resource with more permissions.
|
|
|
|
NotAuthorized authorizationMatching = iota
|
|
|
|
// Authorized means the user is authorized given her current permissions.
|
|
|
|
Authorized authorizationMatching = iota
|
|
|
|
)
|
|
|
|
|
2021-07-22 03:52:37 +00:00
|
|
|
const (
|
|
|
|
messageOperationFailed = "Operation failed."
|
|
|
|
messageAuthenticationFailed = "Authentication failed. Check your credentials."
|
|
|
|
messageUnableToRegisterOneTimePassword = "Unable to set up one-time passwords." //nolint:gosec
|
|
|
|
messageUnableToRegisterSecurityKey = "Unable to register your security key."
|
|
|
|
messageUnableToResetPassword = "Unable to reset your password."
|
|
|
|
messageMFAValidationFailed = "Authentication failed, please retry later."
|
2022-04-02 22:32:57 +00:00
|
|
|
messagePasswordWeak = "Your supplied password does not meet the password policy requirements"
|
2021-07-22 03:52:37 +00:00
|
|
|
)
|
2020-11-27 09:59:22 +00:00
|
|
|
|
2021-11-29 03:09:14 +00:00
|
|
|
const (
|
|
|
|
logFmtErrParseRequestBody = "Failed to parse %s request body: %+v"
|
|
|
|
logFmtErrWriteResponseBody = "Failed to write %s response body for user '%s': %+v"
|
|
|
|
logFmtErrRegulationFail = "Failed to perform %s authentication regulation for user '%s': %+v"
|
|
|
|
logFmtErrSessionRegenerate = "Could not regenerate session during %s authentication for user '%s': %+v"
|
|
|
|
logFmtErrSessionReset = "Could not reset session during %s authentication for user '%s': %+v"
|
|
|
|
logFmtErrSessionSave = "Could not save session with the %s during %s authentication for user '%s': %+v"
|
|
|
|
logFmtErrObtainProfileDetails = "Could not obtain profile details during %s authentication for user '%s': %+v"
|
|
|
|
logFmtTraceProfileDetails = "Profile details for user '%s' => groups: %s, emails %s"
|
|
|
|
)
|
|
|
|
|
2021-07-22 03:52:37 +00:00
|
|
|
const (
|
2022-03-02 06:40:26 +00:00
|
|
|
testInactivity = time.Second * 10
|
2021-07-22 03:52:37 +00:00
|
|
|
testRedirectionURL = "http://redirection.local"
|
|
|
|
testUsername = "john"
|
|
|
|
)
|
2020-05-20 22:03:15 +00:00
|
|
|
|
2021-12-01 03:32:58 +00:00
|
|
|
// Duo constants.
|
|
|
|
const (
|
|
|
|
allow = "allow"
|
|
|
|
deny = "deny"
|
|
|
|
enroll = "enroll"
|
|
|
|
auth = "auth"
|
|
|
|
)
|
|
|
|
|
2021-05-04 22:06:05 +00:00
|
|
|
const (
|
|
|
|
accept = "accept"
|
|
|
|
reject = "reject"
|
|
|
|
)
|
2021-07-22 03:52:37 +00:00
|
|
|
|
|
|
|
const authPrefix = "Basic "
|
|
|
|
|
|
|
|
const ldapPasswordComplexityCode = "0000052D."
|
|
|
|
|
|
|
|
var ldapPasswordComplexityCodes = []string{
|
|
|
|
"0000052D", "SynoNumber", "SynoMixedCase", "SynoExcludeNameDesc", "SynoSpecialChar",
|
|
|
|
}
|
|
|
|
|
|
|
|
var ldapPasswordComplexityErrors = []string{
|
|
|
|
"LDAP Result Code 19 \"Constraint Violation\": Password fails quality checking policy",
|
|
|
|
"LDAP Result Code 19 \"Constraint Violation\": Password is too young to change",
|
|
|
|
}
|