(ctx context.Context, header textproto.Header, body buffer.Buffer)
| 120 | } |
| 121 | |
| 122 | func (d *dkimCheckState) CheckBody(ctx context.Context, header textproto.Header, body buffer.Buffer) module.CheckResult { |
| 123 | defer trace.StartRegion(ctx, "check.dkim/CheckBody").End() |
| 124 | |
| 125 | if !header.Has("DKIM-Signature") { |
| 126 | if d.c.noSigAction.Reject || d.c.noSigAction.Quarantine { |
| 127 | d.log.Printf("no signatures present") |
| 128 | } else { |
| 129 | d.log.Debugf("no signatures present") |
| 130 | } |
| 131 | return d.c.noSigAction.Apply(module.CheckResult{ |
| 132 | Reason: &exterrors.SMTPError{ |
| 133 | Code: 550, |
| 134 | EnhancedCode: exterrors.EnhancedCode{5, 7, 20}, |
| 135 | Message: "No DKIM signatures", |
| 136 | CheckName: "check.dkim", |
| 137 | }, |
| 138 | AuthResult: []authres.Result{ |
| 139 | &authres.DKIMResult{ |
| 140 | Value: authres.ResultNone, |
| 141 | }, |
| 142 | }, |
| 143 | }) |
| 144 | } |
| 145 | |
| 146 | b := bytes.Buffer{} |
| 147 | _ = textproto.WriteHeader(&b, header) |
| 148 | bodyRdr, err := body.Open() |
| 149 | if err != nil { |
| 150 | return module.CheckResult{ |
| 151 | Reject: true, |
| 152 | Reason: exterrors.WithTemporary( |
| 153 | exterrors.WithFields(err, map[string]interface{}{ |
| 154 | "check": "check.dkim", |
| 155 | "smtp_msg": "Internal I/O error", |
| 156 | }), |
| 157 | true, |
| 158 | ), |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | verifications, err := dkim.VerifyWithOptions(io.MultiReader(&b, bodyRdr), &dkim.VerifyOptions{ |
| 163 | LookupTXT: func(domain string) ([]string, error) { |
| 164 | return d.c.resolver.LookupTXT(ctx, domain) |
| 165 | }, |
| 166 | }) |
| 167 | if err != nil { |
| 168 | return module.CheckResult{ |
| 169 | Reject: true, |
| 170 | Reason: exterrors.WithTemporary( |
| 171 | exterrors.WithFields(err, map[string]interface{}{ |
| 172 | "check": "check.dkim", |
| 173 | "smtp_msg": "Internal error during policy check", |
| 174 | }), |
| 175 | true, |
| 176 | ), |
| 177 | } |
| 178 | } |
| 179 |
nothing calls this directly
no test coverage detected