-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dkim: generated header not properly formatted #23
Comments
Hmm, interesting. Is |
No, in the last iteration the len is 1 and the character is "\n". I wrote a simple test program to reproduce the error. It seems due to the lenght of the DKIM header string. package main
import (
"bytes"
"crypto/rand"
"crypto/rsa"
"fmt"
"log"
"strings"
"time"
"github.com/emersion/go-msgauth/dkim"
)
func main() {
header := make(map[string]string)
header["Return-Path"] = fmt.Sprintf("[email protected]")
header["From"] = "[email protected]"
header["To"] = "[email protected]"
header["Subject"] = "Send Test"
header["Message-ID"] = "<xxxx@xxxx>"
header["Date"] = time.Now().Format(time.RFC1123Z)
message := ""
for k, v := range header {
message += fmt.Sprintf("%s: %s\r\n", k, v)
}
message += "\r\n" + "Longer message body"
fmt.Printf("%v\n", message)
reader := rand.Reader
bitSize := 1024
key, _ := rsa.GenerateKey(reader, bitSize)
r := strings.NewReader(message)
options := &dkim.SignOptions{
Domain: "test.xxxxxxxxxx.xxxxx",
Selector: "brisbane",
Signer: key,
}
var b bytes.Buffer
if err := dkim.Sign(&b, r, options); err != nil {
log.Fatal(err)
}
fmt.Printf("Message:\n%v\n\n", b.String())
} Output:
|
Does it work properly if we remove |
Yes it does! I've submitted a pull request that adds a test that fails due to this issue and solves it! |
Hi, I'm playing with this library and I'm incurring in a strange issue.
In some case, when I try to generate a DKIM signature, the generated header get an extra "\r\n" that makes the mail invalid.
For istance, if I try to sign this email:
I got this signed message
notice that the extra black line added before From header makes the message to be worngly interpreded by a receiving SMTP.
The issues seems related to the length of the header, in fact if I try to add (or remove) headers from the message it works properly:
Note the extra header here.
If you give me some tips, I could try to solve the issue and submit a PR!
It seems to me that the issue is due to the 76 char limitation of the message line.
The text was updated successfully, but these errors were encountered: