@@ -101,8 +101,8 @@ local function algorithmIsValid(token)
101
101
if token .headerdecoded .alg == nil then
102
102
log (" No 'alg' provided in JWT header." )
103
103
return false
104
- elseif token .headerdecoded .alg ~= ' HS256' and token .headerdecoded .alg ~= ' RS256' then
105
- log (" HS256 and RS256 supported. Incorrect alg in JWT: " .. token .headerdecoded .alg )
104
+ elseif token .headerdecoded .alg ~= ' HS256' and token . headerdecoded . alg ~= ' HS512 ' and token .headerdecoded .alg ~= ' RS256' then
105
+ log (" HS256, HS512 and RS256 supported. Incorrect alg in JWT: " .. token .headerdecoded .alg )
106
106
return false
107
107
end
108
108
@@ -123,6 +123,12 @@ local function hs256SignatureIsValid(token, secret)
123
123
return checksum == token .signaturedecoded
124
124
end
125
125
126
+ local function hs512SignatureIsValid (token , secret )
127
+ local hmac = openssl .hmac .new (secret , ' SHA512' )
128
+ local checksum = hmac :final (token .header .. ' .' .. token .payload )
129
+ return checksum == token .signaturedecoded
130
+ end
131
+
126
132
local function expirationIsValid (token )
127
133
return os.difftime (token .payloaddecoded .exp , core .now ().sec ) > 0
128
134
end
@@ -149,7 +155,7 @@ function jwtverify(txn)
149
155
goto out
150
156
end
151
157
152
- -- 2. Verify the signature algorithm is supported (HS256, RS256)
158
+ -- 2. Verify the signature algorithm is supported (HS256, HS512, RS256)
153
159
if algorithmIsValid (token ) == false then
154
160
log (" Algorithm not valid." )
155
161
goto out
@@ -166,6 +172,11 @@ function jwtverify(txn)
166
172
log (" Signature not valid." )
167
173
goto out
168
174
end
175
+ elseif token .headerdecoded .alg == ' HS512' then
176
+ if hs512SignatureIsValid (token , hmacSecret ) == false then
177
+ log (" Signature not valid." )
178
+ goto out
179
+ end
169
180
end
170
181
171
182
-- 4. Verify that the token is not expired
@@ -217,7 +228,7 @@ local publicKeyPath = os.getenv("OAUTH_PUBKEY_PATH")
217
228
local pem = readAll (publicKeyPath )
218
229
config .publicKey = pem
219
230
220
- -- when using an HS256 signature
231
+ -- when using an HS256 or HS512 signature
221
232
config .hmacSecret = os.getenv (" OAUTH_HMAC_SECRET" )
222
233
223
234
log (" PublicKeyPath: " .. publicKeyPath )
0 commit comments