mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 09:17:18 +00:00
Core: feature add 2FA (OTP) (#1054)
Add 2 factor authentification for improved security on your websites/apps. Taken from TrinityCore Closes #1049 on github.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "RealmList.h"
|
||||
#include "AuthSocket.h"
|
||||
#include "AuthCodes.h"
|
||||
#include "TOTP.h"
|
||||
#include "SHA1.h"
|
||||
#include "openssl/crypto.h"
|
||||
|
||||
@@ -532,6 +533,12 @@ bool AuthSocket::_HandleLogonChallenge()
|
||||
pkt.append(s.AsByteArray().get(), s.GetNumBytes()); // 32 bytes
|
||||
pkt.append(unk3.AsByteArray(16).get(), 16);
|
||||
uint8 securityFlags = 0;
|
||||
|
||||
// Check if token is used
|
||||
_tokenKey = fields[8].GetString();
|
||||
if (!_tokenKey.empty())
|
||||
securityFlags = 4;
|
||||
|
||||
pkt << uint8(securityFlags); // security flags (0x0...0x04)
|
||||
|
||||
if (securityFlags & 0x01) // PIN input
|
||||
@@ -704,6 +711,25 @@ bool AuthSocket::_HandleLogonProof()
|
||||
sha.UpdateBigNumbers(&A, &M, &K, NULL);
|
||||
sha.Finalize();
|
||||
|
||||
// Check auth token
|
||||
if ((lp.securityFlags & 0x04) || !_tokenKey.empty())
|
||||
{
|
||||
uint8 size;
|
||||
socket().recv((char*)&size, 1);
|
||||
char* token = new char[size + 1];
|
||||
token[size] = '\0';
|
||||
socket().recv(token, size);
|
||||
unsigned int validToken = TOTP::GenerateToken(_tokenKey.c_str());
|
||||
unsigned int incomingToken = atoi(token);
|
||||
delete[] token;
|
||||
if (validToken != incomingToken)
|
||||
{
|
||||
char data[] = { AUTH_LOGON_PROOF, WOW_FAIL_UNKNOWN_ACCOUNT, 3, 0 };
|
||||
socket().send(data, sizeof(data));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (_expversion & POST_BC_EXP_FLAG) // 2.x and 3.x clients
|
||||
{
|
||||
sAuthLogonProof_S proof;
|
||||
|
||||
Reference in New Issue
Block a user