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

Function pre_auth

modules/auth/api.c:152–282  ·  view source on GitHub ↗

* Purpose of this function is to find credentials with given realm, * do sanity check, validate credential correctness and determine if * we should really authenticate (there must be no authentication for * ACK and CANCEL */

Source from the content-addressed store, hash-verified

150 * ACK and CANCEL
151 */
152auth_result_t pre_auth(struct sip_msg* _m, str* _realm, hdr_types_t _hftype,
153 struct hdr_field** _h, unsigned skip_flags)
154{
155 int ret, ecode;
156 auth_body_t* c;
157 struct sip_uri *uri;
158 const str *emsg;
159
160 /* ACK and CANCEL must be always authorized, there is
161 * no way how to challenge ACK and CANCEL cannot be
162 * challenged because it must have the same CSeq as
163 * the request to be canceled
164 */
165
166 if ((_m->REQ_METHOD == METHOD_ACK) || (_m->REQ_METHOD == METHOD_CANCEL))
167 return AUTHORIZED;
168
169 if (_realm->len == 0) {
170 if (get_realm(_m, _hftype, &uri) < 0) {
171 LM_ERR("failed to extract realm\n");
172 emsg = str_static(MESSAGE_400);
173 ecode = 400;
174 goto ereply;
175 }
176
177 *_realm = uri->host;
178 strip_realm(_realm);
179 }
180
181 /* Try to find credentials with corresponding realm
182 * in the message, parse them and return pointer to
183 * parsed structure
184 */
185 ret = find_credentials(_m, _realm, _hftype, _h);
186 if (ret < 0) {
187 LM_ERR("failed to find credentials\n");
188 if (ret == -2) {
189 emsg = str_static(MESSAGE_500);
190 ecode = 500;
191 } else {
192 emsg = str_static(MESSAGE_400);
193 ecode = 400;
194 }
195 goto ereply;
196 } else if (ret > 0) {
197 LM_DBG("credentials with given realm not found\n");
198 return NO_CREDENTIALS;
199 }
200 if (skip_flags & AUTH_SKIP_CRED_CHECK)
201 return DO_AUTHORIZATION;
202
203 /* Pointer to the parsed credentials */
204 c = (auth_body_t*)((*_h)->parsed);
205 dig_cred_t *dcp = &(c->digest);
206
207 /* Check credentials correctness here */
208 if (check_dig_cred(dcp) != E_DIG_OK) {
209 LM_DBG("received credentials are not filled properly\n");

Callers 1

pv_authorizeFunction · 0.85

Calls 9

get_realmFunction · 0.85
strip_realmFunction · 0.85
find_credentialsFunction · 0.85
check_dig_credFunction · 0.85
mark_authorized_credFunction · 0.85
decr_nonceFunction · 0.85
is_nonce_staleFunction · 0.85
is_nonce_index_validFunction · 0.85
send_respFunction · 0.85

Tested by

no test coverage detected