Skip to content

Don't rely on libcrypto returning static buffers #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions libsofia-sip-ua/stun/stun_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ int stun_encode_message_integrity(stun_attr_t *attr,
stun_buffer_t *pwd) {
int padded_len;
unsigned int dig_len;
unsigned char md[EVP_MAX_MD_SIZE];
unsigned char *padded_text = NULL;
void *sha1_hmac;

Expand All @@ -474,10 +475,10 @@ int stun_encode_message_integrity(stun_attr_t *attr,
memcpy(padded_text, buf, len);
memset(padded_text + len, 0, padded_len - len);

sha1_hmac = HMAC(EVP_sha1(), pwd->data, pwd->size, padded_text, padded_len, NULL, &dig_len);
sha1_hmac = HMAC(EVP_sha1(), pwd->data, pwd->size, padded_text, padded_len, md, &dig_len);
}
else {
sha1_hmac = HMAC(EVP_sha1(), pwd->data, pwd->size, buf, len, NULL, &dig_len);
sha1_hmac = HMAC(EVP_sha1(), pwd->data, pwd->size, buf, len, md, &dig_len);
}

assert(dig_len == 20);
Expand Down Expand Up @@ -525,6 +526,7 @@ int stun_validate_message_integrity(stun_msg_t *msg, stun_buffer_t *pwd)
int padded_len, len;
unsigned int dig_len;
unsigned char dig[20]; /* received sha1 digest */
unsigned char md[EVP_MAX_MD_SIZE];
unsigned char *padded_text;
#endif

Expand All @@ -550,7 +552,7 @@ int stun_validate_message_integrity(stun_msg_t *msg, stun_buffer_t *pwd)
memset(padded_text, 0, padded_len);
memcpy(padded_text, msg->enc_buf.data, len);

memcpy(dig, HMAC(EVP_sha1(), pwd->data, pwd->size, padded_text, padded_len, NULL, &dig_len), 20);
memcpy(dig, HMAC(EVP_sha1(), pwd->data, pwd->size, padded_text, padded_len, md, &dig_len), 20);

if (memcmp(dig, msg->enc_buf.data + msg->enc_buf.size - 20, 20) != 0) {
/* does not match, but try the test server's password */
Expand Down