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

fix(jwt-plugin): Add missing pkey sanity check for ES384 and ES512 #12724

Merged
merged 2 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions changelog/unreleased/kong/fix-jwt-plugin-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**Jwt**: fix an issue where the plugin would fail when using invalid public keys for ES384 and ES512 algorithms."
type: bugfix
scope: Plugin
14 changes: 5 additions & 9 deletions kong/plugins/jwt/jwt_parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,17 @@ local alg_verify = {
RS256 = function(data, signature, key)
local pkey, _ = openssl_pkey.new(key)
assert(pkey, "Consumer Public Key is Invalid")
local digest = openssl_digest.new("sha256")
assert(digest:update(data))
return pkey:verify(signature, digest)
return pkey:verify(signature, data, "sha256")
end,
RS384 = function(data, signature, key)
local pkey, _ = openssl_pkey.new(key)
assert(pkey, "Consumer Public Key is Invalid")
local digest = openssl_digest.new("sha384")
assert(digest:update(data))
return pkey:verify(signature, digest)
return pkey:verify(signature, data, "sha384")
end,
RS512 = function(data, signature, key)
local pkey, _ = openssl_pkey.new(key)
assert(pkey, "Consumer Public Key is Invalid")
local digest = openssl_digest.new("sha512")
assert(digest:update(data))
return pkey:verify(signature, digest)
return pkey:verify(signature, data, "sha512")
end,
-- https://www.rfc-editor.org/rfc/rfc7518#section-3.4
ES256 = function(data, signature, key)
Expand All @@ -150,6 +144,7 @@ local alg_verify = {
-- ECDSA P-521 SHA-512, R and S will be 521 bits each, resulting in a
-- 132-octet sequence.
local pkey, _ = openssl_pkey.new(key)
assert(pkey, "Consumer Public Key is Invalid")
assert(#signature == 96, "Signature must be 96 bytes.")
return pkey:verify(signature, data, "sha384", nil, { ecdsa_use_raw = true })
end,
Expand All @@ -163,6 +158,7 @@ local alg_verify = {
-- ECDSA P-521 SHA-512, R and S will be 521 bits each, resulting in a
-- 132-octet sequence.
local pkey, _ = openssl_pkey.new(key)
assert(pkey, "Consumer Public Key is Invalid")
assert(#signature == 132, "Signature must be 132 bytes.")
return pkey:verify(signature, data, "sha512", nil, { ecdsa_use_raw = true })
end,
Expand Down
Loading