[sr-dev] git:master: pv: changes to SHA string transformations

Daniel-Constantin Mierla miconda at gmail.com
Wed Mar 19 16:50:24 CET 2014


Hello,

I guess libkcore has to be linked against libsrutils, as I could spot 
quickly dependencies based on latest commit from Lucian.

Look in lib/presence/Makefile, there is an example of adding local lib 
dependency to another lib.

Cheers,
Daniel

On 19/03/14 16:21, Carsten Bock wrote:
> Hi Daniel,
>
> i'd have to update a whole bunch of modules, if that's the solution.
> "PV"-module was only the first in a list... (all modules, who were
> using the kcore-lib).
>
> Kind regards,
> Carsten
>
>
>
>
>
>
>
>
> 2014-03-19 15:16 GMT+01:00 Daniel-Constantin Mierla <miconda at gmail.com>:
>> Hello,
>>
>> maybe the lib where you moved the sha files is not in linked by the module
>> -- you have to add it in modules/pv/Makefile.
>>
>> Cheers,
>> Daniel
>>
>>
>> On 19/03/14 14:47, Lucian Balaceanu wrote:
>>> Hi Carsten,
>>>
>>> Just a short mail to tell you I am looking into this issue.
>>>
>>> Thank you
>>>
>>> On 03/19/2014 12:35 PM, Carsten Bock wrote:
>>>> Hi Lucian,
>>>>
>>>> with your commit i get the following errors, when running latest trunk:
>>>>
>>>> loading modules under
>>>>
>>>> /usr/lib64/kamailio/modules_k/:/usr/lib64/kamailio/modules/:/usr/lib/kamailio/modules_k/:/usr/lib/kamailio/modules/
>>>>    0(874033) ERROR:<core>  [sr_module.c:599]: load_module(): ERROR:
>>>> load_module: could not open module
>>>> </usr/lib64/kamailio/modules/pv.so>:
>>>> /usr/lib64/kamailio/libkcore.so.1: undefined symbol: SHA384_Init
>>>>    0(874033) :<core>  [cfg.y:3408]: yyerror_at(): parse error in config
>>>> file /etc/kamailio/kamailio.cfg, line 162, column 12-15: failed to
>>>> load module
>>>> [...]
>>>>
>>>> I am running a nightly build on Debian Master to build standard debian
>>>> packages.
>>>>
>>>> As soon as i revert your change in my local build, everythings fine
>>>> again.
>>>>
>>>> The kcore library has no longer any reference to the SHA384
>>>> functions... can you please check?
>>>>
>>>> Thanks,
>>>> Carsten
>>>>
>>>>
>>>>
>>>> 2014-03-18 16:28 GMT+01:00 Lucian Balaceanu<lucian.balaceanu at 1and1.ro>:
>>>>> Module: sip-router
>>>>> Branch: master
>>>>> Commit: ff91a65db150210a0c55ce57df9f476a9e0ee25e
>>>>> URL:
>>>>> http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ff91a65db150210a0c55ce57df9f476a9e0ee25e
>>>>>
>>>>> Author: lucian balanceanu<lucian.balanceanu at 1and1.ro>
>>>>> Committer: lucian balanceanu<lucian.balanceanu at 1and1.ro>
>>>>> Date:   Tue Mar 18 17:20:36 2014 +0200
>>>>>
>>>>> pv: changes to SHA string transformations
>>>>>
>>>>> - addressed memset faulty usage, changed location of sha256 files,
>>>>>     removed sha2utils.h as we can use defines in sha256.h, removed
>>>>>     redundant code
>>>>>
>>>>> ---
>>>>>
>>>>>    lib/kcore/strcommon.c            |   12 +++---------
>>>>>    lib/kcore/strcommon.h            |    2 +-
>>>>>    sha256.c =>  lib/srutils/sha256.c |   14 +++++++-------
>>>>>    sha256.h =>  lib/srutils/sha256.h |    0
>>>>>    modules/pv/pv_trans.c            |   13 ++++++-------
>>>>>    sha2utils.h                      |   17 -----------------
>>>>>    6 files changed, 17 insertions(+), 41 deletions(-)
>>>>>
>>>>> diff --git a/lib/kcore/strcommon.c b/lib/kcore/strcommon.c
>>>>> index 9401457..8e57e93 100644
>>>>> --- a/lib/kcore/strcommon.c
>>>>> +++ b/lib/kcore/strcommon.c
>>>>> @@ -125,33 +125,27 @@ void compute_md5(char *dst, char *src, int
>>>>> src_len)
>>>>>    void compute_sha256(char *dst, u_int8_t *src, int src_len)
>>>>>    {
>>>>>           SHA256_CTX ctx256;
>>>>> -       char buf[64];
>>>>>           SHA256_Init(&ctx256);
>>>>>           SHA256_Update(&ctx256, src, src_len);
>>>>> -       SHA256_End(&ctx256, buf);
>>>>> -       strncpy(dst, buf, 64);
>>>>> +       SHA256_End(&ctx256, dst);
>>>>>    }
>>>>>
>>>>>    /*! \brief Compute SHA384 checksum */
>>>>>    void compute_sha384(char *dst, u_int8_t *src, int src_len)
>>>>>    {
>>>>>           SHA384_CTX ctx384;
>>>>> -       char buf[96];
>>>>>           SHA384_Init(&ctx384);
>>>>>           SHA384_Update(&ctx384, src, src_len);
>>>>> -       SHA384_End(&ctx384, buf);
>>>>> -       strncpy(dst, buf, 96);
>>>>> +       SHA384_End(&ctx384, dst);
>>>>>    }
>>>>>
>>>>>    /*! \brief Compute SHA512 checksum */
>>>>>    void compute_sha512(char *dst, u_int8_t *src, int src_len)
>>>>>    {
>>>>>           SHA512_CTX ctx512;
>>>>> -       char buf[128];
>>>>>           SHA512_Init(&ctx512);
>>>>>           SHA512_Update(&ctx512, src, src_len);
>>>>> -       SHA512_End(&ctx512, buf);
>>>>> -       strncpy(dst, buf, 128);
>>>>> +       SHA512_End(&ctx512, dst);
>>>>>    }
>>>>>
>>>>>    /*! \brief Unscape all printable ASCII characters */
>>>>> diff --git a/lib/kcore/strcommon.h b/lib/kcore/strcommon.h
>>>>> index 5864ef0..9e81455 100644
>>>>> --- a/lib/kcore/strcommon.h
>>>>> +++ b/lib/kcore/strcommon.h
>>>>> @@ -30,7 +30,7 @@
>>>>>
>>>>>    #include "../../str.h"
>>>>>    #include "../../md5.h"
>>>>> -#include "../../sha256.h"
>>>>> +#include "../srutils/sha256.h"
>>>>>
>>>>>    /*
>>>>>     * add backslashes to special characters
>>>>> diff --git a/sha256.c b/lib/srutils/sha256.c
>>>>> similarity index 98%
>>>>> rename from sha256.c
>>>>> rename to lib/srutils/sha256.c
>>>>> index 187d11d..087736d 100644
>>>>> --- a/sha256.c
>>>>> +++ b/lib/srutils/sha256.c
>>>>> @@ -12,7 +12,7 @@
>>>>>     *    notice, this list of conditions and the following disclaimer.
>>>>>     * 2. Redistributions in binary form must reproduce the above
>>>>> copyright
>>>>>     *    notice, this list of conditions and the following disclaimer in
>>>>> the
>>>>> - *    documentation and/or other materials provided with the
>>>>> distribution.
>>>>> + *    documentation and/or other materials provided w627ith the
>>>>> distribution.
>>>>>     * 3. Neither the name of the copyright holder nor the names of
>>>>> contributors
>>>>>     *    may be used to endorse or promote products derived from this
>>>>> software
>>>>>     *    without specific prior written permission.
>>>>> @@ -624,7 +624,7 @@ void SHA256_Final(sha2_byte digest[], SHA256_CTX*
>>>>> context) {
>>>>>           }
>>>>>
>>>>>           /* Clean up state data: */
>>>>> -       MEMSET_BZERO(context, sizeof(context));
>>>>> +       MEMSET_BZERO(context, sizeof(*context));
>>>>>           usedspace = 0;
>>>>>    }
>>>>>
>>>>> @@ -645,7 +645,7 @@ char *SHA256_End(SHA256_CTX* context, char buffer[])
>>>>> {
>>>>>                   }
>>>>>                   *buffer = (char)0;
>>>>>           } else {
>>>>> -               MEMSET_BZERO(context, sizeof(context));
>>>>> +               MEMSET_BZERO(context, sizeof(*context));
>>>>>           }
>>>>>           MEMSET_BZERO(digest, SHA256_DIGEST_LENGTH);
>>>>>           return buffer;
>>>>> @@ -954,7 +954,7 @@ void SHA512_Final(sha2_byte digest[], SHA512_CTX*
>>>>> context) {
>>>>>           }
>>>>>
>>>>>           /* Zero out state data */
>>>>> -       MEMSET_BZERO(context, sizeof(context));
>>>>> +       MEMSET_BZERO(context, sizeof(*context));
>>>>>    }
>>>>>
>>>>>    char *SHA512_End(SHA512_CTX* context, char buffer[]) {
>>>>> @@ -974,7 +974,7 @@ char *SHA512_End(SHA512_CTX* context, char buffer[])
>>>>> {
>>>>>                   }
>>>>>                   *buffer = (char)0;
>>>>>           } else {
>>>>> -               MEMSET_BZERO(context, sizeof(context));
>>>>> +               MEMSET_BZERO(context, sizeof(*context));
>>>>>           }
>>>>>           MEMSET_BZERO(digest, SHA512_DIGEST_LENGTH);
>>>>>           return buffer;
>>>>> @@ -1029,7 +1029,7 @@ void SHA384_Final(sha2_byte digest[], SHA384_CTX*
>>>>> context) {
>>>>>           }
>>>>>
>>>>>           /* Zero out state data */
>>>>> -       MEMSET_BZERO(context, sizeof(context));
>>>>> +       MEMSET_BZERO(context, sizeof(*context));
>>>>>    }
>>>>>
>>>>>    char *SHA384_End(SHA384_CTX* context, char buffer[]) {
>>>>> @@ -1049,7 +1049,7 @@ char *SHA384_End(SHA384_CTX* context, char
>>>>> buffer[]) {
>>>>>                   }
>>>>>                   *buffer = (char)0;
>>>>>           } else {
>>>>> -               MEMSET_BZERO(context, sizeof(context));
>>>>> +               MEMSET_BZERO(context, sizeof(*context));
>>>>>           }
>>>>>           MEMSET_BZERO(digest, SHA384_DIGEST_LENGTH);
>>>>>           return buffer;
>>>>> diff --git a/sha256.h b/lib/srutils/sha256.h
>>>>> similarity index 100%
>>>>> rename from sha256.h
>>>>> rename to lib/srutils/sha256.h
>>>>> diff --git a/modules/pv/pv_trans.c b/modules/pv/pv_trans.c
>>>>> index 5250920..868123e 100644
>>>>> --- a/modules/pv/pv_trans.c
>>>>> +++ b/modules/pv/pv_trans.c
>>>>> @@ -47,7 +47,6 @@
>>>>>    #include "../../parser/parse_nameaddr.h"
>>>>>
>>>>>    #include "../../lib/kcore/strcommon.h"
>>>>> -#include "../../sha2utils.h"
>>>>>    #include "pv_trans.h"
>>>>>
>>>>>
>>>>> @@ -240,31 +239,31 @@ int tr_eval_string(struct sip_msg *msg, tr_param_t
>>>>> *tp, int subtype,
>>>>>                           if(!(val->flags&PV_VAL_STR))
>>>>>                                   val->rs.s =
>>>>> int2str(val->ri,&val->rs.len);
>>>>>                           compute_sha256(_tr_buffer,
>>>>> (u_int8_t*)val->rs.s, val->rs.len);
>>>>> -                       _tr_buffer[SHA256_LEN] = '\0';
>>>>> +                       _tr_buffer[SHA256_DIGEST_STRING_LENGTH -1] =
>>>>> '\0';
>>>>>                           val->flags = PV_VAL_STR;
>>>>>                           val->ri = 0;
>>>>>                           val->rs.s = _tr_buffer;
>>>>> -                       val->rs.len = SHA256_LEN;
>>>>> +                       val->rs.len = SHA256_DIGEST_STRING_LENGTH -1 ;
>>>>>                           break;
>>>>>                   case TR_S_SHA384:
>>>>>                           if(!(val->flags&PV_VAL_STR))
>>>>>                                   val->rs.s =
>>>>> int2str(val->ri,&val->rs.len);
>>>>>                           compute_sha384(_tr_buffer,
>>>>> (u_int8_t*)val->rs.s, val->rs.len);
>>>>> -                       _tr_buffer[SHA384_LEN] = '\0';
>>>>> +                       _tr_buffer[SHA384_DIGEST_STRING_LENGTH -1] =
>>>>> '\0';
>>>>>                           val->flags = PV_VAL_STR;
>>>>>                           val->ri = 0;
>>>>>                           val->rs.s = _tr_buffer;
>>>>> -                       val->rs.len = SHA384_LEN;
>>>>> +                       val->rs.len = SHA384_DIGEST_STRING_LENGTH -1;
>>>>>                           break;
>>>>>                   case TR_S_SHA512:
>>>>>                           if(!(val->flags&PV_VAL_STR))
>>>>>                                   val->rs.s =
>>>>> int2str(val->ri,&val->rs.len);
>>>>>                           compute_sha512(_tr_buffer,
>>>>> (u_int8_t*)val->rs.s, val->rs.len);
>>>>> -                       _tr_buffer[SHA512_LEN] = '\0';
>>>>> +                       _tr_buffer[SHA512_DIGEST_STRING_LENGTH -1] =
>>>>> '\0';
>>>>>                           val->flags = PV_VAL_STR;
>>>>>                           val->ri = 0;
>>>>>                           val->rs.s = _tr_buffer;
>>>>> -                       val->rs.len = SHA512_LEN;
>>>>> +                       val->rs.len = SHA512_DIGEST_STRING_LENGTH -1;
>>>>>                           break;
>>>>>                   case TR_S_ENCODEHEXA:
>>>>>                           if(!(val->flags&PV_VAL_STR))
>>>>> diff --git a/sha2utils.h b/sha2utils.h
>>>>> deleted file mode 100644
>>>>> index b3c5c96..0000000
>>>>> --- a/sha2utils.h
>>>>> +++ /dev/null
>>>>> @@ -1,17 +0,0 @@
>>>>> -/*!
>>>>> - * \file
>>>>> - * \brief SIP-router core :: sha2 hash support
>>>>> - * \ingroup core
>>>>> - * Module: \ref core
>>>>> - */
>>>>> -
>>>>> -#ifndef _SHA2UTILS_H
>>>>> -#define _SHA2UTILS_H
>>>>> -
>>>>> -#include "str.h"
>>>>> -
>>>>> -#define SHA256_LEN      64
>>>>> -#define SHA384_LEN      96
>>>>> -#define SHA512_LEN     128
>>>>> -
>>>>> -#endif /* _SHA2UTILS_H */
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> sr-dev mailing list
>>>>> sr-dev at lists.sip-router.org
>>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>>>>
>>>>
>>>
>>> _______________________________________________
>>> sr-dev mailing list
>>> sr-dev at lists.sip-router.org
>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>>
>> --
>> Daniel-Constantin Mierla - http://www.asipto.com
>> http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
>> Kamailio World Conference - April 2-4, 2014, Berlin, Germany
>> http://www.kamailioworld.com
>>
>>
>>
>> _______________________________________________
>> sr-dev mailing list
>> sr-dev at lists.sip-router.org
>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
>
>

-- 
Daniel-Constantin Mierla - http://www.asipto.com
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Kamailio World Conference - April 2-4, 2014, Berlin, Germany
http://www.kamailioworld.com




More information about the sr-dev mailing list