File: authenticate.go

package info (click to toggle)
golang-github-twstrike-otr3 0.0~git20161015.0.744856d-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,080 kB
  • sloc: ansic: 127; makefile: 76
file content (37 lines) | stat: -rw-r--r-- 1,476 bytes parent folder | download | duplicates (3)
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
package otr3

// StartAuthenticate should be called when the user wants to initiate authentication with a peer.
// The authentication uses an optional question message and a shared secret. The authentication will proceed
// until the event handler reports that SMP is complete, that a secret is needed or that SMP has failed.
func (c *Conversation) StartAuthenticate(question string, mutualSecret []byte) ([]ValidMessage, error) {
	c.smp.ensureSMP()

	tlvs, err := c.smp.state.startAuthenticate(c, question, mutualSecret)

	if err != nil {
		return nil, err
	}

	msgs, _, err := c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, tlvs)
	return msgs, err
}

// ProvideAuthenticationSecret should be called when the peer has started an authentication request, and the UI has been notified that a secret is needed
// It is only valid to call this function if the current SMP state is waiting for a secret to be provided. The return is the potential messages to send.
func (c *Conversation) ProvideAuthenticationSecret(mutualSecret []byte) ([]ValidMessage, error) {
	t, err := c.continueSMP(mutualSecret)
	if err != nil {
		return nil, err
	}

	msgs, _, err := c.createSerializedDataMessage(nil, messageFlagIgnoreUnreadable, []tlv{*t})
	return msgs, err
}

func (c *Conversation) potentialAuthError(toSend []messageWithHeader, err error) ([]messageWithHeader, error) {
	if err != nil {
		c.messageEventWithError(MessageEventSetupError, err)
	}

	return toSend, err
}