about summary refs log tree commit diff stats
path: root/028call_reply.cc
Commit message (Expand)AuthorAgeFilesLines
* 3136Kartik K. Agaram2016-07-221-2/+0
* 3133Kartik K. Agaram2016-07-221-1/+1
* 2990Kartik K. Agaram2016-05-201-7/+7
* 2931 - be explicit about making copiesKartik K. Agaram2016-05-061-2/+2
* 2874Kartik K. Agaram2016-04-271-11/+11
* 2873 - fix a bug in converting conditional returnsKartik K. Agaram2016-04-271-70/+0
* 2862Kartik K. Agaram2016-04-241-0/+230
-03-03 16:49:52 -0500 Initial support for PGP decryption & signatures' href='/akspecs/aerc/commit/widgets/pgpinfo.go?h=0.5.2&id=f3158b36f1f210ff54febbe82b571c1379b30c98'>f3158b3 ^
f79813a ^
f3158b3 ^



f79813a ^
f3158b3 ^





a31d184 ^

aec5dd1 ^
f3158b3 ^
aec5dd1 ^
f79813a ^
f3158b3 ^





a31d184 ^
f3158b3 ^
aec5dd1 ^
f3158b3 ^
aec5dd1 ^
f3158b3 ^




f79813a ^
f3158b3 ^

f79813a ^
f3158b3 ^







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77




















                                                           
                                                  

                                                                    
                                                                                     
                                                                                




                                                                             
                                                          



                                                                               
                                                                       





                                                                          

                                                 
                                                                   
                                                         
                                                  
                                                            





                                                                                
                                         
 
                                                           
                                                 
                                                                                    




                                                                          
                                    

                                        
                                    







                                         
package widgets

import (
	"errors"

	"git.sr.ht/~sircmpwn/aerc/lib/ui"

	"github.com/gdamore/tcell"
	"golang.org/x/crypto/openpgp"
	pgperrors "golang.org/x/crypto/openpgp/errors"
)

type PGPInfo struct {
	ui.Invalidatable
	details *openpgp.MessageDetails
}

func NewPGPInfo(details *openpgp.MessageDetails) *PGPInfo {
	return &PGPInfo{details: details}
}

func (p *PGPInfo) DrawSignature(ctx *ui.Context) {
	errorStyle := tcell.StyleDefault.Background(tcell.ColorRed).
		Foreground(tcell.ColorWhite).Bold(true)
	softErrorStyle := tcell.StyleDefault.Foreground(tcell.ColorYellow).Bold(true)
	validStyle := tcell.StyleDefault.Foreground(tcell.ColorGreen).Bold(true)

	// TODO: Nicer prompt for TOFU, fetch from keyserver, etc
	if errors.Is(p.details.SignatureError, pgperrors.ErrUnknownIssuer) ||
		p.details.SignedBy == nil {

		x := ctx.Printf(0, 0, softErrorStyle, "*")
		x += ctx.Printf(x, 0, tcell.StyleDefault,
			" Signed with unknown key (%8X); authenticity unknown",
			p.details.SignedByKeyId)
	} else if p.details.SignatureError != nil {
		x := ctx.Printf(0, 0, errorStyle, "Invalid signature!")
		x += ctx.Printf(x, 0, tcell.StyleDefault.
			Foreground(tcell.ColorRed).Bold(true),
			" This message may have been tampered with! (%s)",
			p.details.SignatureError.Error())
	} else {
		entity := p.details.SignedBy.Entity
		ident := entity.PrimaryIdentity()

		x := ctx.Printf(0, 0, validStyle, "✓ Authentic ")
		x += ctx.Printf(x, 0, tcell.StyleDefault,
			"Signature from %s (%8X)",
			ident.Name, p.details.SignedByKeyId)
	}
}

func (p *PGPInfo) DrawEncryption(ctx *ui.Context, y int) {
	validStyle := tcell.StyleDefault.Foreground(tcell.ColorGreen).Bold(true)
	entity := p.details.DecryptedWith.Entity
	ident := entity.PrimaryIdentity()

	x := ctx.Printf(0, y, validStyle, "✓ Encrypted ")
	x += ctx.Printf(x, y, tcell.StyleDefault,
		"To %s (%8X) ", ident.Name, p.details.DecryptedWith.PublicKey.KeyId)
}

func (p *PGPInfo) Draw(ctx *ui.Context) {
	ctx.Fill(0, 0, ctx.Width(), ctx.Height(), ' ', tcell.StyleDefault)
	if p.details.IsSigned && p.details.IsEncrypted {
		p.DrawSignature(ctx)
		p.DrawEncryption(ctx, 1)
	} else if p.details.IsSigned {
		p.DrawSignature(ctx)
	} else if p.details.IsEncrypted {
		p.DrawEncryption(ctx, 0)
	}
}

func (p *PGPInfo) Invalidate() {
	p.DoInvalidate(p)
}