diff options
author | Dániel Bakai <bakaidl@gmail.com> | 2019-04-10 12:52:52 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2019-04-22 15:24:46 +0000 |
commit | 9ce60b173bf17b7d20695d9dc1de050989019664 (patch) | |
tree | 95ec8b8554415ef2c80d6d9950cc9201c8d22c94 /epan/dissectors | |
parent | 51ac1047a7e434a0b2e264780b2fa31f1d986898 (diff) |
Add brotli decompression support for HTTP and HTTP2 dissectors.
Change-Id: I9c09f55673187f6fee723fcd72798fb6b9958b03
Reviewed-on: https://code.wireshark.org/review/32745
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'epan/dissectors')
-rw-r--r-- | epan/dissectors/packet-http.c | 17 | ||||
-rw-r--r-- | epan/dissectors/packet-http2.c | 46 |
2 files changed, 50 insertions, 13 deletions
diff --git a/epan/dissectors/packet-http.c b/epan/dissectors/packet-http.c index 4ee11d234e..0f3698508d 100644 --- a/epan/dissectors/packet-http.c +++ b/epan/dissectors/packet-http.c @@ -237,9 +237,9 @@ static gboolean http_desegment_body = TRUE; static gboolean http_dechunk_body = TRUE; /* - * Decompression of zlib encoded entities. + * Decompression of zlib or brotli encoded entities. */ -#ifdef HAVE_ZLIB +#if defined(HAVE_ZLIB) || defined(HAVE_BROTLI) static gboolean http_decompress_body = TRUE; #else static gboolean http_decompress_body = FALSE; @@ -1704,6 +1704,7 @@ dissect_http_message(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_item *e_ti = NULL; proto_tree *e_tree = NULL; +#ifdef HAVE_ZLIB if (http_decompress_body && (g_ascii_strcasecmp(headers.content_encoding, "gzip") == 0 || g_ascii_strcasecmp(headers.content_encoding, "deflate") == 0 || @@ -1713,6 +1714,16 @@ dissect_http_message(tvbuff_t *tvb, int offset, packet_info *pinfo, uncomp_tvb = tvb_child_uncompress(tvb, next_tvb, 0, tvb_captured_length(next_tvb)); } +#endif + +#ifdef HAVE_BROTLI + if (http_decompress_body && + g_ascii_strcasecmp(headers.content_encoding, "br") == 0) + { + uncomp_tvb = tvb_child_uncompress_brotli(tvb, next_tvb, 0, + tvb_captured_length(next_tvb)); + } +#endif /* * Add the encoded entity to the protocol tree @@ -4017,7 +4028,7 @@ proto_register_http(void) "Whether to reassemble bodies of entities that are transferred " "using the \"Transfer-Encoding: chunked\" method", &http_dechunk_body); -#ifdef HAVE_ZLIB +#if defined(HAVE_ZLIB) || defined(HAVE_BROTLI) prefs_register_bool_preference(http_module, "decompress_body", "Uncompress entity bodies", "Whether to uncompress entity bodies that are compressed " diff --git a/epan/dissectors/packet-http2.c b/epan/dissectors/packet-http2.c index 331ec4ac37..6f3332a0f8 100644 --- a/epan/dissectors/packet-http2.c +++ b/epan/dissectors/packet-http2.c @@ -65,9 +65,9 @@ VALUE_STRING_ENUM(http2_header_repr_type); VALUE_STRING_ARRAY(http2_header_repr_type); /* - * Decompression of zlib encoded entities. + * Decompression of zlib or brotli encoded entities. */ -#ifdef HAVE_ZLIB +#if defined(HAVE_ZLIB) || defined(HAVE_BROTLI) static gboolean http2_decompress_body = TRUE; #else static gboolean http2_decompress_body = FALSE; @@ -1985,18 +1985,36 @@ dissect_frame_prio(tvbuff_t *tvb, proto_tree *http2_tree, guint offset, guint8 f } #ifdef HAVE_NGHTTP2 -static int -can_uncompress_body(packet_info *pinfo) +enum body_uncompression { + BODY_UNCOMPRESSION_NONE, + BODY_UNCOMPRESSION_ZLIB, + BODY_UNCOMPRESSION_BROTLI +}; + +static enum body_uncompression +get_body_uncompression_info(packet_info *pinfo) { http2_data_stream_body_info_t *body_info = get_data_stream_body_info(pinfo); gchar *content_encoding = body_info->content_encoding; /* Check we have a content-encoding header appropriate as well as checking if this is partial content. * We can't decompress part of a gzip encoded entity */ - return http2_decompress_body - && body_info->is_partial_content == FALSE - && content_encoding != NULL - && (strncmp(content_encoding, "gzip", 4) == 0 || strncmp(content_encoding, "deflate", 7) == 0); + if (!http2_decompress_body || body_info->is_partial_content == TRUE || content_encoding == NULL) { + return BODY_UNCOMPRESSION_NONE; + } + +#ifdef HAVE_ZLIB + if (strncmp(content_encoding, "gzip", 4) == 0 || strncmp(content_encoding, "deflate", 7) == 0) { + return BODY_UNCOMPRESSION_ZLIB; + } +#endif +#ifdef HAVE_BROTLI + if (strncmp(content_encoding, "br", 2) == 0) { + return BODY_UNCOMPRESSION_BROTLI; + } +#endif + + return BODY_UNCOMPRESSION_NONE; } /* Try to dissect reassembled http2.data.data according to content_type. */ @@ -2027,9 +2045,17 @@ dissect_http2_data_full_body(tvbuff_t *tvb, packet_info *pinfo, proto_tree *http gint datalen = tvb_reported_length(tvb); - if (can_uncompress_body(pinfo)) { + enum body_uncompression uncompression = get_body_uncompression_info(pinfo); + if (uncompression != BODY_UNCOMPRESSION_NONE) { proto_item *compressed_proto_item = NULL; - tvbuff_t *uncompressed_tvb = tvb_child_uncompress(tvb, tvb, 0, datalen); + + tvbuff_t *uncompressed_tvb = NULL; + if (uncompression == BODY_UNCOMPRESSION_ZLIB) { + uncompressed_tvb = tvb_child_uncompress(tvb, tvb, 0, datalen); + } else if (uncompression == BODY_UNCOMPRESSION_BROTLI) { + uncompressed_tvb = tvb_child_uncompress_brotli(tvb, tvb, 0, datalen); + } + http2_data_stream_body_info_t *body_info = get_data_stream_body_info(pinfo); gchar *compression_method = body_info->content_encoding; |