2020-03-03 22:20:07 +01:00
|
|
|
package widgets
|
|
|
|
|
|
|
|
import (
|
2021-11-05 10:19:46 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/config"
|
|
|
|
"git.sr.ht/~rjarry/aerc/lib/ui"
|
2022-04-25 15:30:43 +02:00
|
|
|
"git.sr.ht/~rjarry/aerc/models"
|
2020-03-03 22:20:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
type PGPInfo struct {
|
|
|
|
ui.Invalidatable
|
2022-04-25 15:30:43 +02:00
|
|
|
details *models.MessageDetails
|
2020-07-27 10:03:55 +02:00
|
|
|
uiConfig config.UIConfig
|
2020-03-03 22:20:07 +01:00
|
|
|
}
|
|
|
|
|
2022-04-25 15:30:43 +02:00
|
|
|
func NewPGPInfo(details *models.MessageDetails, uiConfig config.UIConfig) *PGPInfo {
|
2020-07-27 10:03:55 +02:00
|
|
|
return &PGPInfo{details: details, uiConfig: uiConfig}
|
2020-03-03 22:20:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 01:02:27 +01:00
|
|
|
func (p *PGPInfo) DrawSignature(ctx *ui.Context) {
|
2020-07-27 10:03:55 +02:00
|
|
|
errorStyle := p.uiConfig.GetStyle(config.STYLE_ERROR)
|
|
|
|
warningStyle := p.uiConfig.GetStyle(config.STYLE_WARNING)
|
|
|
|
validStyle := p.uiConfig.GetStyle(config.STYLE_SUCCESS)
|
|
|
|
defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT)
|
2020-03-03 22:20:07 +01:00
|
|
|
|
|
|
|
// TODO: Nicer prompt for TOFU, fetch from keyserver, etc
|
2022-04-25 15:30:43 +02:00
|
|
|
if p.details.SignatureValidity == models.UnknownEntity ||
|
|
|
|
p.details.SignedBy == "" {
|
2020-03-03 22:20:07 +01:00
|
|
|
|
2020-07-27 10:03:55 +02:00
|
|
|
x := ctx.Printf(0, 0, warningStyle, "*")
|
|
|
|
x += ctx.Printf(x, 0, defaultStyle,
|
2020-03-03 22:20:07 +01:00
|
|
|
" Signed with unknown key (%8X); authenticity unknown",
|
|
|
|
p.details.SignedByKeyId)
|
2022-04-25 15:30:43 +02:00
|
|
|
} else if p.details.SignatureValidity != models.Valid {
|
2020-03-04 01:02:27 +01:00
|
|
|
x := ctx.Printf(0, 0, errorStyle, "Invalid signature!")
|
2020-07-27 10:03:55 +02:00
|
|
|
x += ctx.Printf(x, 0, errorStyle,
|
2020-03-03 22:20:07 +01:00
|
|
|
" This message may have been tampered with! (%s)",
|
2022-04-25 15:30:43 +02:00
|
|
|
p.details.SignatureError)
|
2020-03-03 22:20:07 +01:00
|
|
|
} else {
|
2020-03-04 03:49:29 +01:00
|
|
|
x := ctx.Printf(0, 0, validStyle, "✓ Authentic ")
|
2020-07-27 10:03:55 +02:00
|
|
|
x += ctx.Printf(x, 0, defaultStyle,
|
2020-03-04 03:49:29 +01:00
|
|
|
"Signature from %s (%8X)",
|
2022-04-25 15:30:43 +02:00
|
|
|
p.details.SignedBy, p.details.SignedByKeyId)
|
2020-03-03 22:20:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PGPInfo) DrawEncryption(ctx *ui.Context, y int) {
|
2022-06-22 12:19:38 +02:00
|
|
|
warningStyle := p.uiConfig.GetStyle(config.STYLE_WARNING)
|
2020-07-27 10:03:55 +02:00
|
|
|
validStyle := p.uiConfig.GetStyle(config.STYLE_SUCCESS)
|
|
|
|
defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT)
|
2020-03-03 22:20:07 +01:00
|
|
|
|
2020-03-04 03:49:29 +01:00
|
|
|
x := ctx.Printf(0, y, validStyle, "✓ Encrypted ")
|
2020-07-27 10:03:55 +02:00
|
|
|
x += ctx.Printf(x, y, defaultStyle,
|
2022-04-25 15:30:43 +02:00
|
|
|
"To %s (%8X) ", p.details.DecryptedWith, p.details.DecryptedWithKeyId)
|
2022-06-22 12:19:38 +02:00
|
|
|
if !p.details.IsSigned {
|
|
|
|
x += ctx.Printf(x, y, warningStyle,
|
|
|
|
"(message not signed!)")
|
|
|
|
}
|
2020-03-03 22:20:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PGPInfo) Draw(ctx *ui.Context) {
|
2020-07-27 10:03:55 +02:00
|
|
|
defaultStyle := p.uiConfig.GetStyle(config.STYLE_DEFAULT)
|
|
|
|
ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', defaultStyle)
|
2020-03-03 22:20:07 +01:00
|
|
|
if p.details.IsSigned && p.details.IsEncrypted {
|
2020-03-04 01:02:27 +01:00
|
|
|
p.DrawSignature(ctx)
|
2020-03-03 22:20:07 +01:00
|
|
|
p.DrawEncryption(ctx, 1)
|
|
|
|
} else if p.details.IsSigned {
|
2020-03-04 01:02:27 +01:00
|
|
|
p.DrawSignature(ctx)
|
2020-03-03 22:20:07 +01:00
|
|
|
} else if p.details.IsEncrypted {
|
|
|
|
p.DrawEncryption(ctx, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *PGPInfo) Invalidate() {
|
|
|
|
p.DoInvalidate(p)
|
|
|
|
}
|