Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
fix(prosody): use only the system key server after set_asap_key_server (#18160)
Дамян Минков7887859b8790
diff --git a/resources/prosody-plugins/mod_test_observer_http.lua b/resources/prosody-plugins/mod_test_observer_http.luaindex baa93cf80f..9f2ac0cfe6 100644--- a/resources/prosody-plugins/mod_test_observer_http.lua+++ b/resources/prosody-plugins/mod_test_observer_http.lua@@ -61,6 +61,13 @@ elsemodule:log("warn", "Test ASAP public key not found at %s; login ASAP key-server routes will 404", ASAP_KEY_PATH);end+-- The login public key as a JWKS document, served for cache_keys_url.+local ASAP_JWKS_PATH = "/opt/prosody-jitsi-plugins/test-asap-jwks.json";+local asap_jwks = load_pem(ASAP_JWKS_PATH);+if not asap_jwks then+ module:log("warn", "Test ASAP JWKS not found at %s; the login JWKS route will 404", ASAP_JWKS_PATH);+end+local system_asap_public_key = load_pem(SYSTEM_ASAP_KEY_PATH);if system_asap_public_key thenmodule:log("info", "Loaded test system ASAP public key from %s", SYSTEM_ASAP_KEY_PATH);@@ -150,6 +157,20 @@ module:provides("http", {};end;+ -- GET /test-observer/asap-jwks.json+ -- Returns the login public key (kid "test-asap-key") as JWKS, for the+ -- VirtualHost's cache_keys_url.+ ["GET /asap-jwks.json"] = function()+ if not asap_jwks then+ return { status_code = 404; body = "jwks not found" };+ end+ return {+ status_code = 200;+ headers = { ["Content-Type"] = "application/json" };+ body = asap_jwks;+ };+ end;+-- GET /test-observer/system-asap-keys/<sha256hex(kid)>.pem-- Returns the system RSA public key PEM for mod_muc_end_meeting and similar-- system HTTP API modules that use prosody_password_public_key_repo_url.diff --git a/resources/prosody-plugins/token/util.lib.lua b/resources/prosody-plugins/token/util.lib.luaindex 75c76e8cae..83678c61cd 100644--- a/resources/prosody-plugins/token/util.lib.lua+++ b/resources/prosody-plugins/token/util.lib.lua@@ -205,8 +205,16 @@ function Util.new(module)self.cachedKeys = {};local update_keys_cache;update_keys_cache = async.runner(function (name)+ -- stop refreshing once set_asap_key_server() has replaced the key sources+ if not self.cacheKeysUrl then+ return;+ endlocal content, code, cache_for;content, code, cache_for = http_get_with_retry(self.cacheKeysUrl, nr_retries);+ if not self.cacheKeysUrl then+ -- the key sources were replaced while fetching+ return;+ endif content ~= nil thenlocal keys_to_delete = table_shallow_copy(self.cachedKeys);-- Let's convert any certificate to public key@@ -230,6 +238,9 @@ function Util.new(module)end-- let's schedule the clean in an hour and a half, current tokens will be valid for an hourtimer.add_task(90*60, function ()+ if not self.cachedKeys then+ return;+ endfor k, _ in pairs(keys_to_delete) doself.cachedKeys[k] = nil;end@@ -264,8 +275,21 @@ function Util.new(module)return selfend+--- Makes the given key server the only source of public keys: the JWKS+-- (cache_keys_url) and the app_secret read from the host config are dropped.+-- Used by the HTTP API modules that accept only tokens signed with the keys+-- from prosody_password_public_key_repo_url.+-- @param asapKeyServer the key server URLfunction Util:set_asap_key_server(asapKeyServer)self.asapKeyServer = asapKeyServer;+ self.cacheKeysUrl = nil;+ self.cachedKeys = nil;+ self.appSecret = nil;+ -- the key server serves RSA keys, an algorithm derived from app_secret does not apply+ if not starts_with(self.signatureAlgorithm, "RS") then+ self.signatureAlgorithm = "RS256";+ end+ self:clear_asap_cache();endfunction Util:set_asap_accepted_issuers(acceptedIssuers)diff --git a/tests/prosody/docker/Dockerfile b/tests/prosody/docker/Dockerfileindex 04f734cbf5..120f969d1a 100644--- a/tests/prosody/docker/Dockerfile+++ b/tests/prosody/docker/Dockerfile@@ -38,6 +38,8 @@ COPY --chown=prosody:prosody tests/prosody/docker/cfg/ /etc/prosody/cfg/# Two separate key pairs are used: one for login tokens (mod_auth_token) and one for system# tokens (mod_muc_end_meeting and similar HTTP API modules).COPY --chown=prosody:prosody tests/prosody/fixtures/test-asap-public.pem /opt/prosody-jitsi-plugins/test-asap-public.pem+# The login public key again as JWKS, for cache_keys_url on the main VirtualHost.+COPY --chown=prosody:prosody tests/prosody/fixtures/test-asap-jwks.json /opt/prosody-jitsi-plugins/test-asap-jwks.jsonCOPY --chown=prosody:prosody tests/prosody/fixtures/test-system-asap-public.pem /opt/prosody-jitsi-plugins/test-system-asap-public.pem# Pre-create the focus admin account ([email protected], password "focussecret").diff --git a/tests/prosody/docker/cfg/virtualhosts.cfg.lua b/tests/prosody/docker/cfg/virtualhosts.cfg.luaindex 727cbb199d..6b74549452 100644--- a/tests/prosody/docker/cfg/virtualhosts.cfg.lua+++ b/tests/prosody/docker/cfg/virtualhosts.cfg.lua@@ -4,6 +4,11 @@ VirtualHost "localhost"authentication = "token"app_id = "jitsi"asap_key_server = "http://localhost:5280/test-observer/asap-keys"+ -- The login key is also served as JWKS, as deployments that use both+ -- options do. The system HTTP API modules on this host (kick, jigasi+ -- invite, system chat, end meeting) must still accept only tokens from+ -- prosody_password_public_key_repo_url.+ cache_keys_url = "http://localhost:5280/test-observer/asap-jwks.json"signature_algorithm = "RS256"allow_empty_token = true@@ -120,7 +125,9 @@ VirtualHost "hs256.localhost"app_secret = "testsecret"signature_algorithm = "HS256"allow_empty_token = false- modules_enabled = { "presence_identity" }+ -- muc_kick_participant: a system HTTP API module on a host that has only+ -- app_secret; it verifies tokens from prosody_password_public_key_repo_url.+ modules_enabled = { "presence_identity"; "muc_kick_participant" }-- Second VirtualHost whose domain is listed in muc_access_whitelist on the-- MUC component below. Clients connecting here get JIDs likediff --git a/tests/prosody/fixtures/test-asap-jwks.json b/tests/prosody/fixtures/test-asap-jwks.jsonnew file mode 100644index 0000000000..10c4d3ffc3--- /dev/null+++ b/tests/prosody/fixtures/test-asap-jwks.json@@ -0,0 +1,12 @@+{+ "keys": [+ {+ "kty": "RSA",+ "kid": "test-asap-key",+ "use": "sig",+ "alg": "RS256",+ "n": "vjqI5jpci7JHVbA5wR2wnUoZWq2NZMgPVNqCsXuKDVDCjd9WJb4HkX4bd9Gf35kRiNCTz1NC33uWvmBC1RV8-3g7WZRBUKPKsrse4T3eSgBC0jjoziSP31SN2T0uJjlax-Zjh0ofErzkS7pCsUQPADLfGEQ-46_QI2qSHZ_XPv_L7POEyjEM55W5g7FXKeQbflWNKIZkRDn0eaV_LjwIA67ovL327bkl-Sr3T7lXIEd6_UX3h3yxuW0OqFobQMYhnYXVEGGy3T5Ef2_1FWO7MRIGPJPPIL2AyDoOJ1jDJO7-wHFn5I_RG95HtDjvuRXyesCgIQzLF3vz9vTe_PFyUw",+ "e": "AQAB"+ }+ ]+}diff --git a/tests/prosody/mod_muc_kick_participant_spec.js b/tests/prosody/mod_muc_kick_participant_spec.jsindex 1b4bdac38d..caed4c114a 100644--- a/tests/prosody/mod_muc_kick_participant_spec.js+++ b/tests/prosody/mod_muc_kick_participant_spec.js@@ -1,6 +1,8 @@import assert from 'assert';+import { Buffer } from 'buffer';+import http from 'http';-import { mintAsapToken, mintSystemToken } from './helpers/jwt.js';+import { mintAsapToken, mintSystemToken, mintToken } from './helpers/jwt.js';import { getRoomState, kickParticipant } from './helpers/test_observer.js';import { createXmppClient, joinWithFocus } from './helpers/xmpp_client.js';@@ -24,6 +26,41 @@ async function createRoom() {focus };}+/**+ * Sends a kick request to the endpoint served on the given VirtualHost.+ * fetch() cannot override the Host header, which Prosody routes HTTP by.+ *+ * @param {string} host - VirtualHost to address (Host header).+ * @param {string} roomJid - Room JID.+ * @param {string} participantId - Occupant nick to kick.+ * @param {string} token - Bearer token.+ * @returns {Promise<number>} The HTTP status.+ */+function kickOnHost(host, roomJid, participantId, token) {+ const body = JSON.stringify({ participantId });++ return new Promise((resolve, reject) => {+ const req = http.request({+ host: 'localhost',+ port: 5280,+ method: 'PUT',+ path: `/kick-participant?room=${encodeURIComponent(roomJid.split('@')[0])}`,+ headers: {+ Host: host,+ 'Content-Type': 'application/json',+ 'Content-Length': Buffer.byteLength(body),+ Authorization: `Bearer ${token}`+ }+ }, res => {+ res.resume();+ res.on('end', () => resolve(res.statusCode));+ });++ req.on('error', reject);+ req.end(body);+ });+}+/*** Disconnects all provided clients.*@@ -85,6 +122,37 @@ describe('mod_muc_kick_participant', () => {}});+ // hs256.localhost has only app_secret, so its token settings default to+ // HS256; the module must still verify the RS256 system tokens.+ describe('on a host with only app_secret', () => {++ it('accepts a system token', async () => {+ const { roomJid, focus } = await createRoom();++ try {+ const status = await kickOnHost('hs256.localhost', roomJid, 'no-such-occupant', mintSystemToken());++ assert.strictEqual(status, 404,+ 'system token must pass verification and reach the occupant lookup');+ } finally {+ await disconnectAll(focus);+ }+ });++ it('returns 403 for a token signed with the host app_secret', async () => {+ const { roomJid, focus } = await createRoom();++ try {+ const status = await kickOnHost('hs256.localhost', roomJid, 'focus', mintToken({ room: '*' }));++ assert.strictEqual(status, 403);+ } finally {+ await disconnectAll(focus);+ }+ });++ });+});// ── Parameter validation ─────────────────────────────────────────────────