static gchar*
do_get_password (GckSession *session, const gchar *keyid, const gchar *errmsg,
                 const gchar *prompt_text, const gchar *description, gboolean confirm)
{
	GSettings *settings;
	gchar *password = NULL;
	GcrPrompt *prompt;
	gboolean chosen;
	GError *error = NULL;
	gint lifetime;
	gchar *method;
	gchar *label;
	gchar *text;

	g_assert (GCK_IS_SESSION (session));

	/* Do we have the keyid? */
	password = gkd_login_lookup_password (session, "keyid", keyid,
	                                      "source", "gnome-keyring:gpg-agent", NULL);
	if (password != NULL)
		return password;

	prompt = open_password_prompt (session, keyid, errmsg, prompt_text,
	                               description, confirm);
	if (prompt != NULL) {
		password = egg_secure_strdup (gcr_prompt_password (prompt, NULL, &error));
		if (password == NULL) {
			if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
				g_warning ("couldn't prompt for password: %s", egg_error_message (error));
			g_clear_error (&error);
		}
	}

	if (password != NULL && keyid != NULL) {
		settings = gkd_gpg_agent_settings ();

		/* Load up the save options */
		chosen = gcr_prompt_get_choice_chosen (prompt);

		if (chosen) {
			method = g_strdup (GCR_UNLOCK_OPTION_ALWAYS);
			lifetime = -1;

		} else {
			method = g_settings_get_string (settings, "gpg-cache-method");
			lifetime = g_settings_get_int (settings, "gpg-cache-ttl");
			if (g_str_equal (method, GCR_UNLOCK_OPTION_ALWAYS)) {
				g_free (method);
				method = NULL;
			}
		}

		/* Now actually save the password */
		text = calculate_label_for_key (keyid, description);
		label = g_strdup_printf (_("PGP Key: %s"), text);
		gkd_login_store_password (session, password, label, method, lifetime,
		                          "keyid", keyid, "source", "gnome-keyring:gpg-agent", NULL);
		g_free (label);
		g_free (method);
		g_free (text);
	}

	g_clear_object (&prompt);
	return password;
}
Beispiel #2
0
static gboolean
auto_unlock_should_attach (GkmWrapPrompt *self)
{
	return gcr_prompt_get_choice_chosen (GCR_PROMPT (self));
}