[gnome-software] trivial: Add gs_utils_get_user_hash()



commit 406daf09390ed216eed6721052b1c2e94e258d55
Author: Richard Hughes <richard hughsie com>
Date:   Tue Feb 9 18:55:52 2016 +0000

    trivial: Add gs_utils_get_user_hash()
    
    This helper function returns a salted hash string that is specific to the
    machine and the user.

 src/gs-utils.c |   27 +++++++++++++++++++++++++++
 src/gs-utils.h |    1 +
 2 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-utils.c b/src/gs-utils.c
index f972465..5709f9f 100644
--- a/src/gs-utils.c
+++ b/src/gs-utils.c
@@ -474,4 +474,31 @@ gs_utils_get_cachedir (const gchar *kind, GError **error)
        return g_steal_pointer (&cachedir);
 }
 
+/**
+ * gs_utils_get_user_hash:
+ *
+ * This SHA1 hash is composed of the contents of machine-id and your
+ * usename and is also salted with a hardcoded value.
+ *
+ * This provides an identifier that can be used to identify a specific
+ * user on a machine, allowing them to cast only one vote or perform
+ * one review on each application.
+ *
+ * There is no known way to calculate the machine ID or username from
+ * the machine hash and there should be no privacy issue.
+ */
+gchar *
+gs_utils_get_user_hash (GError **error)
+{
+       g_autofree gchar *data = NULL;
+       g_autofree gchar *salted = NULL;
+
+       if (!g_file_get_contents ("/etc/machine-id", &data, NULL, error))
+               return NULL;
+
+       salted = g_strdup_printf ("gnome-software[%s:%s]",
+                                 g_get_user_name (), data);
+       return g_compute_checksum_for_string (G_CHECKSUM_SHA1, salted, -1);
+}
+
 /* vim: set noexpandtab: */
diff --git a/src/gs-utils.h b/src/gs-utils.h
index 22a8ba5..54df901 100644
--- a/src/gs-utils.h
+++ b/src/gs-utils.h
@@ -62,6 +62,7 @@ const gchar    *gs_user_agent                 (void);
 
 gchar          *gs_utils_get_cachedir          (const gchar    *kind,
                                                 GError         **error);
+gchar          *gs_utils_get_user_hash         (GError         **error);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]