2019-11-17 02:50:58 +07:00
|
|
|
package storage
|
|
|
|
|
2020-07-16 12:56:08 +07:00
|
|
|
import (
|
2021-11-23 16:45:38 +07:00
|
|
|
"regexp"
|
2020-07-16 12:56:08 +07:00
|
|
|
)
|
|
|
|
|
2021-11-23 16:45:38 +07:00
|
|
|
const (
|
2022-04-07 12:33:53 +07:00
|
|
|
tableAuthenticationLogs = "authentication_logs"
|
|
|
|
tableDuoDevices = "duo_devices"
|
2021-11-30 13:58:21 +07:00
|
|
|
tableIdentityVerification = "identity_verification"
|
2021-11-23 16:45:38 +07:00
|
|
|
tableTOTPConfigurations = "totp_configurations"
|
2022-04-07 12:33:53 +07:00
|
|
|
tableUserOpaqueIdentifier = "user_opaque_identifier"
|
|
|
|
tableUserPreferences = "user_preferences"
|
2022-03-03 18:20:43 +07:00
|
|
|
tableWebauthnDevices = "webauthn_devices"
|
2022-04-07 12:33:53 +07:00
|
|
|
|
|
|
|
tableOAuth2ConsentSession = "oauth2_consent_session"
|
|
|
|
tableOAuth2AuthorizeCodeSession = "oauth2_authorization_code_session"
|
|
|
|
tableOAuth2AccessTokenSession = "oauth2_access_token_session" //nolint:gosec // This is not a hardcoded credential.
|
|
|
|
tableOAuth2RefreshTokenSession = "oauth2_refresh_token_session" //nolint:gosec // This is not a hardcoded credential.
|
|
|
|
tableOAuth2PKCERequestSession = "oauth2_pkce_request_session"
|
|
|
|
tableOAuth2OpenIDConnectSession = "oauth2_openid_connect_session"
|
|
|
|
tableOAuth2BlacklistedJTI = "oauth2_blacklisted_jti"
|
|
|
|
|
|
|
|
tableMigrations = "migrations"
|
|
|
|
tableEncryption = "encryption"
|
2021-11-23 16:45:38 +07:00
|
|
|
|
|
|
|
tablePrefixBackup = "_bkp_"
|
|
|
|
)
|
|
|
|
|
2022-04-07 12:33:53 +07:00
|
|
|
// OAuth2SessionType represents the potential OAuth 2.0 session types.
|
|
|
|
type OAuth2SessionType string
|
|
|
|
|
|
|
|
// Representation of specific OAuth 2.0 session types.
|
|
|
|
const (
|
|
|
|
OAuth2SessionTypeAuthorizeCode OAuth2SessionType = "authorization code"
|
|
|
|
OAuth2SessionTypeAccessToken OAuth2SessionType = "access token"
|
|
|
|
OAuth2SessionTypeRefreshToken OAuth2SessionType = "refresh token"
|
|
|
|
OAuth2SessionTypePKCEChallenge OAuth2SessionType = "pkce challenge"
|
|
|
|
OAuth2SessionTypeOpenIDConnect OAuth2SessionType = "openid connect"
|
|
|
|
)
|
|
|
|
|
2021-11-25 08:56:58 +07:00
|
|
|
const (
|
|
|
|
encryptionNameCheck = "check"
|
|
|
|
)
|
|
|
|
|
2021-11-23 16:45:38 +07:00
|
|
|
// WARNING: Do not change/remove these consts. They are used for Pre1 migrations.
|
|
|
|
const (
|
2021-12-03 07:04:11 +07:00
|
|
|
tablePre1TOTPSecrets = "totp_secrets"
|
|
|
|
tablePre1IdentityVerificationTokens = "identity_verification_tokens"
|
2022-03-03 18:20:43 +07:00
|
|
|
tablePre1U2FDevices = "u2f_devices"
|
2021-12-03 07:04:11 +07:00
|
|
|
|
|
|
|
tablePre1Config = "config"
|
|
|
|
|
2021-11-23 16:45:38 +07:00
|
|
|
tableAlphaAuthenticationLogs = "AuthenticationLogs"
|
|
|
|
tableAlphaIdentityVerificationTokens = "IdentityVerificationTokens"
|
|
|
|
tableAlphaPreferences = "Preferences"
|
|
|
|
tableAlphaPreferencesTableName = "PreferencesTableName"
|
|
|
|
tableAlphaSecondFactorPreferences = "SecondFactorPreferences"
|
|
|
|
tableAlphaTOTPSecrets = "TOTPSecrets"
|
|
|
|
tableAlphaU2FDeviceHandles = "U2FDeviceHandles"
|
|
|
|
)
|
|
|
|
|
2021-12-03 07:04:11 +07:00
|
|
|
var tablesPre1 = []string{
|
|
|
|
tablePre1TOTPSecrets,
|
|
|
|
tablePre1IdentityVerificationTokens,
|
2022-03-03 18:20:43 +07:00
|
|
|
tablePre1U2FDevices,
|
2021-12-03 07:04:11 +07:00
|
|
|
|
|
|
|
tableUserPreferences,
|
|
|
|
tableAuthenticationLogs,
|
|
|
|
}
|
|
|
|
|
2021-11-23 16:45:38 +07:00
|
|
|
const (
|
|
|
|
providerAll = "all"
|
|
|
|
providerMySQL = "mysql"
|
|
|
|
providerPostgres = "postgres"
|
|
|
|
providerSQLite = "sqlite"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// This is the latest schema version for the purpose of tests.
|
2022-04-25 07:31:05 +07:00
|
|
|
testLatestVersion = 5
|
2021-11-23 16:45:38 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// SchemaLatest represents the value expected for a "migrate to latest" migration. It's the maximum 32bit signed integer.
|
|
|
|
SchemaLatest = 2147483647
|
|
|
|
)
|
|
|
|
|
2022-04-07 12:33:53 +07:00
|
|
|
type ctxKey int
|
|
|
|
|
|
|
|
const (
|
|
|
|
ctxKeyTransaction ctxKey = iota
|
|
|
|
)
|
|
|
|
|
2021-11-23 16:45:38 +07:00
|
|
|
var (
|
|
|
|
reMigration = regexp.MustCompile(`^V(\d{4})\.([^.]+)\.(all|sqlite|postgres|mysql)\.(up|down)\.sql$`)
|
|
|
|
)
|