]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
quic: log user agent when available
authorVictor Julien <vjulien@oisf.net>
Sun, 16 Jan 2022 13:07:21 +0000 (14:07 +0100)
committerVictor Julien <vjulien@oisf.net>
Wed, 19 Jan 2022 13:10:50 +0000 (14:10 +0100)
rust/src/quic/logger.rs
rust/src/quic/quic.rs

index 6d981fa514df153008bc0165badc03992ba2c008..19426776dd017e62fd9dc9b254ce0ef3d72a036f 100644 (file)
@@ -26,6 +26,9 @@ fn log_template(tx: &QuicTransaction, js: &mut JsonBuilder) -> Result<(), JsonEr
         if let Some(sni) = &tx.sni {
             js.set_string("sni", &String::from_utf8_lossy(&sni))?;
         }
+        if let Some(ua) = &tx.ua {
+            js.set_string("ua", &String::from_utf8_lossy(&ua))?;
+        }
     }
     js.open_array("cyu")?;
     for cyu in &tx.cyu {
index 35876d21522272bc0668bccde4b354cebc80f1df..8b16765f877b19e9522583aa5a25b953bb5d2e0b 100644 (file)
@@ -34,17 +34,19 @@ pub struct QuicTransaction {
     pub header: QuicHeader,
     pub cyu: Vec<Cyu>,
     pub sni: Option<Vec<u8>>,
+    pub ua: Option<Vec<u8>>,
     tx_data: AppLayerTxData,
 }
 
 impl QuicTransaction {
-    fn new(header: QuicHeader, data: QuicData, sni: Option<Vec<u8>>) -> Self {
+    fn new(header: QuicHeader, data: QuicData, sni: Option<Vec<u8>>, ua: Option<Vec<u8>>) -> Self {
         let cyu = Cyu::generate(&header, &data.frames);
         QuicTransaction {
             tx_id: 0,
             header,
             cyu,
             sni,
+            ua,
             tx_data: AppLayerTxData::new(),
         }
     }
@@ -84,8 +86,8 @@ impl QuicState {
         self.transactions.iter().find(|&tx| tx.tx_id == tx_id + 1)
     }
 
-    fn new_tx(&mut self, header: QuicHeader, data: QuicData, sni: Option<Vec<u8>>) -> QuicTransaction {
-        let mut tx = QuicTransaction::new(header, data, sni);
+    fn new_tx(&mut self, header: QuicHeader, data: QuicData, sni: Option<Vec<u8>>, ua: Option<Vec<u8>>) -> QuicTransaction {
+        let mut tx = QuicTransaction::new(header, data, sni, ua);
         self.max_tx_id += 1;
         tx.tx_id = self.max_tx_id;
         return tx;
@@ -117,12 +119,17 @@ impl QuicState {
                     // no tx for the short header (data) frames
                     if header.ty != QuicType::Short {
                         let mut sni : Option<Vec<u8>> = None;
+                        let mut ua : Option<Vec<u8>> = None;
                         for frame in &data.frames {
                             if let Frame::Stream(s) = frame {
                                 if let Some(tags) = &s.tags {
                                     for (tag, value) in tags {
                                         if tag == &StreamTag::Sni {
                                             sni = Some(value.to_vec());
+                                        } else if tag == &StreamTag::Uaid {
+                                            ua = Some(value.to_vec());
+                                        }
+                                        if sni.is_some() && ua.is_some() {
                                             break;
                                         }
                                     }
@@ -130,7 +137,7 @@ impl QuicState {
                             }
                         }
 
-                        let transaction = self.new_tx(header, data, sni);
+                        let transaction = self.new_tx(header, data, sni, ua);
                         self.transactions.push(transaction);
                     }
                     return true;