feat: Integrate CIE authentication flow
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
#include "common/Crypto.h"
|
||||
|
||||
#include <drogon/utils/Utilities.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/hmac.h>
|
||||
|
||||
#include <iomanip>
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
@@ -27,6 +30,29 @@ std::string sha256(const std::string &value)
|
||||
return drogon::utils::getSha256(value);
|
||||
}
|
||||
|
||||
std::string hmacSha256Hex(const std::string &key, const std::string &value)
|
||||
{
|
||||
unsigned char digest[EVP_MAX_MD_SIZE];
|
||||
unsigned int digestSize = 0;
|
||||
HMAC(EVP_sha256(),
|
||||
key.data(),
|
||||
static_cast<int>(key.size()),
|
||||
reinterpret_cast<const unsigned char *>(value.data()),
|
||||
value.size(),
|
||||
digest,
|
||||
&digestSize);
|
||||
return toHex(digest, digestSize);
|
||||
}
|
||||
|
||||
bool constantTimeEquals(const std::string &left, const std::string &right)
|
||||
{
|
||||
if (left.size() != right.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return CRYPTO_memcmp(left.data(), right.data(), left.size()) == 0;
|
||||
}
|
||||
|
||||
std::string randomNumericCode(int digits)
|
||||
{
|
||||
std::random_device device;
|
||||
|
||||
Reference in New Issue
Block a user