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

Function challenge

modules/auth/challenge.c:161–255  ·  view source on GitHub ↗

* Create and send a challenge */

Source from the content-addressed store, hash-verified

159 * Create and send a challenge
160 */
161static inline int challenge(struct sip_msg* _msg, str *realm, qop_type_t _qop,
162 int _code, const str *reason, const str_const *_challenge_msg, int algmask)
163{
164 struct hdr_field* h = NULL;
165 auth_body_t* cred = 0;
166 int i, ret, nalgs, index = 0;
167 hdr_types_t hftype = 0; /* Makes gcc happy */
168 struct sip_uri *uri;
169 str auth_hfs[LAST_ALG_SPTD - FIRST_ALG_SPTD + 1];
170 const str_const *alg_val;
171 const struct digest_auth_calc *digest_calc;
172 struct nonce_params calc_np;
173
174 switch(_code) {
175 case WWW_AUTH_CODE:
176 get_authorized_cred(_msg->authorization, &h);
177 hftype = HDR_AUTHORIZATION_T;
178 break;
179 case PROXY_AUTH_CODE:
180 get_authorized_cred(_msg->proxy_auth, &h);
181 hftype = HDR_PROXYAUTH_T;
182 break;
183 }
184
185 if (h) cred = (auth_body_t*)(h->parsed);
186
187 if (realm->len == 0) {
188 if (get_realm(_msg, hftype, &uri) < 0) {
189 LM_ERR("failed to extract URI\n");
190 if (send_resp(_msg, 400, &str_init(MESSAGE_400), NULL, 0) == -1) {
191 LM_ERR("failed to send the response\n");
192 return -1;
193 }
194 return 0;
195 }
196
197 realm = &uri->host;
198 strip_realm(realm);
199 }
200
201 nalgs = 0;
202 if (algmask >= ALG_MD5SESS && _qop == QOP_UNSPEC_D) {
203 /* RFC8760 algos and XYZ-sess mandates QOP */
204 _qop = QOP_AUTH_D;
205 }
206 if(!disable_nonce_check) {
207 /* get the nonce index and mark it as used */
208 index= reserve_nonce_index();
209 if(index == -1)
210 {
211 LM_ERR("no more nonces can be generated\n");
212 return -1;
213 }
214 LM_DBG("nonce index= %d\n", index);
215 }
216
217 if (clock_gettime(CLOCK_REALTIME, &calc_np.expires) != 0) {
218 LM_ERR("clock_gettime failed\n");

Callers 2

www_challengeFunction · 0.85
proxy_challengeFunction · 0.85

Calls 7

get_authorized_credFunction · 0.85
get_realmFunction · 0.85
send_respFunction · 0.85
strip_realmFunction · 0.85
reserve_nonce_indexFunction · 0.85
get_digest_calcFunction · 0.85
build_auth_hfFunction · 0.85

Tested by

no test coverage detected