Skip to content

Commit

Permalink
Complete minimal flow for successful verification of channel
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakira Dixon committed Apr 18, 2017
1 parent cb0692d commit b5f26a4
Show file tree
Hide file tree
Showing 23 changed files with 350 additions and 259 deletions.
19 changes: 18 additions & 1 deletion gui/account_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func (u *gtkUI) handleOneAccountEvent(ev interface{}) {
doInUIThread(func() {
u.handleLogEvent(t)
})
case events.SMP:
doInUIThread(func() {
u.handleSMPEvent(t)
})
default:
log.Printf("unsupported event %#v\n", t)
}
Expand Down Expand Up @@ -134,7 +138,7 @@ func convWindowNowOrLater(account *account, peer string, ui *gtkUI, f func(conve
func (u *gtkUI) handlePeerEvent(ev events.Peer) {
identityWarning := func(cv conversationView) {
cv.updateSecurityWarning()
cv.showIdentityVerificationWarning(u)
cv.showVerificationWarning(u)
}

switch ev.Type {
Expand Down Expand Up @@ -213,3 +217,16 @@ func (u *gtkUI) handleDelayedMessageSentEvent(ev events.DelayedMessageSent) {
}
convWin.delayedMessageSent(ev.Tracer)
}

func (u *gtkUI) handleSMPEvent(ev events.SMP) {
account := u.findAccountForSession(ev.Session)
convWin, err := u.roster.openConversationView(account, ev.From, false)
if err != nil {
return
}
if ev.Type == events.SecretNeeded {
convWin.displayRequestForSecret()
} else {
convWin.displayVerificationSuccess()
}
}
51 changes: 45 additions & 6 deletions gui/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
)

type conversationView interface {
showIdentityVerificationWarning(u *gtkUI)
showVerificationWarning(u *gtkUI)
updateSecurityWarning()
show(userInitiated bool)
appendStatus(from string, timestamp time.Time, show, showStatus string, gone bool)
Expand All @@ -37,6 +37,43 @@ type conversationView interface {
appendPendingDelayed()
haveShownPrivateEndedNotification()
haveShownPrivateNotification()
displayRequestForSecret()
displayVerificationSuccess()
}

func (conv *conversationPane) displayRequestForSecret() {
conv.verificationWarning.Hide()
peer, ok := conv.currentPeer()
if !ok {
// XXX: Why would we not have a peer?
}
b := newBuilder("PeerRequestsSMP")
infobar := b.getObj("peer_requests_smp").(gtki.InfoBar)
infobarMsg := b.getObj("message").(gtki.Label)

verificationButton := b.getObj("verification_button").(gtki.Button)
verificationButton.Connect("clicked", func() {
verifyChannelDialog(conv, infobar)
})

message := fmt.Sprintf("%s is waiting for you to finish verifying the security of this channel...", peer.NameForPresentation())
infobarMsg.SetText(message)
infobar.ShowAll()
conv.peerRequestsSMP = infobar
conv.addNotification(infobar)
}

func (conv *conversationPane) displayVerificationSuccess() {
showThatChannelIsVerified(conv.transientParent)
if conv.waitingForSMP != nil {
conv.waitingForSMP.Destroy()
}
if conv.verificationWarning != nil {
conv.verificationWarning.Destroy()
}
if conv.peerRequestsSMP != nil {
conv.peerRequestsSMP.Destroy()
}
}

type conversationWindow struct {
Expand All @@ -59,6 +96,8 @@ type conversationPane struct {
notificationArea gtki.Box
securityWarning gtki.InfoBar
verificationWarning gtki.InfoBar
waitingForSMP gtki.InfoBar
peerRequestsSMP gtki.InfoBar
// The window to set dialogs transient for
transientParent gtki.Window
sync.Mutex
Expand Down Expand Up @@ -211,7 +250,7 @@ func (conv *conversationPane) onEndOtrSignal() {
func (conv *conversationPane) onVerifyFpSignal() {
switch verifyFingerprintDialog(conv.account, conv.to, conv.currentResource(), conv.transientParent) {
case gtki.RESPONSE_YES:
conv.removeIdentityVerificationWarning()
conv.removeVerificationWarning()
}
}

Expand Down Expand Up @@ -488,7 +527,7 @@ func (conv *conversationPane) isVerified(u *gtkUI) bool {
return hasPeer && p.HasTrustedFingerprint(fingerprint)
}

func (conv *conversationPane) showIdentityVerificationWarning(u *gtkUI) {
func (conv *conversationPane) showVerificationWarning(u *gtkUI) {
conv.Lock()
defer conv.Unlock()

Expand All @@ -502,12 +541,12 @@ func (conv *conversationPane) showIdentityVerificationWarning(u *gtkUI) {
return
}

// TODO: should build verify identity notification be a conv method?
conv.verificationWarning = buildVerifyIdentityNotification(conv)
// TODO: should buildStartVerificationNotification() be a method on conv?
conv.verificationWarning = buildStartVerificationNotification(conv)
conv.addNotification(conv.verificationWarning)
}

func (conv *conversationPane) removeIdentityVerificationWarning() {
func (conv *conversationPane) removeVerificationWarning() {
conv.Lock()
defer conv.Unlock()

Expand Down
25 changes: 25 additions & 0 deletions gui/definitions/CannotVerifyWithSMP.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<interface>
<object class="GtkInfoBar" id="error_verifying_smp">
<property name="message-type">GTK_MESSAGE_WARNING</property>
<child internal-child="content_area">
<object class="GtkBox" id="box">
<property name="homogeneous">false</property>
<child>
<object class="GtkLabel" id="message">
<property name="wrap">true</property>
</object>
</child>
</object>
</child>
<child internal-child="action_area">
<object class="GtkBox" id="button_box">
<child>
<object class="GtkButton" id="try_later_button">
<property name="label" translatable="yes">Sorry</property>
<property name="can-default">true</property>
</object>
</child>
</object>
</child>
</object>
</interface>
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Share the one time PIN below with this contact and remember it to validate your connection later.</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">You will be prompted for the PIN after a conversation with them has started.</property>
<property name="label" translatable="yes">Share the one time PIN below with this contact.</property>
</object>
</child>
<child>
Expand Down
24 changes: 24 additions & 0 deletions gui/definitions/PeerRequestsSMP.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<interface>
<object class="GtkInfoBar" id="peer_requests_smp">
<property name="message-type">GTK_MESSAGE_WARNING</property>
<child internal-child="content_area">
<object class="GtkBox" id="box">
<property name="homogeneous">false</property>
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<child>
<object class="GtkLabel" id="message">
<property name="wrap">true</property>
</object>
</child>
</object>
<object class="GtkButtonBox" id="button_box">
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<child>
<object class="GtkButton" id="verification_button">
<property name="label" translatable="yes">Finish verification</property>
</object>
</child>
</object>
</child>
</object>
</interface>
File renamed without changes.
40 changes: 0 additions & 40 deletions gui/definitions/StartVerification.xml

This file was deleted.

File renamed without changes.
36 changes: 36 additions & 0 deletions gui/definitions/cannot_verify_with_smp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package definitions

func init() {
add(`CannotVerifyWithSMP`, &defCannotVerifyWithSMP{})
}

type defCannotVerifyWithSMP struct{}

func (*defCannotVerifyWithSMP) String() string {
return `<interface>
<object class="GtkInfoBar" id="error_verifying_smp">
<property name="message-type">GTK_MESSAGE_WARNING</property>
<child internal-child="content_area">
<object class="GtkBox" id="box">
<property name="homogeneous">false</property>
<child>
<object class="GtkLabel" id="message">
<property name="wrap">true</property>
</object>
</child>
</object>
</child>
<child internal-child="action_area">
<object class="GtkBox" id="button_box">
<child>
<object class="GtkButton" id="try_later_button">
<property name="label" translatable="yes">Sorry</property>
<property name="can-default">true</property>
</object>
</child>
</object>
</child>
</object>
</interface>
`
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package definitions

func init() {
add(`SMPWizard`, &defSMPWizard{})
add(`GeneratePIN`, &defGeneratePIN{})
}

type defSMPWizard struct{}
type defGeneratePIN struct{}

func (*defSMPWizard) String() string {
func (*defGeneratePIN) String() string {
return `<interface>
<object class="GtkDialog" id="dialog">
<property name="window-position">GTK_WIN_POS_CENTER</property>
Expand All @@ -27,12 +27,7 @@ func (*defSMPWizard) String() string {
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Share the one time PIN below with this contact and remember it to validate your connection later.</property>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">You will be prompted for the PIN after a conversation with them has started.</property>
<property name="label" translatable="yes">Share the one time PIN below with this contact.</property>
</object>
</child>
<child>
Expand Down
34 changes: 34 additions & 0 deletions gui/definitions/peer_requests_smp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package definitions

func init() {
add(`PeerRequestsSMP`, &defPeerRequestsSMP{})
}

type defPeerRequestsSMP struct{}

func (*defPeerRequestsSMP) String() string {
return `<interface>
<object class="GtkInfoBar" id="peer_requests_smp">
<property name="message-type">GTK_MESSAGE_WARNING</property>
<child internal-child="content_area">
<object class="GtkBox" id="box">
<property name="homogeneous">false</property>
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<child>
<object class="GtkLabel" id="message">
<property name="wrap">true</property>
</object>
</child>
</object>
<object class="GtkButtonBox" id="button_box">
<property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
<child>
<object class="GtkButton" id="verification_button">
<property name="label" translatable="yes">Finish verification</property>
</object>
</child>
</object>
</child>
</object>
</interface>`
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package definitions

func init() {
add(`SecureChannelCreated`, &defSecureChannelCreated{})
add(`SecureChannelVerified`, &defSecureChannelVerified{})
}

type defSecureChannelCreated struct{}
type defSecureChannelVerified struct{}

func (*defSecureChannelCreated) String() string {
func (*defSecureChannelVerified) String() string {
return `<interface>
<object class="GtkDialog" id="dialog">
<property name="window-position">GTK_WIN_POS_CENTER</property>
Expand Down
Loading

0 comments on commit b5f26a4

Please sign in to comment.