From 4f3bf1b2ce9d098061b4a0b95e5b86313b7135ce Mon Sep 17 00:00:00 2001 From: Max Jakobitsch Date: Wed, 6 Sep 2023 13:52:26 +0200 Subject: [PATCH 1/5] fix: only un-gzip for Content-Encoding: gzip --- .../aaronjwood/portauthority/async/DownloadAsyncTask.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/aaronjwood/portauthority/async/DownloadAsyncTask.java b/app/src/main/java/com/aaronjwood/portauthority/async/DownloadAsyncTask.java index 149e3f8..0d481c0 100644 --- a/app/src/main/java/com/aaronjwood/portauthority/async/DownloadAsyncTask.java +++ b/app/src/main/java/com/aaronjwood/portauthority/async/DownloadAsyncTask.java @@ -11,6 +11,7 @@ import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.lang.ref.WeakReference; import java.nio.charset.StandardCharsets; @@ -95,7 +96,11 @@ final void doInBackground(String service, Parser parser) { return; } - in = new BufferedReader(new InputStreamReader(new GZIPInputStream(body.byteStream()), StandardCharsets.UTF_8)); + InputStream bodyStream = body.byteStream(); + if ("gzip".equals(response.header("Content-Encoding"))) { + bodyStream = new GZIPInputStream(bodyStream); + } + in = new BufferedReader(new InputStreamReader(bodyStream, StandardCharsets.UTF_8)); String line; long total = 0; while ((line = in.readLine()) != null) { From 4f4e7117b614800e6bf4b508a44daccf146d776f Mon Sep 17 00:00:00 2001 From: Max Jakobitsch Date: Wed, 6 Sep 2023 13:53:58 +0200 Subject: [PATCH 2/5] fix: oui data new format has the first two fields padded with spaces in addition to separation by tabs --- .../aaronjwood/portauthority/async/DownloadOuisAsyncTask.java | 3 +-- .../java/com/aaronjwood/portauthority/parser/OuiParser.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/aaronjwood/portauthority/async/DownloadOuisAsyncTask.java b/app/src/main/java/com/aaronjwood/portauthority/async/DownloadOuisAsyncTask.java index 32988d9..4182b2d 100644 --- a/app/src/main/java/com/aaronjwood/portauthority/async/DownloadOuisAsyncTask.java +++ b/app/src/main/java/com/aaronjwood/portauthority/async/DownloadOuisAsyncTask.java @@ -9,8 +9,7 @@ public class DownloadOuisAsyncTask extends DownloadAsyncTask { - // The official source on gitlab.com doesn't provide a content length header which ruins our ability to report progress! - private static final String SERVICE = "https://raw.githubusercontent.com/wireshark/wireshark/master/manuf"; + private static final String SERVICE = "https://www.wireshark.org/download/automated/data/manuf"; /** * Creates a new asynchronous task to handle downloading OUI data. diff --git a/app/src/main/java/com/aaronjwood/portauthority/parser/OuiParser.java b/app/src/main/java/com/aaronjwood/portauthority/parser/OuiParser.java index e6f673a..701f1c9 100644 --- a/app/src/main/java/com/aaronjwood/portauthority/parser/OuiParser.java +++ b/app/src/main/java/com/aaronjwood/portauthority/parser/OuiParser.java @@ -17,12 +17,12 @@ public String[] parseLine(String line) { } String[] data = line.split("\\t"); - String mac = data[0].toLowerCase(); + String mac = data[0].trim().toLowerCase(); String vendor; if (data.length == 3) { vendor = data[2]; } else { - vendor = data[1]; + vendor = data[1].trim(); } return new String[]{mac, vendor}; From d454f3d580a7dc96f8ad1a29c97b9a78cb7c3028 Mon Sep 17 00:00:00 2001 From: Max Jakobitsch Date: Wed, 6 Sep 2023 14:30:31 +0200 Subject: [PATCH 3/5] fix: ports data fetch original IANA csv --- .../async/DownloadPortDataAsyncTask.java | 2 +- .../portauthority/parser/PortParser.java | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/aaronjwood/portauthority/async/DownloadPortDataAsyncTask.java b/app/src/main/java/com/aaronjwood/portauthority/async/DownloadPortDataAsyncTask.java index 91f5a14..55b392f 100644 --- a/app/src/main/java/com/aaronjwood/portauthority/async/DownloadPortDataAsyncTask.java +++ b/app/src/main/java/com/aaronjwood/portauthority/async/DownloadPortDataAsyncTask.java @@ -9,7 +9,7 @@ public class DownloadPortDataAsyncTask extends DownloadAsyncTask { // The official source on iana.org doesn't provide a content length header which ruins our ability to report progress! - private static final String SERVICE = "https://raw.githubusercontent.com/wireshark/wireshark/master/services"; + private static final String SERVICE = "https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv"; /** * Creates a new asynchronous task that takes care of downloading port data. diff --git a/app/src/main/java/com/aaronjwood/portauthority/parser/PortParser.java b/app/src/main/java/com/aaronjwood/portauthority/parser/PortParser.java index dbe14e6..9c22a25 100644 --- a/app/src/main/java/com/aaronjwood/portauthority/parser/PortParser.java +++ b/app/src/main/java/com/aaronjwood/portauthority/parser/PortParser.java @@ -5,27 +5,27 @@ public class PortParser implements Parser { /** - * Parses the line of port data based on IANA's format. + * Parses the line of the port data CSV file provided by IANA. * * @param line * @return */ @Override public String[] parseLine(String line) { - if (line.isEmpty() || line.startsWith("#")) { + if (line.isEmpty() || line.startsWith(" ") || line.startsWith(",")) { return null; } - String[] data = line.split("\\s+"); - if (!data[1].contains("tcp")) { + String[] data = line.split(","); + if (data.length < 3 || !data[2].contains("tcp")) { return null; } - String port = data[1].substring(0, data[1].indexOf("/")); - String description = data[0]; - if (line.contains("#")) { - description = line.substring(line.indexOf("#") + 1); + String port = data[1]; + if (!port.matches("\\d+")){ + return null; } + String description = data.length >= 4 ? data[3] : data[0]; return new String[]{port, description}; } From 497867e63529e4d5df93b34a8b55f52aea224cf1 Mon Sep 17 00:00:00 2001 From: Max Jakobitsch Date: Wed, 6 Sep 2023 14:43:26 +0200 Subject: [PATCH 4/5] docs: add acknowledgements --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 8b11922..910f3b8 100644 --- a/README.md +++ b/README.md @@ -91,3 +91,10 @@ This means that modifications need to be done either on a new branch based off o This app does not track, collect, or share any data it comes across with anyone or anything. There are no ads or analytics trackers in this software. The service used to determine your public IP address is [open source](https://github.com/aaronjwood/public-ip-api) and is 100% stateless. + +## Acknowledgements + +MAC address vendor OUI resolution is possible thanks to the [lookup table](https://www.wireshark.org/download/automated/data/manuf) assembled by WireShark from IEEE public OUI listings. +See also [Wireshark's OUI Lookup Tool](https://www.wireshark.org/tools/oui-lookup.html). + +Port service names and descriptions are provided by the IANA as the [Service Name and Transport Protocol Port Number Registry](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml). From 84c28cb7bf268b44a701bf5f92713833d84af1ec Mon Sep 17 00:00:00 2001 From: Max Jakobitsch Date: Wed, 6 Sep 2023 15:12:03 +0200 Subject: [PATCH 5/5] fix: download progress for non-gzipped download --- .../portauthority/async/DownloadAsyncTask.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/aaronjwood/portauthority/async/DownloadAsyncTask.java b/app/src/main/java/com/aaronjwood/portauthority/async/DownloadAsyncTask.java index 0d481c0..79f700e 100644 --- a/app/src/main/java/com/aaronjwood/portauthority/async/DownloadAsyncTask.java +++ b/app/src/main/java/com/aaronjwood/portauthority/async/DownloadAsyncTask.java @@ -97,21 +97,24 @@ final void doInBackground(String service, Parser parser) { } InputStream bodyStream = body.byteStream(); - if ("gzip".equals(response.header("Content-Encoding"))) { + boolean gzipped = "gzip".equals(response.header("Content-Encoding")); + if (gzipped) { bodyStream = new GZIPInputStream(bodyStream); } in = new BufferedReader(new InputStreamReader(bodyStream, StandardCharsets.UTF_8)); - String line; + // Lean on the fact that we're working with UTF-8 here. + // Also, make a rough estimation of how much we need to reduce this to account for the compressed data we've received. + double progressPerByte = 100d / body.contentLength() * (gzipped ? 3 : 1); long total = 0; + String line; while ((line = in.readLine()) != null) { if (isCancelled()) { return; } - // Lean on the fact that we're working with UTF-8 here. - // Also, make a rough estimation of how much we need to reduce this to account for the compressed data we've received. - total += line.length() / 3; - downProg.progress = (int) (total * 100 / body.contentLength()); + total += line.length(); + downProg.progress = (int) (total * progressPerByte); + publishProgress(downProg); String[] data = parser.parseLine(line); if (data == null) {