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"
|
||||
"errors"
|
||||
"hash"
|
||||
"net"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"net"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -310,8 +310,6 @@ func (dkim *dkim) Verify(email []byte) (dkimHeader *DKIMHeader, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
// canonicalize returns canonicalized version of header and body
|
||||
func canonicalize(email []byte, cano string, h []string) (headers, body []byte, err error) {
|
||||
body = []byte{}
|
||||
@@ -449,7 +447,7 @@ func getBodyHash(body []byte, algo string, bodyLength uint) (string, error) {
|
||||
// if l tag (body length)
|
||||
if bodyLength != 0 {
|
||||
if uint(len(toH)) < bodyLength {
|
||||
return "", ErrBadDKimTagLBodyTooShort
|
||||
bodyLength = uint(len(toH))
|
||||
}
|
||||
toH = toH[0:bodyLength]
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -338,6 +338,11 @@ func Test_Sign(t *testing.T) {
|
||||
emailSimple, err = dkim.Sign(emailSimple, options)
|
||||
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) {
|
||||
@@ -456,8 +461,6 @@ func TestYahooIncDKIM(t *testing.T) {
|
||||
dkim.lookupTXT = func(string) ([]string, error) {
|
||||
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))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -32,9 +32,6 @@ var (
|
||||
// ErrBadMailFormatHeaders bad headers format (not DKIM Header)
|
||||
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 = errors.New("bad DKIM header format")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user