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