message signing

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
tkejzlar
Forum Newbie
Posts: 5
Joined: Mon May 21, 2007 3:15 am

message signing

Post by tkejzlar »

Hi,

I am using swift for sending e-mails from our accounting system and we now need to sign outgoing messages (we have been doing this in the past using openssl_pkcs7-sign PHP function) - can we somehow sign outgoing messages when sending them via swiftmailer?

Thanks, Tom.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'm not sure how message signing works, but you are going to do you'd write a BeforeSendListener plugin to grab the message before it's sent then sign it. I can probably write an extension to Swift_Message too... something like Swift_SignedMessage. I'll look into how it works, or if you want to brief me on it that would be good :)
tkejzlar
Forum Newbie
Posts: 5
Joined: Mon May 21, 2007 3:15 am

Post by tkejzlar »

Well, I myself am not an expert on message signing, the code we've been using was written by someone who does not work in our company anymore. But, as I understand it, openssl_pkcs7_sign PHP function is used for message signing, and it should work like this:

Code: Select all

$text = 'test e-mail body';

$file = file_put_contents('signing.txt', $text);

openssl_pkcs7_sign('signing.txt',
	'signed.txt',
	'file://openssl/certifikat2006az7.pem',
	'file://openssl/private_key2006az7.pem',
	array());

$data = file_get_contents('signed.txt');
$parts = explode("\n\n", $data, 2);

$parts[0] .= "\nFrom: test <tomas.kejzlar@gmail.com>\n";

mail('somebody@somewhere', 'test', $parts[1], $parts[0]);
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Thanks, it looks pretty easy. I'll check whatever RFC applies to it too :)

I should be able to release a plugin which does what you're doing.
tkejzlar
Forum Newbie
Posts: 5
Joined: Mon May 21, 2007 3:15 am

Post by tkejzlar »

d11wtq wrote:I should be able to release a plugin which does what you're doing.
That would be very nice. I've tried to do it but I've ended up with attachet "smime.p7s" file which - under Thunderbird - is treated as an unattached message signature...

Thanks, Tom.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Apologies for the slow progress on this. I haven't actually had a chance to work on anything yet as we've had guests living with us for the past 4 weeks but they flew back to Australia this morning so I can hopefully find time to work on this tonight :)
tkejzlar
Forum Newbie
Posts: 5
Joined: Mon May 21, 2007 3:15 am

Post by tkejzlar »

Do not apologize... It would be perfect if you could look at it tonight, but it is not critical and we can probbably solve sending signed messages temporarily some other way...
tkejzlar
Forum Newbie
Posts: 5
Joined: Mon May 21, 2007 3:15 am

Post by tkejzlar »

Hi, may I just ask whether you have made any progression on message signing? (just being curious...)

Tom.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

:oops: Sorry, I actually totally forgot about this after trying to fathom out what I was doing wrong with openssl_pkcs7_sign().

Unless you consider my confuddled few lines of experimentation a start, I'm basically where I was last time I posted :oops:

Code: Select all

$message = new Swift_Message("My subject");
$message->setBody("my message");
/*$part1 = new Swift_Message_Part("some part");

$message->attach($part1);

$part2 = new Swift_Message_Part("another_aprt", "text/html");

$message->attach($part2);*/

$message->setTo(array(new Swift_Address("cac@parrswood.manchester.sch.uk"), new Swift_Address("chris@iris.ac")));

$message->setFrom("chris@w3style.co.uk");

$stream = $message->buildData();

$fp = fopen("signed/unsigned.txt", "w");
fwrite($fp, $stream->readFull());
fclose($fp);

echo file_get_contents("signed/unsigned.txt");

echo "===================================";

openssl_pkcs7_sign("signed/unsigned.txt", "signed/signed.txt", "file://mycert.pem", array("file://mykey.pem", "swiftmailer"), array("From: <chris@w3style.co.uk"), OPENSSL_KEYTYPE_RSA);

echo file_get_contents("signed/signed.txt");
This just gave me errors about not being able to create the email structure and I got distracted with something else.

Sorry about that.

Thanks for the reminder. I should add it to the TODO file really.
lukasus
Forum Newbie
Posts: 3
Joined: Fri Apr 18, 2008 9:02 am

Re: message signing

Post by lukasus »

Hi, I try to find any possibility to sign S/MIME e-mails via PHP, but I found nothing. Do you know any ideas?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: message signing

Post by Chris Corbyn »

It's going to be in the enterprise edition of Swift Mailer version 4. The enterprise edition will be a paid download however.
lukasus
Forum Newbie
Posts: 3
Joined: Fri Apr 18, 2008 9:02 am

Re: message signing

Post by lukasus »

Ok, I would buy it, when it will be?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: message signing

Post by Chris Corbyn »

The short answer is "I don't have an accurate ETA", but you may wish to subscribe to this thread:

viewtopic.php?f=52&t=81467
Post Reply