Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not check typ in jwt header #36

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions Cpp/fost-crypto/jwt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ fostlib::nullable<fostlib::jwt::token> fostlib::jwt::token::load(
const auto u8_header = coerce<utf8_string>(v64_header);
const auto str_header = coerce<string>(u8_header);
const auto header = json::parse(str_header);
if (header["typ"] != jwt) {
log::warning(c_fost)("", "JWT type mismatch")("typ", header["typ"]);
return fostlib::null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave the warning, but just remove the early return? I think it's clear it's meant to be there and I'd rather the code looks like it's not missed something

}

const base64_string b64_payload(parts[1]);
const auto v64_payload =
Expand Down Expand Up @@ -184,23 +180,24 @@ fostlib::nullable<fostlib::jwt::token> fostlib::jwt::token::load(
return fostlib::null;
}
} else if (header["alg"] == rs256) {
// expect lamda function must return publickey component as `{e}0x00{n}`
// expect lamda function must return publickey component as
// `{e}0x00{n}`
auto public_key = lambda(header, payload);
std::string modulus_n;
std::string exponent_e;
for (std::vector<f5::byte>::iterator it = public_key.begin(); it != public_key.end(); ++it) {
std::string exponent_e;
for (std::vector<f5::byte>::iterator it = public_key.begin();
it != public_key.end(); ++it) {
if (*it == f5::byte(0x00)) {
exponent_e = std::string(public_key.begin(), it);
modulus_n = std::string(it + 1, public_key.end());
break;
}
}
}
if (not fostlib::rsa::PKCS1v15_SHA256::validate(
std::string(parts[0].begin(), parts[0].end()) + "." + std::string(parts[1].begin(), parts[1].end()),
std::string(parts[2].begin(), parts[2].end()),
modulus_n,
exponent_e
)) {
std::string(parts[0].begin(), parts[0].end()) + "."
+ std::string(parts[1].begin(), parts[1].end()),
std::string(parts[2].begin(), parts[2].end()),
modulus_n, exponent_e)) {
log::warning(c_fost)("", "PKCS1v15_SHA256 verification failed");
return fostlib::null;
}
Expand Down