aboutsummaryrefslogtreecommitdiffstats
path: root/ui/summary.c
diff options
context:
space:
mode:
authorJaap Keuter <jaap.keuter@xs4all.nl>2018-11-06 22:34:09 +0100
committerAnders Broman <a.broman58@gmail.com>2018-11-07 11:43:13 +0000
commitc29c652eb95b7ee973e2e9ce444c0e3edd53cf75 (patch)
treeeedd63d5164af5831d9fab9370b012d9dcd3c763 /ui/summary.c
parent163e4637d50a7cda210de3af1e5de1eaed4cf727 (diff)
Qt: Add file hashes to capture file properties dialog
Like capinfos provide file hashes in the capture file properties dialog. Change-Id: Ia9f1b05f61abd239d81b7061bbba1e53c01f28be Signed-off-by: Jaap Keuter <jaap.keuter@xs4all.nl> Reviewed-on: https://code.wireshark.org/review/30524 Tested-by: Petri Dish Buildbot Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'ui/summary.c')
-rw-r--r--ui/summary.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/ui/summary.c b/ui/summary.c
index 3e35c3ad36..e3d73f3f9e 100644
--- a/ui/summary.c
+++ b/ui/summary.c
@@ -15,9 +15,18 @@
#include <wiretap/pcapng.h>
#include <epan/packet.h>
+#include <wsutil/file_util.h>
+#include <wsutil/wsgcrypt.h>
#include "cfile.h"
#include "ui/summary.h"
+// Strongest to weakest
+#define HASH_SIZE_SHA256 32
+#define HASH_SIZE_RMD160 20
+#define HASH_SIZE_SHA1 20
+
+#define HASH_BUF_SIZE (1024 * 1024)
+
static void
tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
{
@@ -86,6 +95,15 @@ tally_frame_data(frame_data *cur_frame, summary_tally *sum_tally)
}
}
+static void
+hash_to_str(const unsigned char *hash, size_t length, char *str) {
+ int i;
+
+ for (i = 0; i < (int) length; i++) {
+ g_snprintf(str+(i*2), 3, "%02x", hash[i]);
+ }
+}
+
void
summary_fill_in(capture_file *cf, summary_tally *st)
{
@@ -101,6 +119,11 @@ summary_fill_in(capture_file *cf, summary_tally *st)
char* if_string;
wtapng_if_descr_filter_t* if_filter;
+ FILE *fh;
+ char *hash_buf;
+ gcry_md_hd_t hd;
+ size_t hash_bytes;
+
st->packet_count_ts = 0;
st->start_time = 0;
st->stop_time = 0;
@@ -184,6 +207,31 @@ summary_fill_in(capture_file *cf, summary_tally *st)
g_array_append_val(st->ifaces, iface);
}
g_free(idb_info);
+
+ g_strlcpy(st->file_sha256, "<unknown>", HASH_STR_SIZE);
+ g_strlcpy(st->file_rmd160, "<unknown>", HASH_STR_SIZE);
+ g_strlcpy(st->file_sha1, "<unknown>", HASH_STR_SIZE);
+
+ gcry_md_open(&hd, GCRY_MD_SHA256, 0);
+ if (hd) {
+ gcry_md_enable(hd, GCRY_MD_RMD160);
+ gcry_md_enable(hd, GCRY_MD_SHA1);
+ }
+ hash_buf = (char *)g_malloc(HASH_BUF_SIZE);
+
+ fh = ws_fopen(cf->filename, "rb");
+ if (fh && hash_buf && hd) {
+ while((hash_bytes = fread(hash_buf, 1, HASH_BUF_SIZE, fh)) > 0) {
+ gcry_md_write(hd, hash_buf, hash_bytes);
+ }
+ gcry_md_final(hd);
+ hash_to_str(gcry_md_read(hd, GCRY_MD_SHA256), HASH_SIZE_SHA256, st->file_sha256);
+ hash_to_str(gcry_md_read(hd, GCRY_MD_RMD160), HASH_SIZE_RMD160, st->file_rmd160);
+ hash_to_str(gcry_md_read(hd, GCRY_MD_SHA1), HASH_SIZE_SHA1, st->file_sha1);
+ }
+ if (fh) fclose(fh);
+ g_free(hash_buf);
+ gcry_md_close(hd);
}
#ifdef HAVE_LIBPCAP