|
|
562801 |
From 2b20c9f91342da7744ae40ee623735ab95f83219 Mon Sep 17 00:00:00 2001
|
|
|
562801 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
562801 |
Date: Wed, 22 Oct 2014 14:27:00 +0200
|
|
|
562801 |
Subject: [LIBREPORT PATCH 102/105] ureport: get rhsm entitlement cert dir from
|
|
|
562801 |
rhsm conf
|
|
|
562801 |
|
|
|
562801 |
Related #1140224
|
|
|
562801 |
|
|
|
562801 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
562801 |
---
|
|
|
562801 |
src/lib/ureport.c | 46 +++++++++++++++++++++++++++++++++++++++++-----
|
|
|
562801 |
1 file changed, 41 insertions(+), 5 deletions(-)
|
|
|
562801 |
|
|
|
562801 |
diff --git a/src/lib/ureport.c b/src/lib/ureport.c
|
|
|
562801 |
index 5782b4e..41f4531 100644
|
|
|
562801 |
--- a/src/lib/ureport.c
|
|
|
562801 |
+++ b/src/lib/ureport.c
|
|
|
562801 |
@@ -32,7 +32,6 @@
|
|
|
562801 |
|
|
|
562801 |
#define RHSM_WEB_SERVICE_URL "https://api.access.redhat.com/rs/telemetry/abrt"
|
|
|
562801 |
|
|
|
562801 |
-#define RHSMENT_PEM_DIR_PATH "/etc/pki/entitlement"
|
|
|
562801 |
#define RHSMENT_ENT_DATA_BEGIN_TAG "-----BEGIN ENTITLEMENT DATA-----"
|
|
|
562801 |
#define RHSMENT_ENT_DATA_END_TAG "-----END ENTITLEMENT DATA-----"
|
|
|
562801 |
#define RHSMENT_SIG_DATA_BEGIN_TAG "-----BEGIN RSA SIGNATURE-----"
|
|
|
562801 |
@@ -69,6 +68,33 @@ ureport_server_config_set_url(struct ureport_server_config *config,
|
|
|
562801 |
config->ur_url = server_url;
|
|
|
562801 |
}
|
|
|
562801 |
|
|
|
562801 |
+static char *
|
|
|
562801 |
+rhsm_config_get_entitlement_cert_dir(void)
|
|
|
562801 |
+{
|
|
|
562801 |
+ char *result = getenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH");
|
|
|
562801 |
+ if (result != NULL)
|
|
|
562801 |
+ return xstrdup(result);
|
|
|
562801 |
+
|
|
|
562801 |
+ result = run_in_shell_and_save_output(0,
|
|
|
562801 |
+ "python -c \"from rhsm.config import initConfig; print(initConfig().get('rhsm', 'entitlementCertDir'))\"",
|
|
|
562801 |
+ NULL, NULL);
|
|
|
562801 |
+
|
|
|
562801 |
+ /* run_in_shell_and_save_output always returns non-NULL */
|
|
|
562801 |
+ if (result[0] != '/')
|
|
|
562801 |
+ goto error;
|
|
|
562801 |
+
|
|
|
562801 |
+ char *newline = strchrnul(result, '\n');
|
|
|
562801 |
+ if (!newline)
|
|
|
562801 |
+ goto error;
|
|
|
562801 |
+
|
|
|
562801 |
+ *newline = '\0';
|
|
|
562801 |
+ return result;
|
|
|
562801 |
+error:
|
|
|
562801 |
+ error_msg("Failed to get 'rhsm':'entitlementCertDir' from rhsm.config python module.");
|
|
|
562801 |
+ free(result);
|
|
|
562801 |
+ return NULL;
|
|
|
562801 |
+}
|
|
|
562801 |
+
|
|
|
562801 |
void
|
|
|
562801 |
ureport_server_config_set_client_auth(struct ureport_server_config *config,
|
|
|
562801 |
const char *client_auth)
|
|
|
562801 |
@@ -91,13 +117,21 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
|
|
|
562801 |
if (config->ur_url == NULL)
|
|
|
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 |
+ char *rhsm_dir = rhsm_config_get_entitlement_cert_dir();
|
|
|
562801 |
+ if (rhsm_dir == NULL)
|
|
|
562801 |
+ {
|
|
|
562801 |
+ log_notice("Not using client authentication");
|
|
|
562801 |
+ return;
|
|
|
562801 |
+ }
|
|
|
562801 |
+
|
|
|
562801 |
+ GList *certs = get_file_list(rhsm_dir, "pem");
|
|
|
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("'%s' does not contain a cert-key files pair", rhsm_dir);
|
|
|
562801 |
log_notice("Not using client authentication");
|
|
|
562801 |
+ free(rhsm_dir);
|
|
|
562801 |
return;
|
|
|
562801 |
}
|
|
|
562801 |
|
|
|
562801 |
@@ -116,8 +150,9 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
|
|
|
562801 |
{
|
|
|
562801 |
g_list_free_full(certs, (GDestroyNotify)free_file_obj);
|
|
|
562801 |
|
|
|
562801 |
- log_notice(RHSMENT_PEM_DIR_PATH" contains only key files");
|
|
|
562801 |
+ log_notice("'%s' does not contain a cert file (only keys)", rhsm_dir);
|
|
|
562801 |
log_notice("Not using client authentication");
|
|
|
562801 |
+ free(rhsm_dir);
|
|
|
562801 |
return;
|
|
|
562801 |
}
|
|
|
562801 |
|
|
|
562801 |
@@ -125,7 +160,8 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
|
|
|
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 |
+ config->ur_client_key = xasprintf("%s/%s-key.pem", rhsm_dir, fo_get_filename(cert));
|
|
|
562801 |
+ free(rhsm_dir);
|
|
|
562801 |
|
|
|
562801 |
log_debug("Using cert files: '%s' : '%s'", config->ur_client_cert, config->ur_client_key);
|
|
|
562801 |
|
|
|
562801 |
--
|
|
|
562801 |
1.8.3.1
|
|
|
562801 |
|