]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http2: support deflate decompression 6348/head
authorPhilippe Antoine <contact@catenacyber.fr>
Mon, 5 Jul 2021 09:18:26 +0000 (11:18 +0200)
committerPhilippe Antoine <contact@catenacyber.fr>
Mon, 6 Sep 2021 19:37:17 +0000 (21:37 +0200)
cf #4556

(cherry picked from commit 1378b2f45144676d98f3430728dcca3e09540921)

rust/src/http2/decompression.rs

index 96dbd11e87feb0bf3b88794cb69216d6b1e8c372..74637e0f9a73584ceb1e9f603397c4f3c88e5ac3 100644 (file)
@@ -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<HTTP2cursor>),
     BROTLI(brotli::Decompressor<HTTP2cursor>),
+    DEFLATE(DeflateDecoder<HTTP2cursor>),
 }
 
 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<HTTP2cursor> {
     }
 }
 
+impl GetMutCursor for DeflateDecoder<HTTP2cursor> {
+    fn get_mut(&mut self) -> &mut HTTP2cursor {
+        return self.get_mut();
+    }
+}
+
 impl GetMutCursor for brotli::Decompressor<HTTP2cursor> {
     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);