示例#1
0
void
mu_msg_crypto_verify_part (GMimeMultipartSigned *sig, MuMsgOptions opts,
			   GError **err)
{
	/* the signature status */
	MuMsgPartSigStatusReport *report;
	GMimeCryptoContext *ctx;
	GMimeSignatureList *sigs;

	g_return_if_fail (GMIME_IS_MULTIPART_SIGNED(sig));

	ctx = get_crypto_context (opts, NULL, NULL, err);
	if (!ctx) {
		mu_util_g_set_error (err, MU_ERROR_CRYPTO,
				     "failed to get crypto context");
		return;
	}

	sigs = g_mime_multipart_signed_verify (sig, ctx, err);
	g_object_unref (ctx);
	if (!sigs) {
		if (err && !*err)
			mu_util_g_set_error (err, MU_ERROR_CRYPTO,
					     "verification failed");
		return;
	}

	report = get_status_report (sigs);
	g_mime_signature_list_clear (sigs);

	/* tag this part with the signature status check */
	tag_with_sig_status(G_OBJECT(sig), report);
}
示例#2
0
文件: mu-msg-crypto.c 项目: mylese/mu
GMimeObject* /* this is declared in mu-msg-priv.h */
mu_msg_crypto_decrypt_part (GMimeMultipartEncrypted *enc, MuMsgOptions opts,
			    MuMsgPartPasswordFunc func, gpointer user_data,
			    GError **err)
{
	GMimeObject *dec;
	GMimeCryptoContext *ctx;

	g_return_val_if_fail (GMIME_IS_MULTIPART_ENCRYPTED(enc), NULL);

	ctx = get_crypto_context (opts, func, user_data, err);
	if (!ctx) {
		mu_util_g_set_error (err, MU_ERROR_CRYPTO,
				     "failed to get crypto context");
		return NULL;
	}

	dec = g_mime_multipart_encrypted_decrypt (enc, ctx, NULL, err);
	g_object_unref (ctx);
	if (!dec) {
		if (err && !*err)
			mu_util_g_set_error (err, MU_ERROR_CRYPTO,
					     "decryption failed");
		return NULL;
	}

	return dec;
}
示例#3
0
MuMsgPartSigStatusReport*
mu_msg_crypto_verify_part (GMimeMultipartSigned *sig, MuMsgOptions opts,
			   GError **err)
{
	MuMsgPartSigStatusReport *report;
	GMimeCryptoContext *ctx;
	GMimeSignatureList *sigs;

	g_return_val_if_fail (GMIME_IS_MULTIPART_SIGNED(sig), NULL);

	ctx = get_crypto_context (opts, NULL, NULL, err);
	if (!ctx) {
		mu_util_g_set_error (err, MU_ERROR_CRYPTO,
				     "failed to get crypto context");
		return NULL;
	}

	sigs = g_mime_multipart_signed_verify (sig, ctx, err);
	g_object_unref (ctx);
	if (!sigs) {
		if (err && !*err)
			mu_util_g_set_error (err, MU_ERROR_CRYPTO,
					     "verification failed");
		return NULL;
	}

	report = get_status_report (sigs);
	g_mime_signature_list_clear (sigs);

	return report;
}
示例#4
0
GMimeObject* /* this is declared in mu-msg-priv.h */
mu_msg_crypto_decrypt_part (GMimeMultipartEncrypted *enc, MuMsgOptions opts,
			    MuMsgPartPasswordFunc func, gpointer user_data,
			    GError **err)
{
	GMimeObject *dec;
	GMimeCryptoContext *ctx;
	GMimeDecryptResult *res;

	g_return_val_if_fail (GMIME_IS_MULTIPART_ENCRYPTED(enc), NULL);

	ctx = get_crypto_context (opts, func, user_data, err);
	if (!ctx) {
		mu_util_g_set_error (err, MU_ERROR_CRYPTO,
				     "failed to get crypto context");
		return NULL;
	}

	/* at the time of writing, there is a small leak in
	 * g_mime_multipart_encrypted_decrypt; I've notified its
	 * author and it has been fixed 2012-09-12:
	 *   http://git.gnome.org/browse/gmime/commit/
	 *   ?id=1bacd43b50d91bd03a4ae1dc9f46f5783dee61b1
	 * (or GMime > 2.6.10)
	 *   */
	res = NULL;
	dec = g_mime_multipart_encrypted_decrypt (enc, ctx, &res, err);
	g_object_unref (ctx);

	/* we don't use the 3rd param 'res' * (GMimeDecryptResult),
	 * but we must unref it. */
	if (res)
		g_object_unref (res);

	if (!dec) {
		if (err && !*err)
			mu_util_g_set_error (err, MU_ERROR_CRYPTO,
					     "decryption failed");
		return NULL;
	}

	return dec;
}
示例#5
0
文件: mu-msg-crypto.c 项目: mylese/mu
GSList*
mu_msg_mime_sig_infos (GMimeMultipartSigned *sigmpart, MuMsgOptions opts,
		       GError **err)
{
	int i;
	GMimeSignatureList *sigs;
	GMimeCryptoContext *cctx;
	GSList *siginfos;

	if (!GMIME_IS_MULTIPART_SIGNED (sigmpart)) {
		mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
				     "not a multipart/signed part");
		return NULL; /* error */
	}

	/* dummy is good, since we don't need a password when checking
	 * signatures */
	cctx = get_crypto_context (opts, dummy_password_func, NULL, err);

	if (!cctx) /* return a fake siginfos with the error */
		return error_sig_infos (); /* error */

	sigs = g_mime_multipart_signed_verify (sigmpart, cctx, err);
	g_object_unref (cctx);
	if (!sigs)
		return NULL; /* error */

	for (i = 0, siginfos = NULL; i != g_mime_signature_list_length (sigs); ++i) {

		MuMsgPartSigInfo *siginfo;
		siginfo = sig_info_new
			(g_mime_signature_list_get_signature (sigs, i));

		siginfos = g_slist_prepend (siginfos, siginfo);
	}

	return siginfos;
}