Closed slykar closed 3 years ago
Looks like a configuration issue on my side.
Good to know, thanks for checking!
In case anybody has the same issue, this error is caused by the ASAP key server URL not being set properly (check your config files and environment variables). Because no ASAP key server is set, the module falls back to reading the JWT app secret, which is not defined because we are attempting to use RS256, leading to this error (essentially an error indicating an invalid private key format).
If you are using Docker images, make sure variable JWT_ASAP_KEYSERVER is set on the prosody container.
In my case, if I remember correctly it was an invalid response returned from asap_key_server
.
In my case with docker-compose deploy in stable-8719. RS256 failed in the prosody container with the below log.
2023-09-15 01:43:51 c2s55c8c838fa20 error Traceback[c2s]: pkey.new: tasn_dec.c:1149:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag
stack traceback:
[C]: in function '_openssl.pkey.new'
/prosody-plugins/luajwtjitsi.lib.lua:32: in function </prosody-plugins/luajwtjitsi.lib.lua:28>
(...tail calls...)
The related code is
-- Generates an RSA signature of the data.
-- @param data The data to be signed.
-- @param key The private signing key in PEM format.
-- @param algo The digest algorithm to user when generating the signature: sha256, sha384, or sha512.
-- @return The signature or nil and an error message.
local function signRS (data, key, algo)
local privkey = pkey.new(key)
if privkey == nil then
return nil, 'Not a private PEM key'
else
local datadigest = digest.new(algo):update(data)
return privkey:sign(datadigest)
end
end
To debug the issue, I writed a test lua codes "test.lua"
local pkey = require 'openssl.pkey'
key=[[-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAyBRySGBbblhLnNTJUapMBHwVl2RDlOh3TAvGGJlpTE2VpcpbyaZx
jChLBMWeJsiujNpseaMNNfa6qAkckMm3+K0pIqm7JxfgEydhmBIhOLMs0jDIaqU2
gmuh8XzdGpDY+YCRCnuVr9iw7g2xb9aH2t4aMwsfYyvb/YwJ4X7YIRXNI1/U+ZHP
5G7LI4KjPEv0sAAorBhknCmE3e+UuiWOPNQHTSOxiYEApIYZ6hGomwrXSTB/kMtO
EKSpmoX2Tmqeq4TuA5HfNIWUQYS1cIVrxIr1KJNPv5RX0SLIxYLOGm2mQKeHu/X+
5IRuw0BmqUgIMen1ty5lmnazBKJLsnnUmQIDAQAB
-----END RSA PUBLIC KEY-----]]
local pubkey = pkey.new(key)
if pubkey == nil then
print(": failed")
else
print(": successed")
end
It works well in my host server (lua5.1) and still failed in prosody container (lua5.4.2) with the same log as below.
root@67748425b833:/prosody-plugins# lua test.lua
lua: pkey.new: tasn_dec.c:1149:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag
stack traceback:
[C]: in function 'openssl.pkey.new'
test.lua:22: in main chunk
[C]: in ?
Could you help to identy this issue?
Note we are bundling this plugin with in Jitsi Meet, not using the file over here. Check the resources/prosody-plugins folder in the Jitsi Meet repo.
In my case with docker-compose deploy in stable-8719. RS256 failed in the prosody container with the below log.
2023-09-15 01:43:51 c2s55c8c838fa20 error Traceback[c2s]: pkey.new: tasn_dec.c:1149:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag stack traceback: [C]: in function '_openssl.pkey.new' /prosody-plugins/luajwtjitsi.lib.lua:32: in function </prosody-plugins/luajwtjitsi.lib.lua:28> (...tail calls...)
The related code is
-- Generates an RSA signature of the data. -- @param data The data to be signed. -- @param key The private signing key in PEM format. -- @param algo The digest algorithm to user when generating the signature: sha256, sha384, or sha512. -- @return The signature or nil and an error message. local function signRS (data, key, algo) local privkey = pkey.new(key) if privkey == nil then return nil, 'Not a private PEM key' else local datadigest = digest.new(algo):update(data) return privkey:sign(datadigest) end end
To debug the issue, I writed a test lua codes "test.lua"
local pkey = require 'openssl.pkey' key=[[-----BEGIN RSA PUBLIC KEY----- MIIBCgKCAQEAyBRySGBbblhLnNTJUapMBHwVl2RDlOh3TAvGGJlpTE2VpcpbyaZx jChLBMWeJsiujNpseaMNNfa6qAkckMm3+K0pIqm7JxfgEydhmBIhOLMs0jDIaqU2 gmuh8XzdGpDY+YCRCnuVr9iw7g2xb9aH2t4aMwsfYyvb/YwJ4X7YIRXNI1/U+ZHP 5G7LI4KjPEv0sAAorBhknCmE3e+UuiWOPNQHTSOxiYEApIYZ6hGomwrXSTB/kMtO EKSpmoX2Tmqeq4TuA5HfNIWUQYS1cIVrxIr1KJNPv5RX0SLIxYLOGm2mQKeHu/X+ 5IRuw0BmqUgIMen1ty5lmnazBKJLsnnUmQIDAQAB -----END RSA PUBLIC KEY-----]] local pubkey = pkey.new(key) if pubkey == nil then print(": failed") else print(": successed") end
It works well in my host server (lua5.1) and still failed in prosody container (lua5.4.2) with the same log as below.
root@67748425b833:/prosody-plugins# lua test.lua lua: pkey.new: tasn_dec.c:1149:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag stack traceback: [C]: in function 'openssl.pkey.new' test.lua:22: in main chunk [C]: in ?
Could you help to identy this issue?
I got the same issue. Did you find a solution or the cause of the exception?
Hi. I did a fresh Jitsi install few days ago. JWT works with HS256, but fails when using RS256. I've also tested a docker based installation and it works there.
I've noticed that
luajwtjitsi
has been updated 6 days ago to2.0-0
and it got installed on my server. The docker one usesluajwtjitsi 1.3-7
.I'm using the exact same server to serve the public key based on kid.
Prosody Log: