summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2020-02-13 02:58:24 +0000
committerPeter Wu <peter@lekensteyn.nl>2020-02-13 02:58:24 +0000
commit3e53646d7fc3247b72585ac686eaa5bc1e154a4d (patch)
treee3a5070c5468a3334991a4595e001762809b9911
parentf7d2c4e7bdc77e34de5795872d8cb2397e4c9033 (diff)
downloadwireshark-notes-3e53646d7fc3247b72585ac686eaa5bc1e154a4d.tar.gz
lua/doh-get.lua: fix base64url decoding
Avoids malformed packet exception with certain unpadded values. See also https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=16386
-rw-r--r--lua/doh-get.lua15
1 files changed, 15 insertions, 0 deletions
diff --git a/lua/doh-get.lua b/lua/doh-get.lua
index e36ca1c..d95b542 100644
--- a/lua/doh-get.lua
+++ b/lua/doh-get.lua
@@ -11,6 +11,18 @@ local media_type = DissectorTable.get("media_type")
local http_path = Field.new("http.request.uri")
local http2_path = Field.new("http2.headers.path")
+-- Converts "base64url" to standard "base64" encoding.
+local function from_base64url(b64url)
+ local lastlen = string.len(b64url) % 4
+ local b64 = string.gsub(string.gsub(b64url, "-", "+"), "_", "/")
+ if lastlen == 3 then
+ b64 = b64 .. "="
+ elseif lastlen == 2 then
+ b64 = b64 .. "=="
+ end
+ return b64
+end
+
function doh_get.dissector(tvb, pinfo, tree)
local path = http2_path() or http_path()
if not path then
@@ -26,6 +38,9 @@ function doh_get.dissector(tvb, pinfo, tree)
return
end
+ -- Convert base64url to standard base64 with +/ and padding
+ dns_b64 = from_base64url(dns_b64)
+
local dns_tvb = ByteArray.new(dns_b64, true):base64_decode():tvb("Base64-decoded DNS")
-- Allow HTTP GET line to be replaced with the DNS one in the Info column.