2019-04-24 21:52:08 +00:00
|
|
|
package authentication
|
|
|
|
|
2020-05-04 19:39:25 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2020-04-20 21:03:38 +00:00
|
|
|
// Level is the type representing a level of authentication.
|
2019-04-24 21:52:08 +00:00
|
|
|
type Level int
|
|
|
|
|
|
|
|
const (
|
2020-04-20 21:03:38 +00:00
|
|
|
// NotAuthenticated if the user is not authenticated yet.
|
2019-04-24 21:52:08 +00:00
|
|
|
NotAuthenticated Level = iota
|
2020-04-20 21:03:38 +00:00
|
|
|
// OneFactor if the user has passed first factor only.
|
2022-07-26 05:43:39 +00:00
|
|
|
OneFactor
|
2020-04-20 21:03:38 +00:00
|
|
|
// TwoFactor if the user has passed two factors.
|
2022-07-26 05:43:39 +00:00
|
|
|
TwoFactor
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
2021-07-01 23:16:16 +00:00
|
|
|
const (
|
|
|
|
ldapSupportedExtensionAttribute = "supportedExtension"
|
2022-05-10 04:38:36 +00:00
|
|
|
|
|
|
|
// LDAP Extension OID: Password Modify Extended Operation.
|
|
|
|
//
|
|
|
|
// RFC3062: https://datatracker.ietf.org/doc/html/rfc3062
|
|
|
|
//
|
|
|
|
// OID Reference: http://oidref.com/1.3.6.1.4.1.4203.1.11.1
|
|
|
|
//
|
|
|
|
// See the linked documents for more information.
|
|
|
|
ldapOIDExtensionPwdModifyExOp = "1.3.6.1.4.1.4203.1.11.1"
|
|
|
|
|
|
|
|
// LDAP Extension OID: Transport Layer Security.
|
|
|
|
//
|
|
|
|
// RFC2830: https://datatracker.ietf.org/doc/html/rfc2830
|
|
|
|
//
|
|
|
|
// OID Reference: https://oidref.com/1.3.6.1.4.1.1466.20037
|
|
|
|
//
|
|
|
|
// See the linked documents for more information.
|
|
|
|
ldapOIDExtensionTLS = "1.3.6.1.4.1.1466.20037"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ldapSupportedControlAttribute = "supportedControl"
|
|
|
|
|
|
|
|
// LDAP Control OID: Microsoft Password Policy Hints.
|
|
|
|
//
|
|
|
|
// MS ADTS: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/4add7bce-e502-4e0f-9d69-1a3f153713e2
|
|
|
|
//
|
|
|
|
// OID Reference: https://oidref.com/1.2.840.113556.1.4.2239
|
|
|
|
//
|
|
|
|
// See the linked documents for more information.
|
|
|
|
ldapOIDControlMsftServerPolicyHints = "1.2.840.113556.1.4.2239"
|
|
|
|
|
|
|
|
// LDAP Control OID: Microsoft Password Policy Hints (deprecated).
|
|
|
|
//
|
|
|
|
// MS ADTS: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/49751d58-8115-4277-8faf-64c83a5f658f
|
|
|
|
//
|
|
|
|
// OID Reference: https://oidref.com/1.2.840.113556.1.4.2066
|
|
|
|
//
|
|
|
|
// See the linked documents for more information.
|
|
|
|
ldapOIDControlMsftServerPolicyHintsDeprecated = "1.2.840.113556.1.4.2066"
|
2021-07-01 23:16:16 +00:00
|
|
|
)
|
|
|
|
|
2022-05-02 01:51:38 +00:00
|
|
|
const (
|
|
|
|
ldapAttributeUnicodePwd = "unicodePwd"
|
|
|
|
ldapAttributeUserPassword = "userPassword"
|
|
|
|
)
|
|
|
|
|
2022-10-17 10:51:59 +00:00
|
|
|
const (
|
|
|
|
ldapBaseObjectFilter = "(objectClass=*)"
|
|
|
|
)
|
|
|
|
|
2021-08-05 04:17:07 +00:00
|
|
|
const (
|
2022-12-21 10:31:21 +00:00
|
|
|
ldapPlaceholderInput = "{input}"
|
|
|
|
ldapPlaceholderDistinguishedName = "{dn}"
|
|
|
|
ldapPlaceholderUsername = "{username}"
|
|
|
|
ldapPlaceholderDateTimeGeneralized = "{date-time:generalized}"
|
2022-12-22 00:39:59 +00:00
|
|
|
ldapPlaceholderDateTimeMicrosoftNTTimeEpoch = "{date-time:microsoft-nt}"
|
|
|
|
ldapPlaceholderDateTimeUnixEpoch = "{date-time:unix}"
|
2022-12-21 10:31:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ldapGeneralizedTimeDateTimeFormat = "20060102150405.0Z"
|
2021-08-05 04:17:07 +00:00
|
|
|
)
|
|
|
|
|
2022-05-10 04:38:36 +00:00
|
|
|
const (
|
|
|
|
none = "none"
|
|
|
|
)
|
|
|
|
|
2020-03-06 01:38:02 +00:00
|
|
|
const (
|
2022-10-17 10:51:59 +00:00
|
|
|
hashArgon2 = "argon2"
|
|
|
|
hashSHA2Crypt = "sha2crypt"
|
|
|
|
hashPBKDF2 = "pbkdf2"
|
|
|
|
hashSCrypt = "scrypt"
|
|
|
|
hashBCrypt = "bcrypt"
|
2020-03-06 01:38:02 +00:00
|
|
|
)
|
|
|
|
|
2022-10-17 11:31:23 +00:00
|
|
|
var (
|
|
|
|
// ErrUserNotFound indicates the user wasn't found in the authentication backend.
|
|
|
|
ErrUserNotFound = errors.New("user not found")
|
|
|
|
|
|
|
|
// ErrNoContent is returned when the file is empty.
|
|
|
|
ErrNoContent = errors.New("no file content")
|
|
|
|
)
|
2020-05-04 19:39:25 +00:00
|
|
|
|
2020-05-08 03:38:22 +00:00
|
|
|
const fileAuthenticationMode = 0600
|
2020-12-03 05:23:52 +00:00
|
|
|
|
|
|
|
// OWASP recommends to escape some special characters.
|
|
|
|
// https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/LDAP_Injection_Prevention_Cheat_Sheet.md
|
|
|
|
const specialLDAPRunes = ",#+<>;\"="
|