Project

General

Profile

« Previous | Next » 

Revision 6b300a88

Added by Marc Dequènes over 12 years ago

[evol] ported tmail_gpg to GPGME 2.0

View differences:

lib/tmail_gpg.rb
sig = pgp_signature()
sigs_check = nil
GPGME.verify(sig, content) do |signature|
gpg = GPGME::Ctx.new
gpg.verify(GPGME::Data.new(sig), GPGME::Data.new(content)) do |signature|
sigs_check ||= []
sigs_check << signature
end
gpg.release
sigs_check
end
......
raise NotImplementedError, "pgp-encrypted protocol version #{protocol_version} is not implemented" unless protocol_version == 1
encrypted_data = pgp_encrypted_part()
GPGME.decrypt(encrypted_data, {:passphrase_callback => method(:gpg_passphrase_callback_wrapper),
:passphrase_callback_value => passphrase_callback, :textmode => true})
gpg = GPGME::Ctx.new({:passphrase_callback => method(:gpg_passphrase_callback_wrapper),
:passphrase_callback_value => passphrase_callback, :textmode => true})
gpg.decrypt(GPGME::Data.new(encrypted_data))
gpg.release
end
def pgp_crypt(crypters_id)
crypters_id = [crypters_id] unless crypters_id.is_a? Array
crypters = crypters_id.collect{|key_id| gpg_key(key_id, false) }
GPGME.encrypt(crypters, self.to_s, {:armor => true, :always_trust => true})
gpg = GPGME::Ctx.new({:armor => true})
gpg.encrypt(crypters, GPGME::Data.new(self.to_s))
gpg.release
end
def pgp_sign(signers_id, &passphrase_callback)
signers_id = [signers_id] unless signers_id.is_a? Array
signers = signers_id.collect{|key_id| gpg_key(key_id, true) }
# we don't use GPGME.sign(), because we need to get operation information to get the hash_algo and compute the micalg parameter
# we don't use GPGME::Crypto.sign(), because we need to get operation information to get the hash_algo and compute the micalg parameter
gpg = GPGME::Ctx.new({:signers => signers, :passphrase_callback => method(:gpg_passphrase_callback_wrapper),
:passphrase_callback_value => passphrase_callback, :armor => true})
gpg.add_signer(*signers)
......
# adds a final CRLF to respect OpenPGP convention (see note in chapter 5 of RFC3156)
prepared_data = self.to_rfc3156 + "\r\n"
raise 'TMail ERROR: data to sign MUST be in 7bit format, using Quotes-Printable or Base64 encoding !' unless prepared_data.is_7bit?
gpg.sign(GPGME::Data.new(prepared_data), sig_data, GPGME::SIG_MODE_DETACH)
gpg.sign(GPGME::Data.new(prepared_data), GPGME::Data.new(sig_data), GPGME::SIG_MODE_DETACH)
hash_algo = GPGME.gpgme_op_sign_result(gpg).signatures.first.hash_algo
micalg = "pgp-" + GPGME.gpgme_hash_algo_name(hash_algo).downcase
sig_data.seek(0, IO::SEEK_SET)
gpg.release
{:signature => sig_data.read, :micalg => micalg}
end
......
end
begin
require 'gpgme' # >= 1.0.2 needed for :always_trust sign option
require 'gpgme'
TMail::Mail.send(:include, TMail::GpgExtension)
rescue LoadError
end

Also available in: Unified diff