mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-15 09:18:33 +00:00
#102 Prevent Algo confusion attack
This commit is contained in:
parent
4a970bc302
commit
b9528b32eb
7 changed files with 82 additions and 2 deletions
|
@ -25,6 +25,31 @@ SOFTWARE.
|
|||
|
||||
namespace jwt {
|
||||
|
||||
verify_result_t is_secret_a_public_key(const jwt::string_view secret)
|
||||
{
|
||||
std::error_code ec{};
|
||||
|
||||
BIO_uptr bufkey{
|
||||
BIO_new_mem_buf((void*)secret.data(), static_cast<int>(secret.length())),
|
||||
bio_deletor
|
||||
};
|
||||
if (!bufkey) {
|
||||
throw MemoryAllocationException("BIO_new_mem_buf failed");
|
||||
}
|
||||
|
||||
EC_PKEY_uptr pkey{
|
||||
PEM_read_bio_PUBKEY(bufkey.get(), nullptr, nullptr, nullptr),
|
||||
ev_pkey_deletor
|
||||
};
|
||||
|
||||
if (!pkey) {
|
||||
ec = AlgorithmErrc::InvalidKeyErr;
|
||||
return { false, ec };
|
||||
}
|
||||
|
||||
return {true, ec};
|
||||
}
|
||||
|
||||
template <typename Hasher>
|
||||
verify_result_t HMACSign<Hasher>::verify(
|
||||
const jwt::string_view key,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue