aboutsummaryrefslogtreecommitdiff
path: root/lib/email
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-02-08 08:52:35 +0700
committerShulhan <ms@kilabit.info>2019-02-08 08:52:35 +0700
commit0a67cedde8b9babb6923c32e13ded3ca787086cd (patch)
treef5863b1de73b8d26d0336ced44a44bffb77ffcf7 /lib/email
parenta8b1367ce8396aa4c3529465502acf42677fa5c5 (diff)
downloadpakakeh.go-0a67cedde8b9babb6923c32e13ded3ca787086cd.tar.xz
email/dkim: handle invalid characters when parsing tag value with base64
Diffstat (limited to 'lib/email')
-rw-r--r--lib/email/dkim/tag.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/email/dkim/tag.go b/lib/email/dkim/tag.go
index 3120aa06..858f8d77 100644
--- a/lib/email/dkim/tag.go
+++ b/lib/email/dkim/tag.go
@@ -131,16 +131,33 @@ func (t *tag) setValue(val []byte) (err error) {
if len(val) == 0 {
return nil
}
+ var (
+ isBase64 bool
+ b64 = make([]byte, 0, len(val))
+ )
+ if t.key == tagSignature || t.key == tagBodyHash || t.key == tagDNSPublicKey {
+ isBase64 = true
+ }
for x := 0; x < len(val); x++ {
- if libbytes.IsSpace(val[x]) {
+ switch {
+ case libbytes.IsSpace(val[x]):
continue
- }
- if val[x] < 0x21 || val[x] == 0x3B || val[x] > 0x7E {
- return fmt.Errorf("dkim: invalid value: '%s'", val)
+ case val[x] < 0x21 || val[x] == 0x3B || val[x] > 0x7E:
+ if !isBase64 {
+ return fmt.Errorf("dkim: invalid value: '%s'", val)
+ }
+ default:
+ if isBase64 {
+ b64 = append(b64, val[x])
+ }
}
}
- t.value = val
+ if isBase64 {
+ t.value = b64
+ } else {
+ t.value = val
+ }
return nil
}