]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
bittorrent-dht: parse token and target as byte values
authorJason Ish <jason.ish@oisf.net>
Thu, 8 Sep 2022 14:59:11 +0000 (08:59 -0600)
committerVictor Julien <vjulien@oisf.net>
Fri, 28 Oct 2022 09:48:13 +0000 (11:48 +0200)
rust/src/bittorrent_dht/logger.rs
rust/src/bittorrent_dht/parser.rs

index 50a1a260877c2ffac5b9c91df9a4bf9353d3fc68..283f10332335f8e4cd16f0e62ed593b0dc3a0bff 100644 (file)
@@ -65,13 +65,13 @@ fn log_bittorrent_dht(
         js.open_object("request")?;
         js.set_hex("id", &request.id)?;
         if let Some(target) = &request.target {
-            js.set_string("target", target)?;
+            js.set_hex("target", target)?;
         }
         if let Some(info_hash) = &request.info_hash {
             js.set_hex("info_hash", info_hash)?;
         }
         if let Some(token) = &request.token {
-            js.set_string("token", token)?;
+            js.set_hex("token", token)?;
         }
         if let Some(implied_port) = request.implied_port {
             js.set_uint("implied_port", u64::from(implied_port))?;
index b72c5aee9a8322632374961fb205ecdacaf8f1c3..cdb0db45dc4f8ff72a3c0cb8d4c1b19302e9db70 100644 (file)
@@ -32,11 +32,11 @@ pub struct BitTorrentDHTRequest {
     /// q = * - 20 byte string, sender's node ID in network byte order
     pub id: Vec<u8>,
     /// q = find_node - target node ID
-    pub target: Option<String>,
+    pub target: Option<Vec<u8>>,
     /// q = get_peers/announce_peer - 20-byte info hash of target torrent
     pub info_hash: Option<Vec<u8>>,
     /// q = announce_peer - token key received from previous get_peers query
-    pub token: Option<String>,
+    pub token: Option<Vec<u8>>,
     /// q = announce_peer - 0 or 1, if 1 ignore provided port and
     ///                     use source port of UDP packet
     pub implied_port: Option<u8>,
@@ -125,9 +125,10 @@ impl FromBencode for BitTorrentDHTRequest {
                     id = value.try_into_bytes().context("id").map(Some)?;
                 }
                 (b"target", value) => {
-                    target = String::decode_bencode_object(value)
+                    target = value
+                        .try_into_bytes()
                         .context("target")
-                        .map(Some)?;
+                        .map(|v| Some(v.to_vec()))?;
                 }
                 (b"info_hash", value) => {
                     info_hash = value
@@ -136,9 +137,10 @@ impl FromBencode for BitTorrentDHTRequest {
                         .map(|v| Some(v.to_vec()))?;
                 }
                 (b"token", value) => {
-                    token = String::decode_bencode_object(value)
+                    token = value
+                        .try_into_bytes()
                         .context("token")
-                        .map(Some)?;
+                        .map(|v| Some(v.to_vec()))?;
                 }
                 (b"implied_port", value) => {
                     implied_port = u8::decode_bencode_object(value)