[Home]

Summary:ASTERISK-16871: [regression] ast_md5_hash sometimes create incorrect md5 digest
Reporter:zhiqiang wang (rainlake)Labels:
Date Opened:2010-10-25 15:40:49Date Closed:2015-03-27 16:35:24
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Functions/func_md5
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:ast_md5_hash sometimes create incorrect md5 digest. on arm(DockStar) device
make & install asterisk 1.8.0 on my DockStar. my ata can not register or make calls sometimes.
add log in channels/chan_sip.c @ check_auth()
like  below code

function ast_md5_hash can not get correct md5 digest almost all the time(sometimes it is correct) .
it's different as echo -n "<user>:<realm>:<secret>" | md5sum
while in 1.6.2.10, it's always correct.

{code}
if (!ast_strlen_zero(md5secret)) {
               ast_copy_string(a1_hash, md5secret, sizeof(a1_hash));
               ast_log(LOG_NOTICE, "result is correct hash is has md5secret original:%s",a1_hash);
       } else {
               char a1[256];

               snprintf(a1, sizeof(a1), "%s:%s:%s", username, p->realm, secret);
                ast_log(LOG_NOTICE, "result is correct hash is a1 original:%s",a1);
               ast_md5_hash(a1_hash, a1);
               ast_log(LOG_NOTICE, "result is correct hash is a1 hashed:%s",a1_hash);
       }

       /* compute the expected response to compare with what we received */
       {
               char a2[256];
               char a2_hash[256];
               char resp[256];

               snprintf(a2, sizeof(a2), "%s:%s", sip_methods[sipmethod].text,
                               S_OR(keys[K_URI].s, uri));
               ast_log(LOG_NOTICE, "result is correct hash is a2 original:%s",a2);
               ast_md5_hash(a2_hash, a2);
                ast_log(LOG_NOTICE, "result is correct hash is a2 hash:%s",a2_hash);
               snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, usednonce, a2_hash);
                ast_log(LOG_NOTICE, "result is correct hash original is :%s",resp);
               ast_md5_hash(resp_hash, resp);
               ast_log(LOG_NOTICE, "result is correct hash is:%s",resp_hash);
       }
{code}
Comments:By: zhiqiang wang (rainlake) 2010-10-25 15:57:18

it seems while len /2 = 0 get correct digest.
for example

REGISTER:sip:192.168.1.15=0cf453a336b9d4efbc3ba5514ff2a17f is correct.

By: Paul Belanger (pabelanger) 2010-11-01 15:25:01

I was looking at this the other day, seems like a perfect issue for a test case :)

By: Russell Bryant (russell) 2010-11-04 13:24:03

There is already a test module with some basic unit tests for MD5.  I'd like to see the test case updated that demonstrates a problem.

By: Matt Jordan (mjordan) 2015-03-27 16:34:27.463-0500

I can't reproduce this on an x86 system (32-bit or 64-bit).

{{ast_md5_hash}} calls {{MD5Update}}. It's possible that this is related to your platform and the version of the library that you have installed on there. A quick Google search for issues with the MD5 library and odd length strings didn't turn up much. However, if this was systemic across the platforms Asterisk is typically installed on, I'd suspect we'd be getting lit up.

As it is, I'm closing this out as "Can't Reproduce" - although I suspect that even if we could, we'd find out that it was a problem in the library, and not Asterisk itself.