static void add_key (SeahorseHKPSource *ssrc, SeahorsePgpKey *key) { SeahorseObject *prev; GQuark keyid; keyid = seahorse_pgp_key_canonize_id (seahorse_pgp_key_get_keyid (key)); prev = seahorse_context_get_object (SCTX_APP (), SEAHORSE_SOURCE (ssrc), keyid); if (prev != NULL) { g_return_if_fail (SEAHORSE_IS_PGP_KEY (prev)); seahorse_pgp_key_set_uids (SEAHORSE_PGP_KEY (prev), seahorse_pgp_key_get_uids (key)); seahorse_pgp_key_set_subkeys (SEAHORSE_PGP_KEY (prev), seahorse_pgp_key_get_subkeys (key)); return; } /* Add to context */ seahorse_object_set_source (SEAHORSE_OBJECT (key), SEAHORSE_SOURCE (ssrc)); seahorse_context_add_object (SCTX_APP (), SEAHORSE_OBJECT (key)); }
guint seahorse_pgp_signature_get_sigtype (SeahorsePgpSignature *self) { SeahorseObject *sobj; GQuark id; g_return_val_if_fail (SEAHORSE_IS_PGP_SIGNATURE (self), 0); id = seahorse_pgp_key_canonize_id (self->pv->keyid); sobj = seahorse_context_find_object (SCTX_APP (), id, SEAHORSE_LOCATION_LOCAL); if (sobj) { if (seahorse_object_get_usage (sobj) == SEAHORSE_USAGE_PRIVATE_KEY) return SKEY_PGPSIG_TRUSTED | SKEY_PGPSIG_PERSONAL; if (seahorse_object_get_flags (sobj) & SEAHORSE_FLAG_TRUSTED) return SKEY_PGPSIG_TRUSTED; } return 0; }
/** * seahorse_service_crypto_verify_text: * @crypto: #SeahorseServiceCrypto context * @ktype: "openpgp" * @flags: FLAG_QUIET for no notification * @crypttext: the text to decrypt * @cleartext: the plaintext after verification (out) * @signer: the signer if the text is signed (out) * @error: a potential error (out) * * DBus: VerifyText * * Decrypts the @crypttext and returns it in @cleartext. If the text * was signed, the signed is returned. * * Returns: TRUE on success */ gboolean seahorse_service_crypto_verify_text (SeahorseServiceCrypto *crypto, const gchar *ktype, int flags, const gchar *crypttext, gchar **cleartext, char **signer, GError **error) { gpgme_verify_result_t status; gpgme_error_t gerr; SeahorseGpgmeOperation *pop; gpgme_data_t plain, cipher; gboolean ret = TRUE; GQuark keyid; if (!g_str_equal (ktype, g_quark_to_string (SEAHORSE_PGP))) { g_set_error (error, SEAHORSE_DBUS_ERROR, SEAHORSE_DBUS_ERROR_INVALID, _("Invalid key type for verifying: %s"), ktype); return FALSE; } /* * TODO: Once we support different kinds of keys that support encryption * then all this logic will need to change. */ pop = seahorse_gpgme_operation_new (NULL); /* new data from text */ gerr = gpgme_data_new_from_mem (&cipher, crypttext, strlen (crypttext), FALSE); g_return_val_if_fail (GPG_IS_OK (gerr), FALSE); gerr = gpgme_data_new (&plain); g_return_val_if_fail (GPG_IS_OK (gerr), FALSE); /* encrypt with armor */ gpgme_set_textmode (pop->gctx, TRUE); gpgme_set_armor (pop->gctx, TRUE); /* Do the decryption */ gerr = gpgme_op_verify_start (pop->gctx, cipher, NULL, plain); /* Frees plain */ ret = process_crypto_result (pop, gerr, plain, cleartext, NULL, error); if (ret) { *signer = NULL; status = gpgme_op_verify_result (pop->gctx); if (status->signatures) { if (!(flags & FLAG_QUIET)) notify_signatures (NULL, status); if (status->signatures->summary & GPGME_SIGSUM_GREEN || status->signatures->summary & GPGME_SIGSUM_VALID || status->signatures->summary & GPGME_SIGSUM_KEY_MISSING) { keyid = seahorse_pgp_key_canonize_id (status->signatures->fpr); *signer = seahorse_context_id_to_dbus (SCTX_APP (), keyid); } } } g_object_unref (pop); gpgme_data_release (cipher); return TRUE; }