示例#1
0
/* Verify a signed message */
static gchar*
verify_text (const gchar *text, SeahorseApplet *sapplet)
{
    gchar *rawtext = NULL;
    gchar *signer;
    gboolean ret;

    if (cryptui_keyset_get_count (dbus_keyset) == 0) {
        cryptui_need_to_get_keys (dbus_keyset);
        return NULL;
    }

    ret = dbus_g_proxy_call (dbus_crypto_proxy, "VerifyText", NULL,
                             G_TYPE_STRING, "openpgp",
                             G_TYPE_INT, 0,
                             G_TYPE_STRING, text,
                             G_TYPE_INVALID, 
                             G_TYPE_STRING, &rawtext,
                             G_TYPE_STRING, &signer,
                             G_TYPE_INVALID);
    
    if (ret) {
        /* Not interested in the signer */
        g_free (signer);
        return rawtext;
        
    } else {
        return NULL;
    }
}
示例#2
0
/* Decrypt an encrypted message */
static gchar*
decrypt_text (const gchar *text, SeahorseApplet *sapplet)
{
    gchar *rawtext = NULL;
    gchar *signer = NULL;
    gboolean ret;
    GError *err = NULL;
    
    if (cryptui_keyset_get_count (dbus_keyset) == 0) {
        cryptui_need_to_get_keys (dbus_keyset);
        return NULL;
    }
    
    ret = dbus_g_proxy_call (dbus_crypto_proxy, "DecryptText", &err,
                             G_TYPE_STRING, "openpgp",
                             G_TYPE_INT, 0,
                             G_TYPE_STRING, text,
                             G_TYPE_INVALID, 
                             G_TYPE_STRING, &rawtext,
                             G_TYPE_STRING, &signer,
                             G_TYPE_INVALID);

    if (ret) {
        g_free (signer);
        
        return rawtext;
    } else {
        notification_error (_("Signing Failed"), _("The clipboard could not be Signed."), 
                            sapplet, err);
        g_clear_error (&err);
        return NULL;
    }
}
static gpgme_key_t
prompt_signer ()
{
    gpgme_error_t gerr = 0;
    CryptUIKeyset *keyset;
    CryptUIKeyStore *ckstore;
    gpgme_key_t key = NULL;
    gpgme_ctx_t ctx = NULL;
    gchar *signer;
    gchar *id;
    guint count;
    GList *keys;

    keyset = cryptui_keyset_new ("openpgp", TRUE);
    ckstore = cryptui_key_store_new (keyset, TRUE, NULL);
    cryptui_key_store_set_filter (ckstore, signer_filter, NULL);

    count = cryptui_key_store_get_count (ckstore);

    if (count == 0) {
        cryptui_need_to_get_keys ();
        return NULL;
    } else if (count == 1) {
        keys = cryptui_key_store_get_all_keys (ckstore);
        signer = (gchar*) keys->data;
        g_list_free (keys);
    } else {
        signer = cryptui_prompt_signer (keyset, _("Choose Signer"));
    }

    if (signer) {

        id = cryptui_keyset_key_raw_keyid (keyset, signer);
        g_free (signer);

        gpgme_check_version (NULL);
        gerr = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
        g_return_val_if_fail (gerr == 0, NULL);

        gerr = gpgme_new (&ctx);
        g_return_val_if_fail (gerr == 0, NULL);

        /* Load up the GPGME secret key */
        gerr = gpgme_get_key (ctx, id, &key, 1);
        g_free (id);

        gpgme_release (ctx);

        if (gerr != 0)
            seahorse_util_handle_gpgme (gerr, _("Couldn't load keys"));
    }

    g_object_unref (ckstore);
    g_object_unref (keyset);
    return key;
}
示例#4
0
static void
encrypt_received (GtkClipboard *board, const gchar *text, SeahorseApplet *sapplet)
{
    gchar *signer = NULL;
    gchar *enctext = NULL;
    gchar **keys = NULL;
    gboolean ret;
    GError *err = NULL;

    /* No text on clipboard */
    if (!text)
        return;
 
    /* Get the recipient list */
    if (cryptui_keyset_get_count (dbus_keyset) == 0)
        cryptui_need_to_get_keys ();
    else
        keys = cryptui_prompt_recipients (dbus_keyset, _("Choose Recipient Keys"), &signer);

    /* User may have cancelled */
    if (keys && *keys) {
        ret = dbus_g_proxy_call (dbus_crypto_proxy, "EncryptText", &err, 
                                G_TYPE_STRV, keys, 
                                G_TYPE_STRING, signer, 
                                G_TYPE_INT, 0,
                                G_TYPE_STRING, text,
                                G_TYPE_INVALID,
                                G_TYPE_STRING, &enctext,
                                G_TYPE_INVALID);
    
        if (ret) {
            /* And finish up */
            gtk_clipboard_set_text (board, enctext, strlen (enctext));
            detect_received (board, enctext, sapplet);
            
            if (seahorse_gconf_get_boolean (DISPLAY_CLIPBOARD_ENC_KEY) == TRUE)
                display_text (_("Encrypted Text"), enctext, FALSE);
        } else {
        	notification_error (_("Encryption Failed"), _("The clipboard could not be encrypted."), 
        	                    sapplet, err);
        	g_clear_error (&err);
        }
        
        g_strfreev(keys);
        g_free (signer);
        g_free (enctext);
    }
}
示例#5
0
static void
sign_received (GtkClipboard *board, const gchar *text, SeahorseApplet *sapplet)
{
    gchar *signer = NULL;
    gchar *enctext = NULL;
    gboolean ret;
    GError *err = NULL;
    
    /* No text on clipboard */
    if (!text)
        return;

    if (cryptui_keyset_get_count (dbus_keyset) == 0)
        cryptui_need_to_get_keys (dbus_keyset);
    else
        signer = cryptui_prompt_signer (dbus_keyset, _("Choose Key to Sign with"));
    
    if (signer == NULL)
        return;

    /* Perform the signing */
    ret = dbus_g_proxy_call (dbus_crypto_proxy, "SignText", &err, 
                                G_TYPE_STRING, signer, 
                                G_TYPE_INT, 0,
                                G_TYPE_STRING, text,
                                G_TYPE_INVALID,
                                G_TYPE_STRING, &enctext,
                                G_TYPE_INVALID);
     
     if (ret) {                          
        /* And finish up */
        gtk_clipboard_set_text (board, enctext, strlen (enctext));
        detect_received (board, enctext, sapplet);

        if (seahorse_gconf_get_boolean (DISPLAY_CLIPBOARD_ENC_KEY) == TRUE)
            display_text (_("Signed Text"), enctext, FALSE);
    } else {
        notification_error (_("Signing Failed"), _("The clipboard could not be Signed."), 
                            sapplet, err);
        g_clear_error (&err);
    }
    
    g_free (signer);
    g_free (enctext);
}
static gpgme_key_t*
prompt_recipients (gpgme_key_t *signkey)
{
    gpgme_error_t gerr = 0;
    CryptUIKeyset *keyset;
    gpgme_ctx_t ctx;
    gpgme_key_t key;
    GArray *keys;
    gchar **recips;
    gchar *signer;

    *signkey = NULL;

    keyset = cryptui_keyset_new ("openpgp", TRUE);

    if (cryptui_keyset_get_count (keyset) == 0) {
        cryptui_need_to_get_keys ();
    } else {
        recips = cryptui_prompt_recipients (keyset, _("Choose Recipients"), &signer);

        if (recips) {
            gpgme_check_version (NULL);
            gerr = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP);
            g_return_val_if_fail (gerr == 0, NULL);

            gerr = gpgme_new (&ctx);
            g_return_val_if_fail (gerr == 0, NULL);

            if (signer) {
                /* Load up the GPGME secret key */
                gchar *id = cryptui_keyset_key_raw_keyid (keyset, signer);
                gerr = gpgme_get_key (ctx, id, signkey, 1);
                g_free (id);

                /* A more descriptive error message */
                if (GPG_ERR_EOF == gpgme_err_code (gerr))
                    gerr = gpgme_error (GPG_ERR_NOT_FOUND);
            }

            if (gerr == 0) {
                gchar **ids;
                guint num;

                /* Load up the GPGME keys */
                ids = cryptui_keyset_keys_raw_keyids (keyset, (const gchar**)recips);
                num = g_strv_length (ids);
                keys = g_array_new (TRUE, TRUE, sizeof (gpgme_key_t));
                gerr = gpgme_op_keylist_ext_start (ctx, (const gchar**)ids, 0, 0);
                g_free (ids);

                if (gerr == 0) {
                    while ((gerr = gpgme_op_keylist_next (ctx, &key)) == 0)
                        g_array_append_val (keys, key);
                    gpgme_op_keylist_end (ctx);
                }

                /* Ignore EOF error */
                if (GPG_ERR_EOF == gpgme_err_code (gerr))
                    gerr = 0;

                if (gerr == 0 && num != keys->len)
                    g_warning ("couldn't load all the keys (%d/%d) from GPGME", keys->len, num);
            }

            gpgme_release (ctx);
        }

        g_object_unref (keyset);

        if (!recips)
            return NULL;

        g_strfreev (recips);
        g_free (signer);

        if (gerr == 0 && keys->len)
            return (gpgme_key_t*)g_array_free (keys, FALSE);

        /* When failure, free all our return values */
        seahorse_util_free_keys ((gpgme_key_t*)g_array_free (keys, FALSE));
        if (*signkey)
            gpgme_key_unref (*signkey);

        seahorse_util_handle_gpgme (gerr, _("Couldn't load keys"));
    }

    return NULL;
}