forked from coyim/coyim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fingerprint_verification.go
81 lines (63 loc) · 1.95 KB
/
fingerprint_verification.go
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
78
79
80
81
package gui
import (
"fmt"
"github.com/twstrike/coyim/Godeps/_workspace/src/github.com/twstrike/gotk3adapter/gtki"
"github.com/twstrike/coyim/client"
"github.com/twstrike/coyim/config"
"github.com/twstrike/coyim/i18n"
)
func buildVerifyFingerprintDialog(accountName string, ourFp []byte, uid string, theirFp []byte) gtki.Dialog {
var message string
var builderName string
if theirFp == nil {
builderName = "VerifyFingerprintUnknown"
message = fmt.Sprintf(i18n.Local(
"You can't verify the fingerprint for %s yet.\n"+
"You first have to start an encrypted conversation with them.",
), uid)
} else {
m := i18n.Local(`
Is this the correct fingerprint for %[1]s?
Fingerprint for you (%[3]s):
%[4]s
Purported fingerprint for %[1]s:
%[2]s
`)
message = fmt.Sprintf(m,
uid,
config.FormatFingerprint(theirFp),
accountName,
config.FormatFingerprint(ourFp),
)
builderName = "VerifyFingerprint"
}
builder := builderForDefinition(builderName)
obj, _ := builder.GetObject("dialog")
dialog := obj.(gtki.Dialog)
obj, _ = builder.GetObject("message")
l := obj.(gtki.Label)
l.SetText(message)
l.SetSelectable(true)
dialog.SetTitle(fmt.Sprintf(i18n.Local("Verify fingerprint for %s"), uid))
return dialog
}
func verifyFingerprintDialog(account *account, uid string, parent gtki.Window) gtki.ResponseType {
accountConfig := account.session.GetConfig()
conversation, _ := account.session.ConversationManager().EnsureConversationWith(uid)
ourFp := conversation.OurFingerprint()
theirFp := conversation.TheirFingerprint()
dialog := buildVerifyFingerprintDialog(accountConfig.Account, ourFp, uid, theirFp)
defer dialog.Destroy()
dialog.SetTransientFor(parent)
dialog.ShowAll()
responseType := gtki.ResponseType(dialog.Run())
switch responseType {
case gtki.RESPONSE_YES:
account.executeCmd(client.AuthorizeFingerprintCmd{
Account: accountConfig,
Peer: uid,
Fingerprint: theirFp,
})
}
return responseType
}