From 1fd5b957e653a97b41434430ec234d9536b9e9f3 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 23 Jul 2022 10:28:22 +0200 Subject: [PATCH] Added VirusTotal result dialog --- .../java/eu/faircode/email/VirusTotal.java | 18 +++-- .../eu/faircode/email/AdapterAttachment.java | 35 +++++++++- .../main/res/layout/dialog_virus_total.xml | 67 +++++++++++++++++++ 3 files changed, 113 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/layout/dialog_virus_total.xml diff --git a/app/src/extra/java/eu/faircode/email/VirusTotal.java b/app/src/extra/java/eu/faircode/email/VirusTotal.java index e006aba8c7..7a010f57ec 100644 --- a/app/src/extra/java/eu/faircode/email/VirusTotal.java +++ b/app/src/extra/java/eu/faircode/email/VirusTotal.java @@ -52,8 +52,11 @@ public class VirusTotal { hash = Helper.getHash(is, "SHA-256"); } + String uri = URI_ENDPOINT + "gui/file/" + hash; + Log.i("VT uri=" + uri); + Bundle result = new Bundle(); - result.putString("uri", URI_ENDPOINT + "gui/file/" + hash); + result.putString("uri", uri); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String apikey = prefs.getString("vt_apikey", null); @@ -83,7 +86,10 @@ public class VirusTotal { throw new FileNotFoundException(error); } - if (status == HttpsURLConnection.HTTP_OK) { + if (status == HttpsURLConnection.HTTP_NOT_FOUND) { + result.putInt("count", 0); + result.putInt("malicious", 0); + } else { String response = Helper.readStream(connection.getInputStream()); Log.i("VT response=" + response); @@ -93,8 +99,8 @@ public class VirusTotal { JSONObject jdata = jroot.getJSONObject("data"); JSONObject jattributes = jdata.getJSONObject("attributes"); - JSONObject jclassification = jattributes.getJSONObject("popular_threat_classification"); - String label = jclassification.getString("suggested_threat_label"); + JSONObject jclassification = jattributes.optJSONObject("popular_threat_classification"); + String label = (jclassification == null ? null : jclassification.getString("suggested_threat_label")); int count = 0; int malicious = 0; @@ -111,11 +117,11 @@ public class VirusTotal { malicious++; } - Log.i("VT label=" + label + " " + malicious + "/" + count); + Log.i("VT analysis=" + malicious + "/" + count + " label=" + label); - result.putString("label", label); result.putInt("count", count); result.putInt("malicious", malicious); + result.putString("label", label); } } finally { connection.disconnect(); diff --git a/app/src/main/java/eu/faircode/email/AdapterAttachment.java b/app/src/main/java/eu/faircode/email/AdapterAttachment.java index 1163744f56..b69e728f82 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAttachment.java +++ b/app/src/main/java/eu/faircode/email/AdapterAttachment.java @@ -20,6 +20,7 @@ package eu.faircode.email; */ import android.content.Context; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; @@ -36,6 +37,7 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; import androidx.core.content.FileProvider; import androidx.fragment.app.Fragment; import androidx.lifecycle.Lifecycle; @@ -330,7 +332,38 @@ public class AdapterAttachment extends RecyclerView.Adapter + + + + + + + + + + + + + + +