Changeset 1439 for pjproject/trunk/pjnath/src/pjnath/stun_msg.c
- Timestamp:
- Sep 18, 2007 7:33:33 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/stun_msg.c
r1410 r1439 32 32 #define STUN_XOR_FINGERPRINT 0x5354554eL 33 33 34 static int padding_char; 35 34 36 static const char *stun_method_names[] = 35 37 { … … 55 57 { PJ_STUN_SC_UNAUTHORIZED, "Unauthorized"}, 56 58 { PJ_STUN_SC_UNKNOWN_ATTRIBUTE, "Unknown Attribute"}, 57 { PJ_STUN_SC_STALE_CREDENTIALS, "Stale Credentials"},58 { PJ_STUN_SC_INTEGRITY_CHECK_FAILURE,"Integrity Check Failure"},59 { PJ_STUN_SC_MISSING_USERNAME, "Missing Username"},60 { PJ_STUN_SC_USE_TLS, "Use TLS"},61 { PJ_STUN_SC_MISSING_REALM,"Missing Realm"},62 { PJ_STUN_SC_MISSING_NONCE,"Missing Nonce"},63 { PJ_STUN_SC_UNKNOWN_USERNAME, "Unknown Username"},64 { PJ_STUN_SC_NO_BINDING, "No Binding"},59 //{ PJ_STUN_SC_STALE_CREDENTIALS, "Stale Credentials"}, 60 //{ PJ_STUN_SC_INTEGRITY_CHECK_FAILURE, "Integrity Check Failure"}, 61 //{ PJ_STUN_SC_MISSING_USERNAME, "Missing Username"}, 62 //{ PJ_STUN_SC_USE_TLS, "Use TLS"}, 63 //{ PJ_STUN_SC_MISSING_REALM, "Missing Realm"}, 64 //{ PJ_STUN_SC_MISSING_NONCE, "Missing Nonce"}, 65 //{ PJ_STUN_SC_UNKNOWN_USERNAME, "Unknown Username"}, 66 //{ PJ_STUN_SC_NO_BINDING, "No Binding"}, 65 67 { PJ_STUN_SC_STALE_NONCE, "Stale Nonce"}, 66 68 { PJ_STUN_SC_TRANSITIONING, "Active Destination Already Set"}, … … 569 571 570 572 573 /* 574 * Set padding character. 575 */ 576 PJ_DEF(int) pj_stun_set_padding_char(int chr) 577 { 578 int old_pad = padding_char; 579 padding_char = chr; 580 return old_pad; 581 } 582 583 571 584 ////////////////////////////////////////////////////////////////////////////// 572 585 … … 900 913 /* Copy the string */ 901 914 pj_memcpy(buf+ATTR_HDR_LEN, ca->value.ptr, ca->value.slen); 915 916 /* Add padding character, if string is not 4-bytes aligned. */ 917 if (ca->value.slen & 0x03) { 918 pj_uint8_t pad[3]; 919 pj_memset(pad, padding_char, sizeof(pad)); 920 pj_memcpy(buf+ATTR_HDR_LEN+ca->value.slen, pad, 921 4-(ca->value.slen & 0x03)); 922 } 902 923 903 924 /* Done */ … … 1379 1400 * attributes MUST be repeated in the list. 1380 1401 */ 1402 /* No longer necessary 1381 1403 if ((attr_cnt & 0x01)) { 1382 1404 attr->attrs[attr_cnt] = attr_array[attr_cnt-1]; 1383 1405 } 1384 1385 *p_attr = NULL; 1406 */ 1407 1408 *p_attr = attr; 1386 1409 1387 1410 return PJ_SUCCESS; … … 1634 1657 ((options & PJ_STUN_IS_DATAGRAM) && msg_len + 20 != pdu_len)) 1635 1658 { 1659 return PJNATH_EINSTUNMSGLEN; 1660 } 1661 1662 /* STUN message is always padded to the nearest 4 bytes, thus 1663 * the last two bits of the length field are always zero. 1664 */ 1665 if ((msg_len & 0x03) != 0) { 1636 1666 return PJNATH_EINSTUNMSGLEN; 1637 1667 } … … 1879 1909 has_fingerprint = PJ_TRUE; 1880 1910 } else { 1881 if (has_ msg_int || has_fingerprint) {1911 if (has_fingerprint) { 1882 1912 /* Another attribute is found which is not FINGERPRINT 1883 * after FINGERPRINT or MESSAGE-INTEGRITY */ 1913 * after FINGERPRINT. Note that non-FINGERPRINT is 1914 * allowed to appear after M-I 1915 */ 1884 1916 if (p_response) { 1885 1917 pj_stun_msg_create_response(pool, msg, … … 1887 1919 NULL, p_response); 1888 1920 } 1889 return has_fingerprint ? PJNATH_ESTUNFINGERPOS : 1890 PJNATH_ESTUNMSGINTPOS; 1921 return PJNATH_ESTUNFINGERPOS; 1891 1922 } 1892 1923 } … … 2115 2146 } 2116 2147 2117 /* We MUST update the message length in the header NOW before 2118 * calculating MESSAGE-INTEGRITY and FINGERPRINT. 2119 * Note that length is not including the 20 bytes header. 2148 /* If MESSAGE-INTEGRITY is present, include the M-I attribute 2149 * in message length before calculating M-I 2120 2150 */ 2121 if (amsgint && afingerprint) { 2122 body_len = (pj_uint16_t)((buf - start) - 20 + 24 + 8); 2123 } else if (amsgint) { 2151 if (amsgint) { 2124 2152 body_len = (pj_uint16_t)((buf - start) - 20 + 24); 2125 } else if (afingerprint) {2126 body_len = (pj_uint16_t)((buf - start) - 20 + 8);2127 2153 } else { 2128 2154 body_len = (pj_uint16_t)((buf - start) - 20); … … 2162 2188 pj_hmac_sha1_init(&ctx, (pj_uint8_t*)key->ptr, key->slen); 2163 2189 pj_hmac_sha1_update(&ctx, (pj_uint8_t*)start, buf-start); 2164 if ((buf-start) & 0x3F) { 2165 pj_uint8_t zeroes[64]; 2166 pj_bzero(zeroes, sizeof(zeroes)); 2167 pj_hmac_sha1_update(&ctx, zeroes, 64-((buf-start) & 0x3F)); 2168 } 2190 // 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 //} 2169 2196 pj_hmac_sha1_final(&ctx, amsgint->hmac); 2170 2197 … … 2181 2208 /* Calculate FINGERPRINT if present */ 2182 2209 if (afingerprint != NULL) { 2210 /* Update message length */ 2211 PUTVAL16H(start, 2, 2212 (pj_uint16_t)(GETVAL16H(start, 2)+8)); 2213 2183 2214 afingerprint->value = pj_crc32_calc(start, buf-start); 2184 2215 afingerprint->value ^= STUN_XOR_FINGERPRINT;
Note: See TracChangeset
for help on using the changeset viewer.