Browse Source

added checks for audience and issuer values (#1772)

* added checks for audience and issuer values
default audience and issuer checks to validate only appId
added missing documentation lines from the previous PR for context_user and context_group session values

* support for accepting any audience
option set to accept any audience by default
master
Aaron van Meerten 8 years ago
parent
commit
622d4ba89c
1 changed files with 49 additions and 2 deletions
  1. 49
    2
      resources/prosody-plugins/token/util.lib.lua

+ 49
- 2
resources/prosody-plugins/token/util.lib.lua View File

@@ -86,6 +86,12 @@ function Util.new(module)
86 86
         return nil;
87 87
     end
88 88
 
89
+    --array of accepted issuers: by default only includes our appId
90
+    self.acceptedIssuers = module:get_option_array('asap_accepted_issuers',{self.appId})
91
+
92
+    --array of accepted audiences: by default only includes our appId
93
+    self.acceptedAudiences = module:get_option_array('asap_accepted_audiences',{'*'})
94
+
89 95
     if self.asapKeyServer and not have_async then
90 96
         module:log("error", "requires a version of Prosody with util.async");
91 97
         return nil;
@@ -147,6 +153,38 @@ function Util:get_public_key(keyId)
147 153
     return nil;
148 154
 end
149 155
 
156
+--- Verifies issuer part of token
157
+-- @param 'iss' claim from the token to verify
158
+-- @return nil and error string or true for accepted claim
159
+function Util:verify_issuer(issClaim)
160
+    for i, iss in ipairs(self.acceptedIssuers) do
161
+        if issClaim == iss then
162
+            --claim matches an accepted issuer so return success
163
+            return true;
164
+        end
165
+    end
166
+    --if issClaim not found in acceptedIssuers, fail claim
167
+    return nil, "Invalid issuer ('iss' claim)";
168
+end
169
+
170
+--- Verifies audience part of token
171
+-- @param 'aud' claim from the token to verify
172
+-- @return nil and error string or true for accepted claim
173
+function Util:verify_audience(audClaim)
174
+    for i, aud in ipairs(self.acceptedAudiences) do
175
+        if aud == '*' then
176
+            --* indicates to accept any audience in the claims so return success
177
+            return true;
178
+        end
179
+        if audClaim == aud then
180
+            --claim matches an accepted audience so return success
181
+            return true;
182
+        end
183
+    end
184
+    --if issClaim not found in acceptedIssuers, fail claim
185
+    return nil, "Invalid audience ('aud' claim)";
186
+end
187
+
150 188
 --- Verifies token
151 189
 -- @param token the token to verify
152 190
 -- @param secret the secret to use to verify token
@@ -166,8 +204,10 @@ function Util:verify_token(token, secret)
166 204
     if issClaim == nil then
167 205
         return nil, "'iss' claim is missing";
168 206
     end
169
-    if issClaim ~= self.appId then
170
-        return nil, "Invalid application ID('iss' claim)";
207
+    --check the issuer against the accepted list
208
+    local issCheck, issCheckErr = self:verify_issuer(issClaim);
209
+    if issCheck == nil then
210
+        return nil, issCheckErr;
171 211
     end
172 212
 
173 213
     local roomClaim = claims["room"];
@@ -179,6 +219,11 @@ function Util:verify_token(token, secret)
179 219
     if audClaim == nil then
180 220
         return nil, "'aud' claim is missing";
181 221
     end
222
+    --check the audience against the accepted list
223
+    local audCheck, audCheckErr = self:verify_audience(audClaim);
224
+    if audCheck == nil then
225
+        return nil, audCheckErr;
226
+    end
182 227
 
183 228
     return claims;
184 229
 end
@@ -188,6 +233,8 @@ end
188 233
 -- Stores in session the following values:
189 234
 -- session.jitsi_meet_room - the room name value from the token
190 235
 -- session.jitsi_meet_domain - the domain name value from the token
236
+-- session.jitsi_meet_context_user - the user details from the token
237
+-- session.jitsi_meet_context_group - the group value from the token
191 238
 -- @param session the current session
192 239
 -- @return false and error
193 240
 function Util:process_and_verify_token(session)

Loading…
Cancel
Save