MCPcopy Create free account
hub / github.com/SIPp/sipp / createAuthResponseMD5

Function createAuthResponseMD5

src/auth.cpp:266–333  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

264}
265
266static int createAuthResponseMD5(
267 const char* user, const char* password, int password_len,
268 const char* method, const char* uri, const char* authtype,
269 const char* msgbody, const char* realm, const char* nonce,
270 const char* cnonce, const char* nc,
271 unsigned char* result)
272{
273 md5_byte_t ha1[MD5_HASH_SIZE], ha2[MD5_HASH_SIZE];
274 md5_byte_t resp[MD5_HASH_SIZE], body[MD5_HASH_SIZE];
275 unsigned char body_hex[HASH_HEX_SIZE+1];
276 unsigned char ha1_hex[HASH_HEX_SIZE+1], ha2_hex[HASH_HEX_SIZE+1];
277 char tmp[MAX_HEADER_LEN];
278 md5_state_t Md5Ctx;
279
280 // Load in A1
281 md5_init(&Md5Ctx);
282 md5_append(&Md5Ctx, (md5_byte_t *) user, strlen(user));
283 md5_append(&Md5Ctx, (md5_byte_t *) ":", 1);
284 md5_append(&Md5Ctx, (md5_byte_t *) realm, strlen(realm));
285 md5_append(&Md5Ctx, (md5_byte_t *) ":", 1);
286 md5_append(&Md5Ctx, (md5_byte_t *) password, password_len);
287 md5_finish(&Md5Ctx, ha1);
288 hashToHex(&ha1[0], &ha1_hex[0], MD5_HASH_SIZE);
289
290 if (auth_uri) {
291 snprintf(tmp, sizeof(tmp), "sip:%s", auth_uri);
292 } else {
293 strncpy(tmp, uri, sizeof(tmp) - 1);
294 }
295 // If using Auth-Int make a hash of the body - which is NULL for REG
296 if (stristr(authtype, "auth-int") != nullptr) {
297 md5_init(&Md5Ctx);
298 md5_append(&Md5Ctx, (md5_byte_t *) msgbody, strlen(msgbody));
299 md5_finish(&Md5Ctx, body);
300 hashToHex(&body[0], &body_hex[0], MD5_HASH_SIZE);
301 }
302
303 // Load in A2
304 md5_init(&Md5Ctx);
305 md5_append(&Md5Ctx, (md5_byte_t *) method, strlen(method));
306 md5_append(&Md5Ctx, (md5_byte_t *) ":", 1);
307 md5_append(&Md5Ctx, (md5_byte_t *) tmp, strlen(tmp));
308 if (stristr(authtype, "auth-int") != nullptr) {
309 md5_append(&Md5Ctx, (md5_byte_t *) ":", 1);
310 md5_append(&Md5Ctx, (md5_byte_t *) &body_hex, HASH_HEX_SIZE);
311 }
312 md5_finish(&Md5Ctx, ha2);
313 hashToHex(&ha2[0], &ha2_hex[0], MD5_HASH_SIZE);
314
315 md5_init(&Md5Ctx);
316 md5_append(&Md5Ctx, (md5_byte_t *) &ha1_hex, HASH_HEX_SIZE);
317 md5_append(&Md5Ctx, (md5_byte_t *) ":", 1);
318 md5_append(&Md5Ctx, (md5_byte_t *) nonce, strlen(nonce));
319 if (cnonce[0] != '\0') {
320 md5_append(&Md5Ctx, (md5_byte_t *) ":", 1);
321 md5_append(&Md5Ctx, (md5_byte_t *) nc, strlen(nc));
322 md5_append(&Md5Ctx, (md5_byte_t *) ":", 1);
323 md5_append(&Md5Ctx, (md5_byte_t *) cnonce, strlen(cnonce));

Callers 2

createAuthHeaderMD5Function · 0.85
verifyAuthHeaderFunction · 0.85

Calls 5

md5_initFunction · 0.85
md5_appendFunction · 0.85
md5_finishFunction · 0.85
hashToHexFunction · 0.85
stristrFunction · 0.85

Tested by

no test coverage detected