AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::Crypto::TOTP Struct Reference

#include "TOTP.h"

Public Types

using Secret = std::vector< uint8 >
 

Static Public Member Functions

static uint32 GenerateToken (Secret const &key, time_t timestamp)
 
static bool ValidateToken (Secret const &key, uint32 token)
 

Static Public Attributes

static constexpr size_t RECOMMENDED_SECRET_LENGTH = 20
 

Detailed Description

Member Typedef Documentation

◆ Secret

using Acore::Crypto::TOTP::Secret = std::vector<uint8>

Member Function Documentation

◆ GenerateToken()

uint32 Acore::Crypto::TOTP::GenerateToken ( Secret const &  key,
time_t  timestamp 
)
static
28{
29 timestamp /= TOTP_INTERVAL;
30 unsigned char challenge[8];
31 for (int i = 8; i--; timestamp >>= 8)
32 challenge[i] = timestamp;
33
34 unsigned char digest[HMAC_RESULT_SIZE];
35 uint32 digestSize = HMAC_RESULT_SIZE;
36 HMAC(EVP_sha1(), secret.data(), secret.size(), challenge, 8, digest, &digestSize);
37
38 uint32 offset = digest[19] & 0xF;
39 uint32 truncated = (digest[offset] << 24) | (digest[offset + 1] << 16) | (digest[offset + 2] << 8) | (digest[offset + 3]);
40 truncated &= 0x7FFFFFFF;
41 return (truncated % 1000000);
42}
static constexpr uint32 TOTP_INTERVAL
Definition: TOTP.cpp:24
static constexpr uint32 HMAC_RESULT_SIZE
Definition: TOTP.cpp:25
std::uint32_t uint32
Definition: Define.h:108

References HMAC_RESULT_SIZE, and TOTP_INTERVAL.

◆ ValidateToken()

bool Acore::Crypto::TOTP::ValidateToken ( Secret const &  key,
uint32  token 
)
static
45{
46 time_t now = GetEpochTime().count();
47 return (
48 (token == GenerateToken(secret, now - TOTP_INTERVAL)) ||
49 (token == GenerateToken(secret, now)) ||
50 (token == GenerateToken(secret, now + TOTP_INTERVAL))
51 );
52}
Seconds GetEpochTime()
Definition: Timer.h:141
static uint32 GenerateToken(Secret const &key, time_t timestamp)
Definition: TOTP.cpp:27

References GetEpochTime(), and TOTP_INTERVAL.

Referenced by account_commandscript::HandleAccount2FARemoveCommand(), account_commandscript::HandleAccount2FASetupCommand(), and AuthSession::HandleLogonProof().

Member Data Documentation

◆ RECOMMENDED_SECRET_LENGTH

constexpr std::size_t Acore::Crypto::TOTP::RECOMMENDED_SECRET_LENGTH = 20
staticconstexpr