Allow any body length, even if sigoptions.bodylength is set
This commit is contained in:
6
dkim.go
6
dkim.go
@@ -14,10 +14,10 @@ import (
|
|||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
"hash"
|
"hash"
|
||||||
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"net"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -310,8 +310,6 @@ func (dkim *dkim) Verify(email []byte) (dkimHeader *DKIMHeader, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// canonicalize returns canonicalized version of header and body
|
// canonicalize returns canonicalized version of header and body
|
||||||
func canonicalize(email []byte, cano string, h []string) (headers, body []byte, err error) {
|
func canonicalize(email []byte, cano string, h []string) (headers, body []byte, err error) {
|
||||||
body = []byte{}
|
body = []byte{}
|
||||||
@@ -449,7 +447,7 @@ func getBodyHash(body []byte, algo string, bodyLength uint) (string, error) {
|
|||||||
// if l tag (body length)
|
// if l tag (body length)
|
||||||
if bodyLength != 0 {
|
if bodyLength != 0 {
|
||||||
if uint(len(toH)) < bodyLength {
|
if uint(len(toH)) < bodyLength {
|
||||||
return "", ErrBadDKimTagLBodyTooShort
|
bodyLength = uint(len(toH))
|
||||||
}
|
}
|
||||||
toH = toH[0:bodyLength]
|
toH = toH[0:bodyLength]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -338,6 +338,11 @@ func Test_Sign(t *testing.T) {
|
|||||||
emailSimple, err = dkim.Sign(emailSimple, options)
|
emailSimple, err = dkim.Sign(emailSimple, options)
|
||||||
assert.Equal(t, signedSimpleSimpleLength, string(emailSimple))
|
assert.Equal(t, signedSimpleSimpleLength, string(emailSimple))
|
||||||
|
|
||||||
|
// options.BodyLength is way larger than email body
|
||||||
|
options.BodyLength = 50000
|
||||||
|
emailRelaxed = append([]byte(nil), email...)
|
||||||
|
emailRelaxed, err = dkim.Sign(emailRelaxed, options)
|
||||||
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Verify(t *testing.T) {
|
func Test_Verify(t *testing.T) {
|
||||||
@@ -456,8 +461,6 @@ func TestYahooIncDKIM(t *testing.T) {
|
|||||||
dkim.lookupTXT = func(string) ([]string, error) {
|
dkim.lookupTXT = func(string) ([]string, error) {
|
||||||
return []string{"v=DKIM1; g=*; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDGDd1Fz/AblN4d1haW+4B/u8PXkpd/s/JFkCPqp0Zk8xZ/SEs15fsWmj7yZwfsgi04Bs1eJhUIGf0iufHvkK5ws5XKBfbw1hYBHexopqYT5JFERYJ3slNEG5EeB04kKWpECjoMkXhDWvUJrHaBqGAz2KQ1dKAzrtKqRN2IVcDbBQIDAQAB"}, nil
|
return []string{"v=DKIM1; g=*; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDGDd1Fz/AblN4d1haW+4B/u8PXkpd/s/JFkCPqp0Zk8xZ/SEs15fsWmj7yZwfsgi04Bs1eJhUIGf0iufHvkK5ws5XKBfbw1hYBHexopqYT5JFERYJ3slNEG5EeB04kKWpECjoMkXhDWvUJrHaBqGAz2KQ1dKAzrtKqRN2IVcDbBQIDAQAB"}, nil
|
||||||
}
|
}
|
||||||
//dkim.now = func() time.Time { return time.Unix(1439925628, 0) }
|
|
||||||
//_, err := dkim.Verify([]byte(yahooIncDKIMtest), yIncTXT, yIncTime)
|
|
||||||
_, err := dkim.Verify([]byte(yahooIncDKIMtest))
|
_, err := dkim.Verify([]byte(yahooIncDKIMtest))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -32,9 +32,6 @@ var (
|
|||||||
// ErrBadMailFormatHeaders bad headers format (not DKIM Header)
|
// ErrBadMailFormatHeaders bad headers format (not DKIM Header)
|
||||||
ErrBadMailFormatHeaders = errors.New("bad mail format found in headers")
|
ErrBadMailFormatHeaders = errors.New("bad mail format found in headers")
|
||||||
|
|
||||||
// ErrBadDKimTagLBodyTooShort bad l tag
|
|
||||||
ErrBadDKimTagLBodyTooShort = errors.New("bad tag l or bodyLength option. Body length < l value")
|
|
||||||
|
|
||||||
// ErrDkimHeaderBadFormat when errors found in DKIM header
|
// ErrDkimHeaderBadFormat when errors found in DKIM header
|
||||||
ErrDkimHeaderBadFormat = errors.New("bad DKIM header format")
|
ErrDkimHeaderBadFormat = errors.New("bad DKIM header format")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user