Blame SOURCES/0100-ureport-allow-multiple-cert-file-in-rhsm-entitlement.patch

562801
From 52928f385d8a0885ba7cc6a110d4ff6dc4ab91e6 Mon Sep 17 00:00:00 2001
562801
From: Jakub Filak <jfilak@redhat.com>
562801
Date: Wed, 22 Oct 2014 08:00:39 +0200
562801
Subject: [LIBREPORT PATCH 100/105] ureport: allow multiple cert file in
562801
 rhsm-entitlement dir
562801
562801
Thanks Martin Milata <mmilata@redhat.com>
562801
562801
https://bugzilla.redhat.com/show_bug.cgi?id=1140224#c6
562801
562801
Related to #1140224
562801
562801
Signed-off-by: Jakub Filak <jfilak@redhat.com>
562801
---
562801
 src/lib/ureport.c | 54 +++++++++++++++++++++++-------------------------------
562801
 1 file changed, 23 insertions(+), 31 deletions(-)
562801
562801
diff --git a/src/lib/ureport.c b/src/lib/ureport.c
562801
index 0e0472e..99e84ef 100644
562801
--- a/src/lib/ureport.c
562801
+++ b/src/lib/ureport.c
562801
@@ -103,52 +103,44 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
562801
             ureport_server_config_set_url(config, xstrdup(RHSM_WEB_SERVICE_URL));
562801
 
562801
         GList *certs = get_file_list(RHSMENT_PEM_DIR_PATH, "pem");
562801
-        if (g_list_length(certs) != 2)
562801
+        if (g_list_length(certs) < 2)
562801
         {
562801
+            g_list_free_full(certs, (GDestroyNotify)free_file_obj);
562801
+
562801
             log_notice(RHSMENT_PEM_DIR_PATH" does not contain unique cert-key files pair");
562801
             log_notice("Not using client authentication");
562801
             return;
562801
         }
562801
 
562801
-        const char *cert = NULL;
562801
-        const char *key = NULL;
562801
-
562801
-        file_obj_t *fst = (file_obj_t *)certs->data;
562801
-        file_obj_t *scn = (file_obj_t *)certs->next->data;
562801
-
562801
-        if (strlen(fo_get_filename(fst)) < strlen(fo_get_filename(scn)))
562801
+        /* Use the last non-key file found. */
562801
+        file_obj_t *cert = NULL;
562801
+        for (GList *iter = certs; iter != NULL; iter = g_list_next(iter))
562801
         {
562801
-            cert = fo_get_filename(fst);
562801
-            key = fo_get_filename(scn);
562801
+            file_obj_t *tmp = (file_obj_t *)iter->data;
562801
+            const char *file_name = fo_get_filename(tmp);
562801
 
562801
-            config->ur_client_cert = xstrdup(fo_get_fullpath(fst));
562801
-            config->ur_client_key = xstrdup(fo_get_fullpath(scn));
562801
+            if (suffixcmp(file_name, "-key"))
562801
+                cert = tmp;
562801
         }
562801
-        else
562801
+
562801
+        if (cert == NULL)
562801
         {
562801
-            cert = fo_get_filename(scn);
562801
-            key = fo_get_filename(fst);
562801
+            g_list_free_full(certs, (GDestroyNotify)free_file_obj);
562801
 
562801
-            config->ur_client_cert = xstrdup(fo_get_fullpath(scn));
562801
-            config->ur_client_key = xstrdup(fo_get_fullpath(fst));
562801
+            log_notice(RHSMENT_PEM_DIR_PATH" contains only key files");
562801
+            log_notice("Not using client authentication");
562801
+            return;
562801
         }
562801
 
562801
-        const bool iscomplement = prefixcmp(key, cert) != 0 || strcmp("-key", key + strlen(cert)) != 0;
562801
-        g_list_free_full(certs, (GDestroyNotify)free_file_obj);
562801
+        config->ur_client_cert = xstrdup(fo_get_fullpath(cert));
562801
+        /* Yes, the key file may not exists. I over took this code from
562801
+         * sos-uploader and they are pretty happy with this approach, so why
562801
+         * shouldn't we?. */
562801
+        config->ur_client_key = xasprintf("%s/%s-key.pem", RHSMENT_PEM_DIR_PATH, fo_get_filename(cert));
562801
 
562801
-        if (iscomplement)
562801
-        {
562801
-            log_notice("Key file '%s' isn't complement to cert file '%s'",
562801
-                    config->ur_client_key, config->ur_client_cert);
562801
-            log_notice("Not using client authentication");
562801
-
562801
-            free(config->ur_client_cert);
562801
-            free(config->ur_client_key);
562801
-            config->ur_client_cert = NULL;
562801
-            config->ur_client_key = NULL;
562801
+        log_debug("Using cert files: '%s' : '%s'", config->ur_client_cert, config->ur_client_key);
562801
 
562801
-            return;
562801
-        }
562801
+        g_list_free_full(certs, (GDestroyNotify)free_file_obj);
562801
 
562801
         char *certdata = xmalloc_open_read_close(config->ur_client_cert, /*no size limit*/NULL);
562801
         if (certdata != NULL)
562801
-- 
562801
1.8.3.1
562801