Skip to content

Commit 8df6a22

Browse files
committed
Expose SSID for display to the user (coyim#42)
1 parent 10003e0 commit 8df6a22

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

auth_state_machine.go

+4
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ func (s authStateAwaitingDHKey) receiveDHKeyMessage(c *Conversation, msg []byte)
177177
c.keys.setOurCurrentDHKeys(c.ake.secretExponent, c.ake.ourPublicValue)
178178
c.keys.ourCounter++
179179

180+
c.sentRevealSig = true
181+
180182
return authStateAwaitingSig{revealSigMsg: revealSigMsg}, revealSigMsg, nil
181183
}
182184

@@ -221,6 +223,8 @@ func (s authStateAwaitingRevealSig) receiveRevealSigMessage(c *Conversation, msg
221223
c.keys.setOurCurrentDHKeys(c.ake.secretExponent, c.ake.ourPublicValue)
222224
c.keys.ourCounter++
223225

226+
c.sentRevealSig = false
227+
224228
return authStateNone{}, sigMsg, c.akeHasFinished()
225229
}
226230

auth_state_machine_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ func Test_receiveDHKey_TransitionsFromAwaitingDHKeyToAwaitingSigAndSendsRevealSi
149149
ourDHCommitAKE.dhCommitMessage()
150150

151151
c := bobContextAtAwaitingDHKey()
152+
c.sentRevealSig = false
152153

153154
state, msg, err := authStateAwaitingDHKey{}.receiveDHKeyMessage(c, fixtureDHKeyMsg(otrV3{})[otrv3HeaderLen:])
154155

@@ -157,6 +158,7 @@ func Test_receiveDHKey_TransitionsFromAwaitingDHKeyToAwaitingSigAndSendsRevealSi
157158
assertEquals(t, ok, true)
158159
assertEquals(t, dhMsgType(msg), msgTypeRevealSig)
159160
assertEquals(t, dhMsgVersion(msg), uint16(3))
161+
assertEquals(t, c.sentRevealSig, true)
160162
}
161163

162164
func Test_receiveDHKey_AtAwaitingDHKeyStoresGyAndSigKey(t *testing.T) {
@@ -236,12 +238,14 @@ func Test_receiveRevealSig_TransitionsFromAwaitingRevealSigToNoneOnSuccess(t *te
236238
revealSignMsg := fixtureRevealSigMsgBody(otrV2{})
237239

238240
c := aliceContextAtAwaitingRevealSig()
241+
c.sentRevealSig = true
239242

240243
state, msg, err := authStateAwaitingRevealSig{}.receiveRevealSigMessage(c, revealSignMsg)
241244

242245
assertEquals(t, err, nil)
243246
assertEquals(t, state, authStateNone{})
244247
assertEquals(t, dhMsgType(msg), msgTypeSig)
248+
assertEquals(t, c.sentRevealSig, false)
245249
}
246250

247251
func Test_receiveRevealSig_AtAwaitingRevealSigStoresOursAndTheirDHKeysAndIncreaseCounter(t *testing.T) {

conversation.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ type Conversation struct {
4848
securityEventHandler SecurityEventHandler
4949
receivedKeyHandler ReceivedKeyHandler
5050

51-
debug bool
51+
debug bool
52+
sentRevealSig bool
5253
}
5354

5455
func (c *Conversation) messageHeader(msgType byte) ([]byte, error) {

ssid.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package otr3
2+
3+
import "fmt"
4+
5+
// SecureSessionID returns the secure session ID as two formatted strings
6+
// The index returned points to the string that should be highlighted
7+
func (c *Conversation) SecureSessionID() (parts []string, highlightIndex int) {
8+
l := fmt.Sprintf("%0x", c.ssid[0:4])
9+
r := fmt.Sprintf("%0x", c.ssid[4:])
10+
11+
ix := 1
12+
if c.sentRevealSig {
13+
ix = 0
14+
}
15+
16+
return []string{l, r}, ix
17+
}

ssid_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package otr3
2+
3+
import "testing"
4+
5+
func Test_SecureSessionID_returnsTheSessionIDAsTwoFormattedStrings(t *testing.T) {
6+
c := newConversation(nil, fixtureRand())
7+
c.ssid = [8]byte{0x01, 0x02, 0xF3, 0x04, 0x00, 0x06, 0x07, 0x08}
8+
9+
parts, _ := c.SecureSessionID()
10+
11+
assertDeepEquals(t, parts[0], "0102f304")
12+
assertDeepEquals(t, parts[1], "00060708")
13+
}
14+
15+
func Test_SecureSessionID_returnsTheIndexOfTheValueThatShouldBeHighlighted(t *testing.T) {
16+
c := newConversation(nil, fixtureRand())
17+
c.ssid = [8]byte{0x01, 0x02, 0xF3, 0x04, 0x00, 0x06, 0x07, 0x08}
18+
19+
c.sentRevealSig = true
20+
_, f := c.SecureSessionID()
21+
assertEquals(t, f, 0)
22+
23+
c.sentRevealSig = false
24+
_, f = c.SecureSessionID()
25+
assertEquals(t, f, 1)
26+
}

0 commit comments

Comments
 (0)