Project

General

Profile

« Previous | Next » 

Revision c0979b3e

Added by Marc Dequènes about 15 years ago

  • ID c0979b3eb0412e410e1215171c043eeb29253823

[evol] moved signed/encrypted mail creation from original mail to TMail class, and removed mail object duplication in the process (references to inners objects caused original mail to be altered, copying original headers instead)

View differences:

lib/cyborghood/mail.rb
end
def crypt(fingerprint)
clear_data = build_intermediate_mail()
encrypted_data = clear_data.pgp_crypt(fingerprint)
# build properly encrypted mail
# (modify original mail parts)
@mail.set_content_type("multipart", "encrypted", {'boundary' => TMail.new_boundary, "protocol" => "application/pgp-encrypted"})
@mail.transfer_encoding = "7bit"
@mail['content-disposition'] = nil
@mail.body = "This mail is a RFC3156 encrypted message.\n"
@mail.parts.clear
p_pgp = TMail::Mail.new
p_pgp.set_content_type("application", "pgp-encrypted")
p_pgp.transfer_encoding = "7bit"
p_pgp.content_disposition = "inline"
p_pgp.body = "Version: 1\n"
@mail.parts << p_pgp
p_encrypted = TMail::Mail.new
p_encrypted.set_content_type("application", "octet-stream")
p_encrypted.transfer_encoding = "7bit"
p_encrypted.content_disposition = "inline"
p_encrypted.body = encrypted_data
@mail.parts << p_encrypted
@mail = @mail.create_encrypted(fingerprint)
end
def sign
data = build_intermediate_mail()
sign_data = data.pgp_sign([@config.mail.key_id]) do |uid_hint, passphrase_info, prev_was_bad|
# we don't check the uid, as their is only one signer
@mail = @mail.create_signed(@config.mail.key_id) do |uid_hint, passphrase_info, prev_was_bad|
@config.mail.key_passphrase
end
original_content_type = @mail.content_type
original_content_transfer_encoding = @mail.content_transfer_encoding
original_content_disposition = @mail.content_disposition
# build properly signed mail
# (modify original mail parts)
@mail.set_content_type("multipart", "signed", {'boundary' => TMail.new_boundary, 'protocol' => "application/pgp-signature", 'micalg' => sign_data[:micalg]})
@mail.transfer_encoding = "7bit"
@mail['content-disposition'] = nil
@mail.body = "This mail is a RFC3156 signed message.\n"
@mail.parts.clear
p_signed = data
@mail.parts << p_signed
p_signature = TMail::Mail.new
p_signature.set_content_type("application", "pgp-signature")
p_signature.transfer_encoding = "7bit"
p_signature.content_disposition = "inline"
p_signature.body = sign_data[:signature]
@mail.parts << p_signature
end
def sign_and_crypt(fingerprint)
# not using sign_and_crypt(), to avoid repeating code
sign()
crypt(fingerprint)
end
......
private
def build_intermediate_mail
# build a fake mail to get the generated content to be crypted/signed
fake_mail = TMail::Mail.new
fake_mail['content-type'] = @mail['content-type'].to_s
fake_mail.transfer_encoding = @mail.transfer_encoding if @mail.transfer_encoding
fake_mail.content_disposition = @mail.content_disposition if @mail.content_disposition
if @mail.multipart?
@mail.each_part {|p| fake_mail.parts << p }
else
fake_mail.body = @mail.body
end
# store the calculated content, to be able to use the raw() method
fake_mail.write_back
fake_mail
end
def parse_signed
order = {:ok => false, :msg => "mail not formatted correctly"}

Also available in: Unified diff