28#include <unordered_map>
30#define SECRET_FLAG_FOR(key, val, server) server ## _ ## key = (val ## ull << (16*SERVER_PROCESS_ ## server))
31#define SECRET_FLAG(key, val) SECRET_FLAG_ ## key = val, SECRET_FLAG_FOR(key, val, AUTHSERVER), SECRET_FLAG_FOR(key, val, WORLDSERVER)
63 std::string str =
sConfigMgr->GetStringDefault(configKey,
"");
70 TC_LOG_FATAL(
"server.loading",
"Invalid value for '{}' - specify a hexadecimal integer of up to {} bits with no prefix.", configKey, bits);
76 if (!((
BigNumber(0) <= secret) && (secret < threshold)))
78 TC_LOG_ERROR(
"server.loading",
"Value for '{}' is out of bounds (should be an integer of up to {} bits with no prefix). Truncated to {} bits.", configKey, bits, bits);
92 std::unique_lock<std::mutex> lock(
_secrets[i].lock);
101 std::unique_lock<std::mutex> lock(
_secrets[i].lock);
117 oldDigest = result->Fetch()->GetString();
123 ((!oldDigest) != (!currentValue)) ||
130 TC_LOG_MESSAGE_BODY(
"server.loading", errorLevel,
"Invalid value for '{}' specified - this is not actually the secret being used in your auth DB.", info.configKey);
132 TC_LOG_MESSAGE_BODY(
"server.loading", errorLevel,
"No value for '{}' specified - please specify the secret currently being used in your auth DB.", info.configKey);
138 if (oldDigest && info.oldKey)
143 TC_LOG_MESSAGE_BODY(
"server.loading", errorLevel,
"Invalid value for '{}' specified - this is not actually the secret previously used in your auth DB.", info.oldKey);
153 TC_LOG_MESSAGE_BODY(
"server.loading", errorLevel,
"Your value of '{}' changed, but we cannot transition your database to the new value:\n{}", info.configKey, error->c_str());
158 TC_LOG_INFO(
"server.loading",
"Successfully transitioned database to new '{}' value.", info.configKey);
181 Field* fields = result->Fetch();
182 if (fields[1].IsNull())
186 std::vector<uint8> totpSecret = fields[1].
GetBinary();
204 trans->Append(updateStmt);
205 }
while (result->NextRow());
210 return std::string(
"Unknown secret index - huh?");
217 trans->Append(deleteStmt);
226 return std::string(
"Failed to hash new secret");
231 trans->Append(insertStmt);
SQLTransaction< LoginDatabaseConnection > LoginDatabaseTransaction
std::shared_ptr< ResultSet > QueryResult
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
#define TC_LOG_ERROR(filterType__,...)
#define TC_LOG_MESSAGE_BODY(filterType__, level__,...)
#define TC_LOG_INFO(filterType__,...)
#define TC_LOG_FATAL(filterType__,...)
@ LOGIN_UPD_ACCOUNT_TOTP_SECRET
@ LOGIN_SEL_SECRET_DIGEST
@ LOGIN_INS_SECRET_DIGEST
@ LOGIN_DEL_SECRET_DIGEST
std::optional< T > Optional
Optional helper class to wrap optional values within.
static Optional< BigNumber > GetHexFromConfig(char const *configKey, int bits)
#define SECRET_FLAG(key, val)
static constexpr SecretInfo secret_info[NUM_SECRETS]
#define THIS_SERVER_PROCESS
@ SERVER_PROCESS_AUTHSERVER
void SetRand(int32 numbits)
bool SetHexStr(char const *str)
Class used to access individual fields of database query result.
std::vector< uint8 > GetBinary() const
void setUInt32(uint8 index, uint32 value)
void setBinary(uint8 index, std::vector< uint8 > const &value)
void setString(uint8 index, std::string const &value)
std::array< Secret, NUM_SECRETS > _secrets
static SecretMgr * instance()
Optional< std::string > AttemptTransition(Secrets i, Optional< BigNumber > const &newSecret, Optional< BigNumber > const &oldSecret, bool hadOldSecret) const
void AttemptLoad(Secrets i, LogLevel errorLevel, std::unique_lock< std::mutex > const &)
Secret const & GetSecret(Secrets i)
static constexpr size_t KEY_SIZE_BYTES
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
static Optional< std::string > Hash(std::string const &password, BigNumber const &salt, uint32 nIterations=DEFAULT_ITERATIONS, uint32 kibMemoryCost=DEFAULT_MEMORY_COST)
static bool Verify(std::string const &password, std::string const &hash)