27#define SECRET_FLAG_FOR(key, val, server) server ## _ ## key = (val ## ull << (16*SECRET_OWNER_ ## server))
28#define SECRET_FLAG(key, val) SECRET_FLAG_ ## key = val, SECRET_FLAG_FOR(key, val, BNETSERVER), SECRET_FLAG_FOR(key, val, WORLDSERVER)
62 std::string str =
sConfigMgr->GetStringDefault(configKey,
"");
69 TC_LOG_FATAL(
"server.loading",
"Invalid value for '{}' - specify a hexadecimal integer of up to {} bits with no prefix.", configKey, bits);
75 if (!((
BigNumber(0) <= secret) && (secret < threshold)))
77 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);
93 std::unique_lock<std::mutex> lock(
_secrets[i].lock);
102 std::unique_lock<std::mutex> lock(
_secrets[i].lock);
118 oldDigest = result->Fetch()->GetString();
124 ((!oldDigest) != (!currentValue)) ||
128 if (info.owner !=
OWNER)
131 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);
133 TC_LOG_MESSAGE_BODY(
"server.loading", errorLevel,
"No value for '{}' specified - please specify the secret currently being used in your auth DB.", info.configKey);
139 if (oldDigest && info.oldKey)
144 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);
154 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());
159 TC_LOG_INFO(
"server.loading",
"Successfully transitioned database to new '{}' value.", info.configKey);
182 Field* fields = result->Fetch();
183 if (fields[1].IsNull())
187 std::vector<uint8> totpSecret = fields[1].
GetBinary();
205 trans->Append(updateStmt);
206 }
while (result->NextRow());
211 return std::string(
"Unknown secret index - huh?");
218 trans->Append(deleteStmt);
227 return std::string(
"Failed to hash new secret");
232 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]
@ SECRET_OWNER_BNETSERVER
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 setBinary(const uint8 index, const std::vector< uint8 > &value)
void setUInt32(const uint8 index, const uint32 value)
void setString(const uint8 index, const std::string &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 Initialize(SecretOwner owner)
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)