From 1fc77bc3aca41b371be43cc4df48eb344b3ed72d Mon Sep 17 00:00:00 2001 From: Anthony Alba Date: Wed, 1 Mar 2017 13:35:23 +0800 Subject: [PATCH 1/2] base64: flush base64 decoding, and skip base64 padding in crypto line --- daemon/sdp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/daemon/sdp.c b/daemon/sdp.c index 14c5647a6..b608f3703 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -444,6 +444,12 @@ static int parse_attribute_crypto(struct sdp_attribute *output) { str_shift(&c->key_base64_str, 7); ret = g_base64_decode_step(c->key_base64_str.s, enc_salt_key_len, (guchar *) c->key_salt_buf, &b64_state, &b64_save); + // flush b64_state needed for AES-192: 36+2; AES-256: 45+1; + if (enc_salt_key_len % 4) { + ret += g_base64_decode_step("==", 4 - b64_state, + (guchar *) c->key_salt_buf + ret, &b64_state, &b64_save); + } + assert( !b64_state ); err = "invalid base64 encoding"; if (ret != salt_key_len) goto error; @@ -455,6 +461,12 @@ static int parse_attribute_crypto(struct sdp_attribute *output) { c->lifetime_str = c->key_params_str; str_shift(&c->lifetime_str, 7 + enc_salt_key_len); + // skip past base64 padding + if (enc_salt_key_len % 4 == 2) { + str_shift_cmp(&c->lifetime_str, "=="); + } else if (enc_salt_key_len % 4 == 3) { + str_shift_cmp(&c->lifetime_str, "="); + } if (c->lifetime_str.len >= 2) { err = "invalid key parameter syntax"; if (c->lifetime_str.s[0] != '|') From 3e2e0242c3268cf321392700b465e78baea836b7 Mon Sep 17 00:00:00 2001 From: Anthony Alba Date: Thu, 2 Mar 2017 05:29:50 +0800 Subject: [PATCH 2/2] Determine base64 padding from enc_salt_key_len --- daemon/sdp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/daemon/sdp.c b/daemon/sdp.c index b608f3703..22616775a 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -446,10 +446,9 @@ static int parse_attribute_crypto(struct sdp_attribute *output) { (guchar *) c->key_salt_buf, &b64_state, &b64_save); // flush b64_state needed for AES-192: 36+2; AES-256: 45+1; if (enc_salt_key_len % 4) { - ret += g_base64_decode_step("==", 4 - b64_state, + ret += g_base64_decode_step("==", 4 - (enc_salt_key_len % 4), (guchar *) c->key_salt_buf + ret, &b64_state, &b64_save); } - assert( !b64_state ); err = "invalid base64 encoding"; if (ret != salt_key_len) goto error;