phalaaxx / milter

A golang library for milter support
BSD 2-Clause "Simplified" License
45 stars 22 forks source link

Question - Implementation of DKIM #25

Open abolinhas opened 3 weeks ago

abolinhas commented 3 weeks ago

Hi I'm using milter with Postfix, now i'm trying to implement DKIM using this library https://github.com/toorop/go-dkim. My question is where I should put dkim.Sign method()? Inside Body(), BodyChunk(), Headers ()....? Seams Dkim needs to get the full message, sign it and replace the message with a signed on.

Best regards

PetriTurunen commented 2 weeks ago

Yes, DKIM signing needs the whole message so it should be done as last step just before the message is send. If you want to do it in your milter then the Body() is the right place to do it. And make it the last thing you do in your milter.

But it may still fail :(

Im using opendkim for DKIM signing and its the last milter in the filter chain in my postfix.

abolinhas commented 2 weeks ago

Body() only includes the body part, not the headers. Is not correct?

PetriTurunen commented 2 weeks ago

If i have understood correctly Body() doesnt include anything. Its just called when all the body parts are read.

So you need to create the message your self by collecting all headers + body parts and this is why adding DKIM may fail because you have to get everything just right to add the signature.

Check this for example: https://github.com/phalaaxx/pf-milters/blob/master/extmilter/main.go