mirror of
https://github.com/arun11299/cpp-jwt.git
synced 2025-05-14 16:58:34 +00:00
Deprecated BIO_f_base64 from boringssl #61
This commit is contained in:
parent
42fcc915e4
commit
4752d47592
2 changed files with 15 additions and 32 deletions
|
@ -33,19 +33,6 @@ verify_result_t HMACSign<Hasher>::verify(
|
||||||
{
|
{
|
||||||
std::error_code ec{};
|
std::error_code ec{};
|
||||||
|
|
||||||
BIO_uptr b64{BIO_new(BIO_f_base64()), bio_deletor};
|
|
||||||
if (!b64) {
|
|
||||||
throw MemoryAllocationException("BIO_new failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
BIO* bmem = BIO_new(BIO_s_mem());
|
|
||||||
if (!bmem) {
|
|
||||||
throw MemoryAllocationException("BIO_new failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
BIO_push(b64.get(), bmem);
|
|
||||||
BIO_set_flags(b64.get(), BIO_FLAGS_BASE64_NO_NL);
|
|
||||||
|
|
||||||
unsigned char enc_buf[EVP_MAX_MD_SIZE];
|
unsigned char enc_buf[EVP_MAX_MD_SIZE];
|
||||||
uint32_t enc_buf_len = 0;
|
uint32_t enc_buf_len = 0;
|
||||||
|
|
||||||
|
@ -60,27 +47,23 @@ verify_result_t HMACSign<Hasher>::verify(
|
||||||
ec = AlgorithmErrc::VerificationErr;
|
ec = AlgorithmErrc::VerificationErr;
|
||||||
return {false, ec};
|
return {false, ec};
|
||||||
}
|
}
|
||||||
|
if (enc_buf_len == 0) {
|
||||||
BIO_write(b64.get(), enc_buf, enc_buf_len);
|
|
||||||
(void)BIO_flush(b64.get());
|
|
||||||
|
|
||||||
int len = BIO_pending(bmem);
|
|
||||||
if (len < 0) {
|
|
||||||
ec = AlgorithmErrc::VerificationErr;
|
ec = AlgorithmErrc::VerificationErr;
|
||||||
return {false, ec};
|
return {false, ec};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cbuf;
|
std::string b64_enc_str = jwt::base64_encode((const char*)&enc_buf[0], enc_buf_len);
|
||||||
cbuf.resize(len + 1);
|
|
||||||
|
|
||||||
len = BIO_read(bmem, &cbuf[0], len);
|
if (!b64_enc_str.length()) {
|
||||||
cbuf.resize(len);
|
ec = AlgorithmErrc::VerificationErr;
|
||||||
|
return {false, ec};
|
||||||
|
}
|
||||||
|
|
||||||
//Make the base64 string url safe
|
// Make the base64 string url safe
|
||||||
auto new_len = jwt::base64_uri_encode(&cbuf[0], cbuf.length());
|
auto new_len = jwt::base64_uri_encode(&b64_enc_str[0], b64_enc_str.length());
|
||||||
cbuf.resize(new_len);
|
b64_enc_str.resize(new_len);
|
||||||
|
|
||||||
bool ret = (jwt::string_view{cbuf} == jwt_sign);
|
bool ret = (jwt::string_view{b64_enc_str} == jwt_sign);
|
||||||
|
|
||||||
return { ret, ec };
|
return { ret, ec };
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,8 +157,8 @@ inline void jwt_payload::decode(const jwt::string_view enc_str)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string jwt_signature::encode(const jwt_header& header,
|
inline std::string jwt_signature::encode(const jwt_header& header,
|
||||||
const jwt_payload& payload,
|
const jwt_payload& payload,
|
||||||
std::error_code& ec)
|
std::error_code& ec)
|
||||||
{
|
{
|
||||||
std::string jwt_msg;
|
std::string jwt_msg;
|
||||||
ec.clear();
|
ec.clear();
|
||||||
|
@ -168,7 +168,7 @@ inline std::string jwt_signature::encode(const jwt_header& header,
|
||||||
|
|
||||||
std::string hdr_sign = header.base64_encode();
|
std::string hdr_sign = header.base64_encode();
|
||||||
std::string pld_sign = payload.base64_encode();
|
std::string pld_sign = payload.base64_encode();
|
||||||
std::string data = hdr_sign + '.' + pld_sign;
|
std::string data = hdr_sign + '.' + pld_sign;
|
||||||
|
|
||||||
auto res = sign_fn(key_, data);
|
auto res = sign_fn(key_, data);
|
||||||
|
|
||||||
|
@ -192,8 +192,8 @@ inline std::string jwt_signature::encode(const jwt_header& header,
|
||||||
}
|
}
|
||||||
|
|
||||||
inline verify_result_t jwt_signature::verify(const jwt_header& header,
|
inline verify_result_t jwt_signature::verify(const jwt_header& header,
|
||||||
const jwt::string_view hdr_pld_sign,
|
const jwt::string_view hdr_pld_sign,
|
||||||
const jwt::string_view jwt_sign)
|
const jwt::string_view jwt_sign)
|
||||||
{
|
{
|
||||||
verify_func_t verify_fn = get_verify_algorithm_impl(header);
|
verify_func_t verify_fn = get_verify_algorithm_impl(header);
|
||||||
return verify_fn(key_, hdr_pld_sign, jwt_sign);
|
return verify_fn(key_, hdr_pld_sign, jwt_sign);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue