wrong response computation in auth header
there is a problem in createAuthResponseMD5 (file src/auth.cpp). It seems that changeset ff340b80 added an issue when computing a response. Also the comment of the changeset seems to suggest something wrong: "verifyAuthHeader now takes auth-int into account, but the response is now calculated wrongly"
So, I propose following change to modify the behaviour:
diff --git a/src/auth.cpp b/src/auth.cpp index ecd1b9e..5add2c1 100644 --- a/src/auth.cpp +++ b/src/auth.cpp @@ -260,7 +260,6 @@ int createAuthResponseMD5(const char *user, unsigned char ha1_hex[HASH_HEX_SIZE+1], ha2_hex[HASH_HEX_SIZE+1]; char tmp[MAX_HEADER_LEN]; md5_state_t Md5Ctx;
- const char authint[] = "auth-int";
// Load in A1 md5_init(&Md5Ctx); @@ -307,7 +306,7 @@ int createAuthResponseMD5(const char *user, md5_append(&Md5Ctx, (md5_byte_t *) ":", 1); md5_append(&Md5Ctx, (md5_byte_t *) cnonce, strlen(cnonce)); md5_append(&Md5Ctx, (md5_byte_t *) ":", 1);
-
md5_append(&Md5Ctx, (md5_byte_t *) authint, strlen(authint)); -
} md5_append(&Md5Ctx, (md5_byte_t *) ":", 1); md5_append(&Md5Ctx, (md5_byte_t *) &ha2_hex, HASH_HEX_SIZE);md5_append(&Md5Ctx, (md5_byte_t *) authtype, strlen(authtype));
I fixed the incorrect response before it waas merged - it was due to not passing the nonce in correctly (https://github.com/SIPp/sipp/commit/829edc7ab8a4bc7689d523fdca8ac2bbd67ba6f5).
I think the behaviour your pull request changes is actually right - authtype would be something like auth,auth-int (because the WWW-Authenticate header contains the possible qop values) but the Authorization header contains the single qop value that was chosen.
yes, I receive a qop different from auth-int, in detail:
Digest username="10", realm="server.localrealm", uri="sip:192.168.1.1:5065", nonce="6bb9b02ad540", response="dcba410a5929311874b168b3884709c0", algorithm=MD5, cnonce="327b23c6", nc=00000001, qop=auth
So, response sent by SIPp couldn't authenticate for this reason. Considering your observation, I propose this patch here:
--- a/src/auth.cpp +++ b/src/auth.cpp @@ -261,6 +261,8 @@ int createAuthResponseMD5(const char *user, char tmp[MAX_HEADER_LEN]; md5_state_t Md5Ctx; const char authint[] = "auth-int";
- const char auth[] = "auth";
- char *authresp;
// Load in A1 md5_init(&Md5Ctx); @@ -283,6 +285,11 @@ int createAuthResponseMD5(const char *user, md5_append(&Md5Ctx, (md5_byte_t *) msgbody, strlen(msgbody)); md5_finish(&Md5Ctx, body); hashToHex(&body[0], &body_hex[0]);
-
authresp = authint; -
} else if (stristr(authtype, "auth") != NULL) {
-
authresp = auth; -
} else {
-
authresp = authtype;}
// Load in A2 @@ -307,7 +314,7 @@ int createAuthResponseMD5(const char *user, md5_append(&Md5Ctx, (md5_byte_t *) ":", 1); md5_append(&Md5Ctx, (md5_byte_t *) cnonce, strlen(cnonce)); md5_append(&Md5Ctx, (md5_byte_t *) ":", 1);
-
md5_append(&Md5Ctx, (md5_byte_t *) authint, strlen(authint)); -
md5_append(&Md5Ctx, (md5_byte_t *) authresp, strlen(authresp));} md5_append(&Md5Ctx, (md5_byte_t *) ":", 1); md5_append(&Md5Ctx, (md5_byte_t *) &ha2_hex, HASH_HEX_SIZE);
Could you give an example of the message flows showing this problem (and clarify whether SIPp is the client or the server)? Having the log file created by the -trace_msg option would be useful - then I can reproduce and test it myself.
yes, sure. I pasted two logs created with -trace_msg option, first one successful (with the proposed patch) second one created with original SIPp code downloaded from master.
SIPp acts always as a client and it tries to register against Radvision stack software running on a CPE.
Here is all the links posted on pastebin:
REGISTER ok: http://pastebin.com/vvXem0eP REGISTER failed: http://pastebin.com/xRVZBM66 Proposed solution: http://pastebin.com/insGS1qm
Sorry - I do agree that this was a valid bug (which you'd only hit if you had cnonce but not qop="auth-int", which is why I missed it). I've just accepted #123 which should fix it.