static const gchar * parse_cert_option_as_pem (JsonObject *options, const gchar *option, GString *pem) { const gchar *problem = NULL; const gchar *file; const gchar *data; gchar *path; problem = parse_option_file_or_data (options, option, &file, &data); if (problem) return problem; if (file) { path = expand_filename (file); /* For now we assume file contents are PEM */ problem = load_pem_contents (path, option, pem); g_free (path); } else if (data) { /* Format this as PEM of the given type */ g_string_append (pem, data); g_string_append_c (pem, '\n'); } return problem; }
static gboolean parse_cert_option_as_pem (CockpitChannel *self, JsonObject *options, const gchar *option, GString *pem) { gboolean ret = TRUE; const gchar *file; const gchar *data; gchar *path; if (!parse_option_file_or_data (self, options, option, &file, &data)) return FALSE; if (file) { path = expand_filename (file); /* For now we assume file contents are PEM */ ret = load_pem_contents (self, path, option, pem); g_free (path); } else if (data) { /* Format this as PEM of the given type */ g_string_append (pem, data); g_string_append_c (pem, '\n'); } return ret; }
static const gchar * parse_cert_option_as_database (JsonObject *options, const gchar *option, GTlsDatabase **database) { gboolean temporary = FALSE; GError *error = NULL; const gchar *problem; const gchar *file; const gchar *data; gchar *path; gint fd; problem = parse_option_file_or_data (options, option, &file, &data); if (problem) return problem; if (file) { path = expand_filename (file); problem = NULL; } else if (data) { temporary = TRUE; path = g_build_filename (g_get_user_runtime_dir (), "cockpit-bridge-cert-authority.XXXXXX", NULL); fd = g_mkstemp (path); if (fd < 0) { g_warning ("couldn't create temporary directory: %s: %s", path, g_strerror (errno)); problem = "internal-error"; } else { close (fd); if (!g_file_set_contents (path, data, -1, &error)) { g_warning ("couldn't write temporary data to: %s: %s", path, error->message); problem = "internal-error"; g_clear_error (&error); } } } else { /* Not specified */ *database = NULL; return NULL; } if (problem == NULL) { *database = g_tls_file_database_new (path, &error); if (error) { g_warning ("couldn't load certificate data: %s: %s", path, error->message); problem = "internal-error"; g_clear_error (&error); } } /* Leave around when problem, for debugging */ if (temporary && problem == NULL) g_unlink (path); g_free (path); return problem; }