Skip to content

Commit

Permalink
Move cli specific SMP functionality to cli folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie Tolentino committed Aug 23, 2017
1 parent 36f2b75 commit 97ea11d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
16 changes: 16 additions & 0 deletions cli/session_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,20 @@ func (c *cliUI) handleLogEvent(ev events.Log) {
}
}

func (c *cliUI) handleSMPEvent(ev events.SMP) {
switch ev.Type {
case events.SecretNeeded:
info(c.term, c.termControl, fmt.Sprintf("%s is attempting to authenticate. Please supply mutual shared secret with /otr-auth user secret", ev.From))
if question := ev.Body; len(question) > 0 {
info(c.term, c.termControl, fmt.Sprintf("%s asks: %s", ev.From, question))
}
case events.Success:
info(c.term, c.termControl, fmt.Sprintf("Authentication with %s successful", ev.From))
case events.Failure:
alert(c.term, c.termControl, fmt.Sprintf("Authentication with %s failed", ev.From))
}
}

func (c *cliUI) observeSessionEvents() {
for ev := range c.events {
switch t := ev.(type) {
Expand All @@ -117,6 +131,8 @@ func (c *cliUI) observeSessionEvents() {
c.handlePresenceEvent(t)
case events.Message:
c.handleMessageEvent(t)
case events.SMP:
c.handleSMPEvent(t)
default:
log.Printf("unsupported event %#v\n", t)
}
Expand Down
17 changes: 0 additions & 17 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,33 +656,16 @@ func (s *session) receiveClientMessage(from, resource string, when time.Time, bo
s.info(fmt.Sprintf("%s has ended the secure conversation. You should do likewise with /otr-end %s", from, from))
}
case event.SMPSecretNeeded:
// CLI only
s.info(fmt.Sprintf("%s is attempting to authenticate. Please supply mutual shared secret with /otr-auth user secret", from))
if question := eh.SmpQuestion; len(question) > 0 {
s.info(fmt.Sprintf("%s asks: %s", from, question))
}

// GUI only
s.publishSMPEvent(events.SecretNeeded, from, resource, eh.SmpQuestion)
case event.SMPComplete:
// CLI only
s.info(fmt.Sprintf("Authentication with %s successful", from))

// GUI only
s.publishSMPEvent(events.Success, from, resource, "")

s.cmdManager.ExecuteCmd(client.AuthorizeFingerprintCmd{
Account: s.GetConfig(),
Session: s,
Peer: from,
Fingerprint: conversation.TheirFingerprint(),
})

case event.SMPFailed:
// CLI only
s.alert(fmt.Sprintf("Authentication with %s failed", from))

// GUI only
s.publishSMPEvent(events.Failure, from, resource, "")
}

Expand Down

0 comments on commit 97ea11d

Please sign in to comment.