summaryrefslogtreecommitdiff
path: root/pjnath
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-05-11 10:37:14 +0000
committerBenny Prijono <bennylp@teluu.com>2007-05-11 10:37:14 +0000
commitb4e01cefd4f354128396e85f205ccfa0879bc319 (patch)
tree07c6a259606d0cefa3d05bdbac9d4392e9bcc237 /pjnath
parentc7b1c88b23e55ca897ebacfdeabb9c17c4cd8f34 (diff)
Fixed missing padding when calculating MESSAGE-INTEGRITY in STUN
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1265 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjnath')
-rw-r--r--pjnath/src/pjnath/stun_auth.c14
-rw-r--r--pjnath/src/pjnath/stun_msg.c16
2 files changed, 24 insertions, 6 deletions
diff --git a/pjnath/src/pjnath/stun_auth.c b/pjnath/src/pjnath/stun_auth.c
index 3f5a77a5..d49b4fa2 100644
--- a/pjnath/src/pjnath/stun_auth.c
+++ b/pjnath/src/pjnath/stun_auth.c
@@ -119,6 +119,7 @@ PJ_DEF(pj_status_t) pj_stun_verify_credential( const pj_uint8_t *pkt,
pj_bool_t username_ok;
const pj_stun_realm_attr *arealm;
const pj_stun_realm_attr *anonce;
+ pj_hmac_sha1_context ctx;
pj_uint8_t digest[PJ_SHA1_DIGEST_SIZE];
pj_uint8_t md5_digest[16];
pj_str_t key;
@@ -327,8 +328,17 @@ PJ_DEF(pj_status_t) pj_stun_verify_credential( const pj_uint8_t *pkt,
key = password;
}
- /* Now calculate HMAC of the message */
- pj_hmac_sha1(pkt, amsgi_pos, (pj_uint8_t*)key.ptr, key.slen, digest);
+ /* Now calculate HMAC of the message, adding zero padding if necessary
+ * to make the input 64 bytes aligned.
+ */
+ pj_hmac_sha1_init(&ctx, (pj_uint8_t*)key.ptr, key.slen);
+ pj_hmac_sha1_update(&ctx, pkt, amsgi_pos);
+ if (amsgi_pos & 0x3F) {
+ pj_uint8_t zeroes[64];
+ pj_bzero(zeroes, sizeof(zeroes));
+ pj_hmac_sha1_update(&ctx, zeroes, 64-(amsgi_pos & 0x3F));
+ }
+ pj_hmac_sha1_final(&ctx, digest);
/* Compare HMACs */
if (pj_memcmp(amsgi->hmac, digest, 20)) {
diff --git a/pjnath/src/pjnath/stun_msg.c b/pjnath/src/pjnath/stun_msg.c
index e0092f26..357a74b5 100644
--- a/pjnath/src/pjnath/stun_msg.c
+++ b/pjnath/src/pjnath/stun_msg.c
@@ -2139,6 +2139,7 @@ PJ_DEF(pj_status_t) pj_stun_msg_encode(pj_stun_msg *msg,
if (amsgint != NULL) {
pj_uint8_t md5_key_buf[16];
+ pj_hmac_sha1_context ctx;
pj_str_t key;
/* MESSAGE-INTEGRITY must be the last attribute in the message, or
@@ -2181,10 +2182,17 @@ PJ_DEF(pj_status_t) pj_stun_msg_encode(pj_stun_msg *msg,
key.slen = 16;
}
- /* Calculate HMAC-SHA1 digest */
- pj_hmac_sha1((pj_uint8_t*)start, buf-start,
- (pj_uint8_t*)key.ptr, key.slen,
- amsgint->hmac);
+ /* Calculate HMAC-SHA1 digest, add zero padding to input
+ * if necessary to make the input 64 bytes aligned.
+ */
+ pj_hmac_sha1_init(&ctx, (pj_uint8_t*)key.ptr, key.slen);
+ pj_hmac_sha1_update(&ctx, (pj_uint8_t*)start, buf-start);
+ if ((buf-start) & 0x3F) {
+ pj_uint8_t zeroes[64];
+ pj_bzero(zeroes, sizeof(zeroes));
+ pj_hmac_sha1_update(&ctx, zeroes, 64-((buf-start) & 0x3F));
+ }
+ pj_hmac_sha1_final(&ctx, amsgint->hmac);
/* Put this attribute in the message */
status = encode_msgint_attr(amsgint, buf, buf_size,