pgp: refactor signature validity display

This commit changes the signature validity display to not use valid as
the default. Now invalid is the default which can cause fewer issues if
an attack vector emerges.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Moritz Poldrack 2022-06-22 12:19:41 +02:00 committed by Robin Jarry
parent b7d8918bbd
commit 7bdfa928cb
1 changed files with 25 additions and 18 deletions

View File

@ -1,12 +1,14 @@
package widgets package widgets
import ( import (
"fmt"
"strings" "strings"
"unicode/utf8" "unicode/utf8"
"git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/models"
"github.com/gdamore/tcell/v2"
) )
type PGPInfo struct { type PGPInfo struct {
@ -25,29 +27,34 @@ func (p *PGPInfo) DrawSignature(ctx *ui.Context) {
validStyle := p.uiConfig.GetStyle(config.STYLE_SUCCESS) validStyle := p.uiConfig.GetStyle(config.STYLE_SUCCESS)
defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT) defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT)
var icon string
var indicatorStyle, textstyle tcell.Style
textstyle = defaultStyle
var indicatorText, messageText string
// TODO: Nicer prompt for TOFU, fetch from keyserver, etc // TODO: Nicer prompt for TOFU, fetch from keyserver, etc
if p.details.SignatureValidity == models.UnknownEntity || switch p.details.SignatureValidity {
p.details.SignedBy == "" { case models.UnknownEntity:
icon = p.uiConfig.IconUnknown
x := ctx.Printf(0, 0, warningStyle, "%s unknown", p.uiConfig.IconUnknown) indicatorStyle = warningStyle
x += ctx.Printf(x, 0, defaultStyle, indicatorText = "Unknown"
" Signed with unknown key (%8X); authenticity unknown", messageText = fmt.Sprintf("Signed with unknown key (%8X); authenticity unknown", p.details.SignedByKeyId)
p.details.SignedByKeyId) case models.Valid:
} else if p.details.SignatureValidity != models.Valid { icon = p.uiConfig.IconSigned
x := ctx.Printf(0, 0, errorStyle, "%s Invalid signature!", p.uiConfig.IconInvalid)
x += ctx.Printf(x, 0, errorStyle,
" This message may have been tampered with! (%s)",
p.details.SignatureError)
} else {
icon := p.uiConfig.IconSigned
if p.details.IsEncrypted && p.uiConfig.IconSignedEncrypted != "" { if p.details.IsEncrypted && p.uiConfig.IconSignedEncrypted != "" {
icon = p.uiConfig.IconSignedEncrypted icon = p.uiConfig.IconSignedEncrypted
} }
x := ctx.Printf(0, 0, validStyle, "%s Authentic ", icon) indicatorStyle = validStyle
x += ctx.Printf(x, 0, defaultStyle, indicatorText = "Authentic"
"Signature from %s (%8X)", messageText = fmt.Sprintf("Signature from %s (%8X)", p.details.SignedBy, p.details.SignedByKeyId)
p.details.SignedBy, p.details.SignedByKeyId) default:
icon = p.uiConfig.IconInvalid
indicatorStyle = errorStyle
indicatorText = "Invalid signature!"
messageText = fmt.Sprintf("This message may have been tampered with! (%s)", p.details.SignatureError)
} }
x := ctx.Printf(0, 0, indicatorStyle, "%s %s ", icon, indicatorText)
ctx.Printf(x, 0, textstyle, messageText)
} }
func (p *PGPInfo) DrawEncryption(ctx *ui.Context, y int) { func (p *PGPInfo) DrawEncryption(ctx *ui.Context, y int) {