From: Philippe Antoine Date: Mon, 5 Jul 2021 09:18:26 +0000 (+0200) Subject: http2: support deflate decompression X-Git-Tag: suricata-6.0.4~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a900dea72ef8052b6b1bee41d50f49be2c6a48bb;p=thirdparty%2Fsuricata.git http2: support deflate decompression cf #4556 (cherry picked from commit 1378b2f45144676d98f3430728dcca3e09540921) --- diff --git a/rust/src/http2/decompression.rs b/rust/src/http2/decompression.rs index 96dbd11e87..74637e0f9a 100644 --- a/rust/src/http2/decompression.rs +++ b/rust/src/http2/decompression.rs @@ -17,7 +17,7 @@ use crate::core::STREAM_TOCLIENT; use brotli; -use flate2::read::GzDecoder; +use flate2::read::{DeflateDecoder, GzDecoder}; use std; use std::io; use std::io::{Cursor, Read, Write}; @@ -30,7 +30,8 @@ pub enum HTTP2ContentEncoding { HTTP2ContentEncodingUnknown = 0, HTTP2ContentEncodingGzip = 1, HTTP2ContentEncodingBr = 2, - HTTP2ContentEncodingUnrecognized = 3, + HTTP2ContentEncodingDeflate = 3, + HTTP2ContentEncodingUnrecognized = 4, } //a cursor turning EOF into blocking errors @@ -77,6 +78,7 @@ pub enum HTTP2Decompresser { UNASSIGNED, GZIP(GzDecoder), BROTLI(brotli::Decompressor), + DEFLATE(DeflateDecoder), } impl std::fmt::Debug for HTTP2Decompresser { @@ -85,15 +87,7 @@ impl std::fmt::Debug for HTTP2Decompresser { HTTP2Decompresser::UNASSIGNED => write!(f, "UNASSIGNED"), HTTP2Decompresser::GZIP(_) => write!(f, "GZIP"), HTTP2Decompresser::BROTLI(_) => write!(f, "BROTLI"), - } - } -} -impl std::fmt::Display for HTTP2Decompresser { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self { - HTTP2Decompresser::UNASSIGNED => write!(f, "UNASSIGNED"), - HTTP2Decompresser::GZIP(_) => write!(f, "GZIP"), - HTTP2Decompresser::BROTLI(_) => write!(f, "BROTLI"), + HTTP2Decompresser::DEFLATE(_) => write!(f, "DEFLATE"), } } } @@ -114,6 +108,12 @@ impl GetMutCursor for GzDecoder { } } +impl GetMutCursor for DeflateDecoder { + fn get_mut(&mut self) -> &mut HTTP2cursor { + return self.get_mut(); + } +} + impl GetMutCursor for brotli::Decompressor { fn get_mut(&mut self) -> &mut HTTP2cursor { return self.get_mut(); @@ -171,6 +171,9 @@ impl HTTP2DecoderHalf { if *input == "gzip".as_bytes().to_vec() { self.encoding = HTTP2ContentEncoding::HTTP2ContentEncodingGzip; self.decoder = HTTP2Decompresser::GZIP(GzDecoder::new(HTTP2cursor::new())); + } else if *input == "deflate".as_bytes().to_vec() { + self.encoding = HTTP2ContentEncoding::HTTP2ContentEncodingDeflate; + self.decoder = HTTP2Decompresser::DEFLATE(DeflateDecoder::new(HTTP2cursor::new())); } else if *input == "br".as_bytes().to_vec() { self.encoding = HTTP2ContentEncoding::HTTP2ContentEncodingBr; self.decoder = HTTP2Decompresser::BROTLI(brotli::Decompressor::new( @@ -207,6 +210,16 @@ impl HTTP2DecoderHalf { } return r; } + HTTP2Decompresser::DEFLATE(ref mut df_decoder) => { + let r = http2_decompress(df_decoder, input, output); + match r { + Err(_) => { + self.decoder = HTTP2Decompresser::UNASSIGNED; + } + _ => {} + } + return r; + } _ => {} } return Ok(input);