-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathotr_test.go
102 lines (91 loc) · 4.13 KB
/
otr_test.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package prekeyserver
import (
"math/big"
"time"
"github.com/otrv4/gotrx"
. "gopkg.in/check.v1"
)
func (s *GenericServerSuite) Test_prekeyProfile_validate_validatesACorrectPrekeyProfile(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
sessions: newSessionManager(),
}
gs.session("[email protected]").(*realSession).cp = sita.clientProfile
pp, _ := generatePrekeyProfile(gs, sita.instanceTag, time.Date(2028, 11, 5, 4, 46, 00, 13, time.UTC), sita.longTerm)
c.Assert(pp.validate(sita.instanceTag, sita.longTerm.Pub), IsNil)
}
func (s *GenericServerSuite) Test_prekeyProfile_validate_checksForCorrectInstanceTag(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
sessions: newSessionManager(),
}
gs.session("[email protected]").(*realSession).cp = sita.clientProfile
pp, _ := generatePrekeyProfile(gs, sita.instanceTag, time.Date(2028, 11, 5, 4, 46, 00, 13, time.UTC), sita.longTerm)
pp.instanceTag = 0xBADBADBA
pp.sig = gotrx.CreateEddsaSignature(pp.generateSignature(sita.longTerm))
c.Assert(pp.validate(sita.instanceTag, sita.longTerm.Pub), ErrorMatches, "invalid instance tag in prekey profile")
}
func (s *GenericServerSuite) Test_prekeyProfile_validate_checksValidSignature(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
sessions: newSessionManager(),
}
gs.session("[email protected]").(*realSession).cp = sita.clientProfile
pp, _ := generatePrekeyProfile(gs, sita.instanceTag, time.Date(2028, 11, 5, 4, 46, 00, 13, time.UTC), sita.longTerm)
v := pp.sig.S()
v[0] = 0x42
pp.sig = gotrx.CreateEddsaSignature(v)
c.Assert(pp.validate(sita.instanceTag, sita.longTerm.Pub), ErrorMatches, "invalid signature in prekey profile")
}
func (s *GenericServerSuite) Test_prekeyProfile_validate_checksForExpiry(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
sessions: newSessionManager(),
}
gs.session("[email protected]").(*realSession).cp = sita.clientProfile
pp, _ := generatePrekeyProfile(gs, sita.instanceTag, time.Date(2028, 11, 5, 4, 46, 00, 13, time.UTC), sita.longTerm)
pp.expiration = time.Date(2017, 11, 5, 13, 46, 00, 13, time.UTC)
pp.sig = gotrx.CreateEddsaSignature(pp.generateSignature(sita.longTerm))
c.Assert(pp.validate(sita.instanceTag, sita.longTerm.Pub), ErrorMatches, "prekey profile has expired")
}
func (s *GenericServerSuite) Test_prekeyProfile_validate_checksValidSharedPrekeyPoint(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
sessions: newSessionManager(),
}
gs.session("[email protected]").(*realSession).cp = sita.clientProfile
pp, _ := generatePrekeyProfile(gs, sita.instanceTag, time.Date(2028, 11, 5, 4, 46, 00, 13, time.UTC), sita.longTerm)
pp.sharedPrekey = gotrx.CreatePublicKey(identityPoint, gotrx.Ed448Key)
pp.sig = gotrx.CreateEddsaSignature(pp.generateSignature(sita.longTerm))
c.Assert(pp.validate(sita.instanceTag, sita.longTerm.Pub), ErrorMatches, "prekey profile shared prekey is not a valid point")
}
func (s *GenericServerSuite) Test_prekeyMessage_validate_validatesACorrectPrekeyMessage(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
}
pm, _, _, _ := generatePrekeyMessage(gs, sita.instanceTag)
c.Assert(pm.validate(sita.instanceTag), IsNil)
}
func (s *GenericServerSuite) Test_prekeyMessage_validate_checksInvalidInstanceTag(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
}
pm, _, _, _ := generatePrekeyMessage(gs, 0xBADBADBA)
c.Assert(pm.validate(sita.instanceTag), ErrorMatches, "invalid instance tag in prekey message")
}
func (s *GenericServerSuite) Test_prekeyMessage_validate_checksInvalidYPoint(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
}
pm, _, _, _ := generatePrekeyMessage(gs, sita.instanceTag)
pm.y = identityPoint
c.Assert(pm.validate(sita.instanceTag), ErrorMatches, "prekey profile Y point is not a valid point")
}
func (s *GenericServerSuite) Test_prekeyMessage_validate_checksInvalidBValue(c *C) {
gs := &GenericServer{
rand: gotrx.FixtureRand(),
}
pm, _, _, _ := generatePrekeyMessage(gs, sita.instanceTag)
pm.b = new(big.Int).SetBytes([]byte{0x00})
c.Assert(pm.validate(sita.instanceTag), ErrorMatches, "prekey profile B value is not a valid DH group member")
}