MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / check_response

Function check_response

modules/auth/api.c:295–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293}
294
295int check_response(const dig_cred_t* _cred, const str* _method,
296 const str *_msg_body, const HASHHEX* _ha1)
297{
298 HASHHEX ha2;
299 struct digest_auth_response resp;
300 const struct digest_auth_calc *digest_calc;
301
302 digest_calc = get_digest_calc(_cred->alg.alg_parsed);
303 if (digest_calc == NULL) {
304 LM_ERR("digest algorithm (%d) unsupported\n", _cred->alg.alg_parsed);
305 return (-1);
306 }
307
308 /*
309 * First, we have to verify that the response received has
310 * the same length as responses created by us
311 */
312 if (_cred->response.len != digest_calc->HASHHEXLEN) {
313 LM_DBG("receive response len != %d\n", digest_calc->HASHHEXLEN);
314 return 1;
315 }
316
317 /*
318 * Now, calculate our response from parameters received
319 * from the user agent
320 */
321 if (digest_calc->HA2(str2const(_msg_body), str2const(_method),
322 str2const(&(_cred->uri)), _cred->qop.qop_parsed == QOP_AUTHINT_D, &ha2) != 0)
323 return (-1);
324 if (digest_calc->response(_ha1, &ha2, str2const(&(_cred->nonce)),
325 str2const(&(_cred->qop.qop_str)), str2const(&(_cred->nc)),
326 str2const(&(_cred->cnonce)), &resp) != 0)
327 return (-1);
328
329#if !defined(NO_DEBUG)
330 do {
331 char tmpb[digest_calc->HASHHEXLEN];
332 LM_DBG("our result = \'%.*s\'\n", digest_calc->HASHHEXLEN,
333 digest_calc->response_hash_fill(&resp, tmpb, sizeof(tmpb)));
334 } while (0);
335#endif
336
337 /*
338 * And simply compare the strings, the user is
339 * authorized if they match
340 */
341 if (digest_calc->response_hash_bcmp(&resp, str2const(&_cred->response)) == 0) {
342 LM_DBG("authorization is OK\n");
343 return 0;
344 } else {
345 LM_DBG("authorization failed\n");
346 return 2;
347 }
348}
349
350static int auth_calc_HA1(const struct calc_HA1_arg *params, HASHHEX *sess_key)
351{

Callers 1

pv_authorizeFunction · 0.85

Calls 1

get_digest_calcFunction · 0.85

Tested by

no test coverage detected