Exemplo n.º 1
0
void
seahorse_gpgme_expires_new (SeahorseGpgmeSubkey *subkey, GtkWindow *parent)
{
	SeahorseWidget *swidget;
	GtkWidget *date, *expire;
	gulong expires;
	gchar *title;
	const gchar *label;
	
	g_return_if_fail (subkey != NULL && SEAHORSE_IS_GPGME_SUBKEY (subkey));

	swidget = seahorse_widget_new_allow_multiple ("expires", parent);
	g_return_if_fail (swidget != NULL);
	g_object_set_data_full (G_OBJECT (swidget), "subkey", 
	                        g_object_ref (subkey), g_object_unref);
	
	date = GTK_WIDGET (seahorse_widget_get_widget (swidget, "calendar"));
	g_return_if_fail (date != NULL);

	expire = GTK_WIDGET (seahorse_widget_get_widget (swidget, "expire"));
	expires = seahorse_pgp_subkey_get_expires (SEAHORSE_PGP_SUBKEY (subkey)); 
	if (!expires) {
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (expire), TRUE);
		gtk_widget_set_sensitive (date, FALSE);
	} else {
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (expire), FALSE);
		gtk_widget_set_sensitive (date, TRUE);
	}
    
	if (expires) {
		struct tm t;
		time_t time = (time_t)expires;
		if (gmtime_r (&time, &t)) {
			gtk_calendar_select_month (GTK_CALENDAR (date), t.tm_mon, t.tm_year + 1900);
			gtk_calendar_select_day (GTK_CALENDAR (date), t.tm_mday);
		}
	}
	
	label = seahorse_pgp_subkey_get_description (SEAHORSE_PGP_SUBKEY (subkey));
	title = g_strdup_printf (_("Expiry: %s"), label);
	gtk_window_set_title (GTK_WINDOW (seahorse_widget_get_widget (swidget, swidget->name)), title);
	g_free (title);
}
Exemplo n.º 2
0
static void
seahorse_pgp_subkey_finalize (GObject *gobject)
{
    SeahorsePgpSubkey *self = SEAHORSE_PGP_SUBKEY (gobject);
    SeahorsePgpSubkeyPrivate *priv
        = seahorse_pgp_subkey_get_instance_private (self);

    g_clear_pointer (&priv->algorithm, g_free);
    g_clear_pointer (&priv->fingerprint, g_free);
    g_clear_pointer (&priv->description, g_free);
    g_clear_pointer (&priv->keyid, g_free);

    G_OBJECT_CLASS (seahorse_pgp_subkey_parent_class)->finalize (gobject);
}
Exemplo n.º 3
0
G_MODULE_EXPORT void
on_gpgme_expire_ok_clicked (GtkButton *button,
                            gpointer user_data)
{
	SeahorseWidget *swidget = SEAHORSE_WIDGET (user_data);
	GtkWidget *widget; 
	SeahorseGpgmeSubkey *subkey;
	gpgme_error_t err;
	time_t expiry = 0;
	struct tm when;
	
	subkey = SEAHORSE_GPGME_SUBKEY (g_object_get_data (G_OBJECT (swidget), "subkey"));
	
	widget = GTK_WIDGET (seahorse_widget_get_widget (swidget, "expire"));
	if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
		
		memset (&when, 0, sizeof (when));            
		widget = GTK_WIDGET (seahorse_widget_get_widget (swidget, "calendar"));
		gtk_calendar_get_date (GTK_CALENDAR (widget), (guint*)&(when.tm_year), 
		                       (guint*)&(when.tm_mon), (guint*)&(when.tm_mday));
		when.tm_year -= 1900;
		expiry = mktime (&when);

		if (expiry <= time (NULL)) {
			seahorse_util_show_error (widget, _("Invalid expiry date"), 
			                          _("The expiry date must be in the future"));
			return;
		}
	}
	
	widget = seahorse_widget_get_widget (swidget, "all-controls");
	gtk_widget_set_sensitive (widget, FALSE);
	g_object_ref (swidget);
	g_object_ref (subkey);
	
	if (expiry != (time_t)seahorse_pgp_subkey_get_expires (SEAHORSE_PGP_SUBKEY (subkey))) {
		err = seahorse_gpgme_key_op_set_expires (subkey, expiry);
		if (!GPG_IS_OK (err))
			seahorse_gpgme_handle_error (err, _("Couldn't change expiry date"));
	}
    
	g_object_unref (subkey);
	g_object_unref (swidget);
	seahorse_widget_destroy (swidget);
}
Exemplo n.º 4
0
static void
seahorse_pgp_subkey_set_property (GObject *object, guint prop_id, const GValue *value,
                                  GParamSpec *pspec)
{
    SeahorsePgpSubkey *self = SEAHORSE_PGP_SUBKEY (object);

    switch (prop_id) {
    case PROP_INDEX:
        seahorse_pgp_subkey_set_index (self, g_value_get_uint (value));
        break;
    case PROP_KEYID:
        seahorse_pgp_subkey_set_keyid (self, g_value_get_string (value));
        break;
    case PROP_FLAGS:
        seahorse_pgp_subkey_set_flags (self, g_value_get_uint (value));
        break;
    case PROP_LENGTH:
        seahorse_pgp_subkey_set_length (self, g_value_get_uint (value));
        break;
    case PROP_ALGORITHM:
        seahorse_pgp_subkey_set_algorithm (self, g_value_get_string (value));
        break;
    case PROP_CREATED:
        seahorse_pgp_subkey_set_created (self, g_value_get_ulong (value));
        break;
    case PROP_EXPIRES:
        seahorse_pgp_subkey_set_expires (self, g_value_get_ulong (value));
        break;
    case PROP_FINGERPRINT:
        seahorse_pgp_subkey_set_fingerprint (self, g_value_get_string (value));
        break;
    case PROP_DESCRIPTION:
        seahorse_pgp_subkey_set_description (self, g_value_get_string (value));
        break;
    }
}
Exemplo n.º 5
0
void
seahorse_gpgme_revoke_new (SeahorseGpgmeSubkey *subkey, GtkWindow *parent)
{
	SeahorseWidget *swidget;
	gchar *title;
	const gchar *label;
	GtkWidget *widget;
	GtkListStore *store;
	GtkTreeIter iter;
	GtkCellRenderer *renderer;
	
	g_return_if_fail (SEAHORSE_IS_GPGME_SUBKEY (subkey));
	
	swidget = seahorse_widget_new ("revoke", parent);
	g_return_if_fail (swidget != NULL);
	
	label = seahorse_pgp_subkey_get_description (SEAHORSE_PGP_SUBKEY (subkey));
	title = g_strdup_printf (_("Revoke: %s"), label);
	gtk_window_set_title (GTK_WINDOW (seahorse_widget_get_widget (swidget, swidget->name)), title);
	g_free (title);
	
	g_object_set_data (G_OBJECT (swidget), "subkey", subkey);

	/* Initialize List Store for the Combo Box */
	store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
    
	gtk_list_store_append (store, &iter);
	gtk_list_store_set (store, &iter,
	                    COLUMN_TEXT, _("No reason"),
	                    COLUMN_TOOLTIP, _("No reason for revoking key"),
	                    COLUMN_INT, REVOKE_NO_REASON,
	                    -1);
                        
	gtk_list_store_append (store, &iter);
	gtk_list_store_set (store, &iter,
	                    COLUMN_TEXT, _("Compromised"),
	                    COLUMN_TOOLTIP, _("Key has been compromised"),
	                    COLUMN_INT, REVOKE_COMPROMISED,
	                    -1);     
	
	gtk_list_store_append (store, &iter);
	gtk_list_store_set (store, &iter,
	                    COLUMN_TEXT, _("Superseded"),
	                    COLUMN_TOOLTIP, _("Key has been superseded"),
	                    COLUMN_INT, REVOKE_SUPERSEDED,
	                    -1);

	gtk_list_store_append (store, &iter);
	gtk_list_store_set (store, &iter,
	                    COLUMN_TEXT, _("Not Used"),
	                    COLUMN_TOOLTIP, _("Key is no longer used"),
	                    COLUMN_INT, REVOKE_NOT_USED,
	                    -1);
                        
	/* Finish Setting Up Combo Box */
	widget = GTK_WIDGET (seahorse_widget_get_widget (swidget, "reason"));
    
	gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
	gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
    
	renderer = gtk_cell_renderer_text_new ();
	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, TRUE);
	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget), renderer,
	                                "text", COLUMN_TEXT,
	                                NULL);
}
Exemplo n.º 6
0
void
seahorse_gpgme_subkey_set_subkey (SeahorseGpgmeSubkey *self, gpgme_subkey_t subkey)
{
	gchar *description, *fingerprint, *name;
	SeahorsePgpSubkey *base;
	const gchar *algo_type;
	GObject *obj;
	gpgme_subkey_t sub;
	gint i, index;
	guint flags;
	
	g_return_if_fail (SEAHORSE_IS_GPGME_SUBKEY (self));
	g_return_if_fail (subkey);
	
	/* Make sure that this subkey is in the pubkey */
	index = -1;
	for (i = 0, sub = self->pv->pubkey->subkeys; sub; ++i, sub = sub->next) {
		if(sub == subkey) {
			index = i;
			break;
		}
	}
	g_return_if_fail (index >= 0);
	
	/* Calculate the algorithm */
	algo_type = gpgme_pubkey_algo_name (subkey->pubkey_algo);
	if (algo_type == NULL)
		algo_type = C_("Algorithm", "Unknown");
	else if (g_str_equal ("Elg", algo_type) || g_str_equal("ELG-E", algo_type))
		algo_type = _("ElGamal");

	/* Additional properties */
	fingerprint = seahorse_pgp_subkey_calc_fingerprint (subkey->fpr);
	name = seahorse_gpgme_uid_calc_name (self->pv->pubkey->uids);
	description = seahorse_pgp_subkey_calc_description (name, index);
	
	self->pv->subkey = subkey;
	
	obj = G_OBJECT (self);
	g_object_freeze_notify (obj);
	
	base = SEAHORSE_PGP_SUBKEY (self);
	seahorse_pgp_subkey_set_index (base, index);
	seahorse_pgp_subkey_set_keyid (base, subkey->keyid);
	seahorse_pgp_subkey_set_algorithm (base, algo_type);
	seahorse_pgp_subkey_set_length (base, subkey->length);
	seahorse_pgp_subkey_set_description (base, description);
	seahorse_pgp_subkey_set_fingerprint (base, fingerprint);
	seahorse_pgp_subkey_set_created (base, subkey->timestamp);
	seahorse_pgp_subkey_set_expires (base, subkey->expires);
	
	/* The order below is significant */
	flags = 0;
	if (subkey->revoked)
		flags |= SEAHORSE_FLAG_REVOKED;
	if (subkey->expired)
		flags |= SEAHORSE_FLAG_EXPIRED;
	if (subkey->disabled)
		flags |= SEAHORSE_FLAG_DISABLED;
	if (flags == 0 && !subkey->invalid)
		flags |= SEAHORSE_FLAG_IS_VALID;
	if (subkey->can_encrypt)
		flags |= SEAHORSE_FLAG_CAN_ENCRYPT;
	if (subkey->can_sign)
		flags |= SEAHORSE_FLAG_CAN_SIGN;
	if (subkey->can_certify)
		flags |= SEAHORSE_FLAG_CAN_CERTIFY;
	if (subkey->can_authenticate)
		flags |= SEAHORSE_FLAG_CAN_AUTHENTICATE;
	
	seahorse_pgp_subkey_set_flags (base, flags);
	
	g_object_notify (obj, "subkey");
	g_object_thaw_notify (obj);
	
	g_free (description);
	g_free (name);
	g_free (fingerprint);
}