msgviewer: parse and display authentication results
Parse the Authentication-Results header and display it in the message
viewer (not enabled by default). DKIM, SPF and DMARC authentication
methods are supported. Implement recommendation from RFC 7601 Sec 7.1 to
have an explicit list of trustworthy hostnames before displaying the
authentication results. Be aware that the authentication headers can be
forged.
To display the results for a specific authentication method, add the
corresponding name to the layout of headers in the viewer section of
aerc.conf, e.g. to display all three, use:
header-layout = From|To,Cc|Bcc,Date,Subject,DKIM|SPF|DMARC
More information will be displayed when "+" is appended to the
authentication method name, e.g. DKIM+ or SPF+ or DMARC+.
Also, add the trustworthy hosts per account with the trusted-authres
parameter, e.g.
trusted-authres = *
to trust every host or use regular expressions for a finer control.
Multiple hosts can be entered as a comma-separated list. Authentication
results will only be displayed when the host is listed in the
trusted-authres list.
Link: https://datatracker.ietf.org/doc/html/rfc7601
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-30 00:20:41 +02:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.sr.ht/~rjarry/aerc/config"
|
|
|
|
"git.sr.ht/~rjarry/aerc/lib/auth"
|
|
|
|
"git.sr.ht/~rjarry/aerc/lib/ui"
|
|
|
|
"github.com/gdamore/tcell/v2"
|
|
|
|
"github.com/mattn/go-runewidth"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AuthInfo struct {
|
|
|
|
ui.Invalidatable
|
|
|
|
authdetails *auth.Details
|
|
|
|
showInfo bool
|
2022-07-03 17:11:12 +02:00
|
|
|
uiConfig *config.UIConfig
|
msgviewer: parse and display authentication results
Parse the Authentication-Results header and display it in the message
viewer (not enabled by default). DKIM, SPF and DMARC authentication
methods are supported. Implement recommendation from RFC 7601 Sec 7.1 to
have an explicit list of trustworthy hostnames before displaying the
authentication results. Be aware that the authentication headers can be
forged.
To display the results for a specific authentication method, add the
corresponding name to the layout of headers in the viewer section of
aerc.conf, e.g. to display all three, use:
header-layout = From|To,Cc|Bcc,Date,Subject,DKIM|SPF|DMARC
More information will be displayed when "+" is appended to the
authentication method name, e.g. DKIM+ or SPF+ or DMARC+.
Also, add the trustworthy hosts per account with the trusted-authres
parameter, e.g.
trusted-authres = *
to trust every host or use regular expressions for a finer control.
Multiple hosts can be entered as a comma-separated list. Authentication
results will only be displayed when the host is listed in the
trusted-authres list.
Link: https://datatracker.ietf.org/doc/html/rfc7601
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-30 00:20:41 +02:00
|
|
|
}
|
|
|
|
|
2022-07-03 17:11:12 +02:00
|
|
|
func NewAuthInfo(auth *auth.Details, showInfo bool, uiConfig *config.UIConfig) *AuthInfo {
|
msgviewer: parse and display authentication results
Parse the Authentication-Results header and display it in the message
viewer (not enabled by default). DKIM, SPF and DMARC authentication
methods are supported. Implement recommendation from RFC 7601 Sec 7.1 to
have an explicit list of trustworthy hostnames before displaying the
authentication results. Be aware that the authentication headers can be
forged.
To display the results for a specific authentication method, add the
corresponding name to the layout of headers in the viewer section of
aerc.conf, e.g. to display all three, use:
header-layout = From|To,Cc|Bcc,Date,Subject,DKIM|SPF|DMARC
More information will be displayed when "+" is appended to the
authentication method name, e.g. DKIM+ or SPF+ or DMARC+.
Also, add the trustworthy hosts per account with the trusted-authres
parameter, e.g.
trusted-authres = *
to trust every host or use regular expressions for a finer control.
Multiple hosts can be entered as a comma-separated list. Authentication
results will only be displayed when the host is listed in the
trusted-authres list.
Link: https://datatracker.ietf.org/doc/html/rfc7601
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-30 00:20:41 +02:00
|
|
|
return &AuthInfo{authdetails: auth, showInfo: showInfo, uiConfig: uiConfig}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AuthInfo) Draw(ctx *ui.Context) {
|
|
|
|
defaultStyle := a.uiConfig.GetStyle(config.STYLE_DEFAULT)
|
|
|
|
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', defaultStyle)
|
|
|
|
var text string
|
|
|
|
if a.authdetails == nil {
|
|
|
|
text = "(no header)"
|
|
|
|
ctx.Printf(0, 0, defaultStyle, text)
|
|
|
|
} else if a.authdetails.Err != nil {
|
2022-07-29 21:25:56 +02:00
|
|
|
style := a.uiConfig.GetStyle(config.STYLE_ERROR)
|
msgviewer: parse and display authentication results
Parse the Authentication-Results header and display it in the message
viewer (not enabled by default). DKIM, SPF and DMARC authentication
methods are supported. Implement recommendation from RFC 7601 Sec 7.1 to
have an explicit list of trustworthy hostnames before displaying the
authentication results. Be aware that the authentication headers can be
forged.
To display the results for a specific authentication method, add the
corresponding name to the layout of headers in the viewer section of
aerc.conf, e.g. to display all three, use:
header-layout = From|To,Cc|Bcc,Date,Subject,DKIM|SPF|DMARC
More information will be displayed when "+" is appended to the
authentication method name, e.g. DKIM+ or SPF+ or DMARC+.
Also, add the trustworthy hosts per account with the trusted-authres
parameter, e.g.
trusted-authres = *
to trust every host or use regular expressions for a finer control.
Multiple hosts can be entered as a comma-separated list. Authentication
results will only be displayed when the host is listed in the
trusted-authres list.
Link: https://datatracker.ietf.org/doc/html/rfc7601
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-30 00:20:41 +02:00
|
|
|
text = a.authdetails.Err.Error()
|
|
|
|
ctx.Printf(0, 0, style, text)
|
|
|
|
} else {
|
|
|
|
checkBounds := func(x int) bool {
|
|
|
|
if x < ctx.Width() {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setResult := func(result auth.Result) (string, tcell.Style) {
|
|
|
|
switch result {
|
|
|
|
case auth.ResultNone:
|
|
|
|
return "none", defaultStyle
|
|
|
|
case auth.ResultNeutral:
|
|
|
|
return "neutral", a.uiConfig.GetStyle(config.STYLE_WARNING)
|
|
|
|
case auth.ResultPolicy:
|
|
|
|
return "policy", a.uiConfig.GetStyle(config.STYLE_WARNING)
|
|
|
|
case auth.ResultPass:
|
|
|
|
return "✓", a.uiConfig.GetStyle(config.STYLE_SUCCESS)
|
|
|
|
case auth.ResultFail:
|
|
|
|
return "✗", a.uiConfig.GetStyle(config.STYLE_ERROR)
|
|
|
|
default:
|
|
|
|
return string(result), a.uiConfig.GetStyle(config.STYLE_ERROR)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x := 1
|
|
|
|
for i := 0; i < len(a.authdetails.Results); i++ {
|
|
|
|
if checkBounds(x) {
|
|
|
|
text, style := setResult(a.authdetails.Results[i])
|
|
|
|
if i > 0 {
|
|
|
|
text = " " + text
|
|
|
|
}
|
|
|
|
x += ctx.Printf(x, 0, style, text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if a.showInfo {
|
|
|
|
infoText := ""
|
|
|
|
for i := 0; i < len(a.authdetails.Infos); i++ {
|
|
|
|
if i > 0 {
|
|
|
|
infoText += ","
|
|
|
|
}
|
|
|
|
infoText += a.authdetails.Infos[i]
|
|
|
|
if reason := a.authdetails.Reasons[i]; reason != "" {
|
|
|
|
infoText += reason
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if checkBounds(x) && infoText != "" {
|
|
|
|
if trunc := ctx.Width() - x - 3; trunc > 0 {
|
|
|
|
text = runewidth.Truncate(infoText, trunc, "…")
|
2022-07-29 21:25:56 +02:00
|
|
|
ctx.Printf(x, 0, defaultStyle, fmt.Sprintf(" (%s)", text))
|
msgviewer: parse and display authentication results
Parse the Authentication-Results header and display it in the message
viewer (not enabled by default). DKIM, SPF and DMARC authentication
methods are supported. Implement recommendation from RFC 7601 Sec 7.1 to
have an explicit list of trustworthy hostnames before displaying the
authentication results. Be aware that the authentication headers can be
forged.
To display the results for a specific authentication method, add the
corresponding name to the layout of headers in the viewer section of
aerc.conf, e.g. to display all three, use:
header-layout = From|To,Cc|Bcc,Date,Subject,DKIM|SPF|DMARC
More information will be displayed when "+" is appended to the
authentication method name, e.g. DKIM+ or SPF+ or DMARC+.
Also, add the trustworthy hosts per account with the trusted-authres
parameter, e.g.
trusted-authres = *
to trust every host or use regular expressions for a finer control.
Multiple hosts can be entered as a comma-separated list. Authentication
results will only be displayed when the host is listed in the
trusted-authres list.
Link: https://datatracker.ietf.org/doc/html/rfc7601
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-30 00:20:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AuthInfo) Invalidate() {
|
|
|
|
a.DoInvalidate(a)
|
|
|
|
}
|