Changeset 1479


Ignore:
Timestamp:
Oct 5, 2007 3:53:56 PM (16 years ago)
Author:
bennylp
Message:

Ticket #392: Added configuration to enable old, rfc3489bis-06 and older, style of MESSAGE-INTEGRITY and FINGERPRINT calculation

Location:
pjproject/trunk/pjnath
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/include/pjnath/config.h

    r1450 r1479  
    112112 */ 
    113113#ifndef PJ_STUN_MAX_PKT_LEN 
    114 #   define PJ_STUN_MAX_PKT_LEN                      512 
     114#   define PJ_STUN_MAX_PKT_LEN                      800 
    115115#endif 
    116116 
     
    129129#ifndef PJ_STUN_STRING_ATTR_PAD_CHR 
    130130#   define PJ_STUN_STRING_ATTR_PAD_CHR              0 
     131#endif 
     132 
     133 
     134/** 
     135 * Enable pre-RFC3489bis-07 style of STUN MESSAGE-INTEGRITY and FINGERPRINT 
     136 * calculation. By default this should be disabled since the calculation is 
     137 * not backward compatible with current STUN specification. 
     138 */ 
     139#ifndef PJ_STUN_OLD_STYLE_MI_FINGERPRINT 
     140#   define PJ_STUN_OLD_STYLE_MI_FINGERPRINT         0 
    131141#endif 
    132142 
  • pjproject/trunk/pjnath/src/pjnath/stun_auth.c

    r1439 r1479  
    343343    pj_hmac_sha1_init(&ctx, (pj_uint8_t*)key.ptr, key.slen); 
    344344 
     345#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT 
     346    /* Pre rfc3489bis-06 style of calculation */ 
     347    pj_hmac_sha1_update(&ctx, pkt, 20); 
     348#else 
    345349    /* First calculate HMAC for the header. 
    346350     * The calculation is different depending on whether FINGERPRINT attribute 
     
    355359        pj_hmac_sha1_update(&ctx, pkt, 20); 
    356360    } 
     361#endif  /* PJ_STUN_OLD_STYLE_MI_FINGERPRINT */ 
    357362 
    358363    /* Now update with the message body */ 
    359364    pj_hmac_sha1_update(&ctx, pkt+20, amsgi_pos); 
     365#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT 
    360366    // This is no longer necessary as per rfc3489bis-08 
    361     //if (amsgi_pos & 0x3F) { 
    362     //  pj_uint8_t zeroes[64]; 
    363     //  pj_bzero(zeroes, sizeof(zeroes)); 
    364     //  pj_hmac_sha1_update(&ctx, zeroes, 64-(amsgi_pos & 0x3F)); 
    365     //} 
     367    if ((amsgi_pos+20) & 0x3F) { 
     368        pj_uint8_t zeroes[64]; 
     369        pj_bzero(zeroes, sizeof(zeroes)); 
     370        pj_hmac_sha1_update(&ctx, zeroes, 64-((amsgi_pos+20) & 0x3F)); 
     371    } 
     372#endif 
    366373    pj_hmac_sha1_final(&ctx, digest); 
    367374 
     
    475482    pj_hmac_sha1_init(&ctx, (pj_uint8_t*)key->ptr, key->slen); 
    476483 
     484#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT 
     485    /* Pre rfc3489bis-06 style of calculation */ 
     486    pj_hmac_sha1_update(&ctx, pkt, 20); 
     487#else 
    477488    /* First calculate HMAC for the header. 
    478489     * The calculation is different depending on whether FINGERPRINT attribute 
     
    487498        pj_hmac_sha1_update(&ctx, pkt, 20); 
    488499    } 
     500#endif  /* PJ_STUN_OLD_STYLE_MI_FINGERPRINT */ 
    489501 
    490502    /* Now update with the message body */ 
    491503    pj_hmac_sha1_update(&ctx, pkt+20, amsgi_pos); 
     504#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT 
    492505    // This is no longer necessary as per rfc3489bis-08 
    493     //if (amsgi_pos & 0x3F) { 
    494     //  pj_uint8_t zeroes[64]; 
    495     //  pj_bzero(zeroes, sizeof(zeroes)); 
    496     //  pj_hmac_sha1_update(&ctx, zeroes, 64-(amsgi_pos & 0x3F)); 
    497     //} 
     506    if ((amsgi_pos+20) & 0x3F) { 
     507        pj_uint8_t zeroes[64]; 
     508        pj_bzero(zeroes, sizeof(zeroes)); 
     509        pj_hmac_sha1_update(&ctx, zeroes, 64-((amsgi_pos+20) & 0x3F)); 
     510    } 
     511#endif 
    498512    pj_hmac_sha1_final(&ctx, digest); 
    499513 
  • pjproject/trunk/pjnath/src/pjnath/stun_msg.c

    r1443 r1479  
    21462146    } 
    21472147 
     2148#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT 
     2149    /* 
     2150     * This is the old style MESSAGE-INTEGRITY and FINGERPRINT 
     2151     * calculation, used in rfc3489bis-06 and older. 
     2152     */ 
     2153    /* We MUST update the message length in the header NOW before 
     2154     * calculating MESSAGE-INTEGRITY and FINGERPRINT.  
     2155     * Note that length is not including the 20 bytes header. 
     2156      */ 
     2157    if (amsgint && afingerprint) { 
     2158        body_len = (pj_uint16_t)((buf - start) - 20 + 24 + 8); 
     2159    } else if (amsgint) { 
     2160        body_len = (pj_uint16_t)((buf - start) - 20 + 24); 
     2161    } else if (afingerprint) { 
     2162        body_len = (pj_uint16_t)((buf - start) - 20 + 8); 
     2163    } else { 
     2164        body_len = (pj_uint16_t)((buf - start) - 20); 
     2165    } 
     2166#else 
    21482167    /* If MESSAGE-INTEGRITY is present, include the M-I attribute 
    21492168     * in message length before calculating M-I 
     
    21542173        body_len = (pj_uint16_t)((buf - start) - 20); 
    21552174    } 
     2175#endif  /* PJ_STUN_OLD_STYLE_MI_FINGERPRINT */ 
    21562176 
    21572177    /* hdr->length = pj_htons(length); */ 
     
    21882208        pj_hmac_sha1_init(&ctx, (pj_uint8_t*)key->ptr, key->slen); 
    21892209        pj_hmac_sha1_update(&ctx, (pj_uint8_t*)start, buf-start); 
     2210#if PJ_STUN_OLD_STYLE_MI_FINGERPRINT 
    21902211        // These are obsoleted in rfc3489bis-08 
    2191         //if ((buf-start) & 0x3F) { 
    2192         //    pj_uint8_t zeroes[64]; 
    2193         //    pj_bzero(zeroes, sizeof(zeroes)); 
    2194         //    pj_hmac_sha1_update(&ctx, zeroes, 64-((buf-start) & 0x3F)); 
    2195         //} 
     2212        if ((buf-start) & 0x3F) { 
     2213            pj_uint8_t zeroes[64]; 
     2214            pj_bzero(zeroes, sizeof(zeroes)); 
     2215            pj_hmac_sha1_update(&ctx, zeroes, 64-((buf-start) & 0x3F)); 
     2216        } 
     2217#endif  /* PJ_STUN_OLD_STYLE_MI_FINGERPRINT */ 
    21962218        pj_hmac_sha1_final(&ctx, amsgint->hmac); 
    21972219 
     
    22082230    /* Calculate FINGERPRINT if present */ 
    22092231    if (afingerprint != NULL) { 
     2232 
     2233#if !PJ_STUN_OLD_STYLE_MI_FINGERPRINT 
    22102234        /* Update message length */ 
    22112235        PUTVAL16H(start, 2,  
    22122236                 (pj_uint16_t)(GETVAL16H(start, 2)+8)); 
     2237#endif 
    22132238 
    22142239        afingerprint->value = pj_crc32_calc(start, buf-start); 
  • pjproject/trunk/pjnath/src/pjnath/stun_session.c

    r1414 r1479  
    561561    int dst_port; 
    562562    const pj_sockaddr *dst = (const pj_sockaddr*)addr; 
    563     char buf[512]; 
     563    char buf[800]; 
    564564     
    565565    if (dst->addr.sa_family == pj_AF_INET()) { 
Note: See TracChangeset for help on using the changeset viewer.