2019-04-25 04:52:08 +07:00
|
|
|
package authentication
|
|
|
|
|
2020-05-05 02:39:25 +07:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
2020-04-21 04:03:38 +07:00
|
|
|
// Level is the type representing a level of authentication.
|
2019-04-25 04:52:08 +07:00
|
|
|
type Level int
|
|
|
|
|
|
|
|
const (
|
2020-04-21 04:03:38 +07:00
|
|
|
// NotAuthenticated if the user is not authenticated yet.
|
2019-04-25 04:52:08 +07:00
|
|
|
NotAuthenticated Level = iota
|
2020-04-21 04:03:38 +07:00
|
|
|
// OneFactor if the user has passed first factor only.
|
2019-04-25 04:52:08 +07:00
|
|
|
OneFactor Level = iota
|
2020-04-21 04:03:38 +07:00
|
|
|
// TwoFactor if the user has passed two factors.
|
2019-04-25 04:52:08 +07:00
|
|
|
TwoFactor Level = iota
|
|
|
|
)
|
|
|
|
|
2021-07-02 06:16:16 +07:00
|
|
|
const (
|
|
|
|
ldapSupportedExtensionAttribute = "supportedExtension"
|
2022-05-10 11:38:36 +07: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-02 06:16:16 +07:00
|
|
|
)
|
|
|
|
|
2022-05-02 08:51:38 +07:00
|
|
|
const (
|
|
|
|
ldapAttributeUnicodePwd = "unicodePwd"
|
|
|
|
ldapAttributeUserPassword = "userPassword"
|
|
|
|
)
|
|
|
|
|
2021-08-05 11:17:07 +07:00
|
|
|
const (
|
|
|
|
ldapPlaceholderInput = "{input}"
|
|
|
|
ldapPlaceholderDistinguishedName = "{dn}"
|
|
|
|
ldapPlaceholderUsername = "{username}"
|
|
|
|
)
|
|
|
|
|
2022-05-10 11:38:36 +07:00
|
|
|
const (
|
|
|
|
none = "none"
|
|
|
|
)
|
|
|
|
|
2020-05-03 11:06:09 +07:00
|
|
|
// CryptAlgo the crypt representation of an algorithm used in the prefix of the hash.
|
|
|
|
type CryptAlgo string
|
|
|
|
|
2020-03-06 08:38:02 +07:00
|
|
|
const (
|
2020-04-21 04:03:38 +07:00
|
|
|
// HashingAlgorithmArgon2id Argon2id hash identifier.
|
2020-05-06 07:52:06 +07:00
|
|
|
HashingAlgorithmArgon2id CryptAlgo = argon2id
|
2020-04-21 04:03:38 +07:00
|
|
|
// HashingAlgorithmSHA512 SHA512 hash identifier.
|
2020-05-03 11:06:09 +07:00
|
|
|
HashingAlgorithmSHA512 CryptAlgo = "6"
|
2020-03-06 08:38:02 +07:00
|
|
|
)
|
|
|
|
|
2020-04-21 04:03:38 +07:00
|
|
|
// These are the default values from the upstream crypt module we use them to for GetInt
|
|
|
|
// and they need to be checked when updating github.com/simia-tech/crypt.
|
2020-03-06 08:38:02 +07:00
|
|
|
const (
|
|
|
|
HashingDefaultArgon2idTime = 1
|
|
|
|
HashingDefaultArgon2idMemory = 32 * 1024
|
|
|
|
HashingDefaultArgon2idParallelism = 4
|
|
|
|
HashingDefaultArgon2idKeyLength = 32
|
|
|
|
HashingDefaultSHA512Iterations = 5000
|
|
|
|
)
|
|
|
|
|
2020-04-21 04:03:38 +07:00
|
|
|
// HashingPossibleSaltCharacters represents valid hashing runes.
|
2021-11-11 16:13:32 +07:00
|
|
|
var HashingPossibleSaltCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/"
|
2020-05-02 23:20:40 +07:00
|
|
|
|
2020-05-05 02:39:25 +07:00
|
|
|
// ErrUserNotFound indicates the user wasn't found in the authentication backend.
|
|
|
|
var ErrUserNotFound = errors.New("user not found")
|
|
|
|
|
2020-05-06 07:52:06 +07:00
|
|
|
const argon2id = "argon2id"
|
2020-05-02 23:20:40 +07:00
|
|
|
const sha512 = "sha512"
|
|
|
|
|
|
|
|
const testPassword = "my;secure*password"
|
2020-05-08 10:38:22 +07:00
|
|
|
|
|
|
|
const fileAuthenticationMode = 0600
|
2020-12-03 12:23:52 +07:00
|
|
|
|
|
|
|
// OWASP recommends to escape some special characters.
|
|
|
|
// https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/LDAP_Injection_Prevention_Cheat_Sheet.md
|
|
|
|
const specialLDAPRunes = ",#+<>;\"="
|