-
Notifications
You must be signed in to change notification settings - Fork 0
/
srp_test.go
126 lines (97 loc) · 3.56 KB
/
srp_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package srp
import (
"strings"
"testing"
"github.com/kangaroux/go-wow-srp6/internal"
"github.com/stretchr/testify/assert"
)
func TestX(t *testing.T) {
rows := internal.MustLoadTestData("testdata/srp/calculate_x.csv")
t.Run("generated test data", func(t *testing.T) {
for _, row := range rows {
username := row[0]
password := row[1]
salt := internal.MustDecodeHex(row[2])
expected := internal.MustDecodeHex(row[3])
assert.Equal(t, expected, calculateX(username, password, salt))
}
})
t.Run("username/pass are case insensitive", func(t *testing.T) {
row := rows[0]
username := row[0]
password := row[1]
salt := internal.MustDecodeHex(row[2])
first := calculateX(strings.ToLower(username), strings.ToLower(password), salt)
second := calculateX(strings.ToUpper(username), strings.ToUpper(password), salt)
assert.Equal(t, first, second)
})
}
func TestVerifier(t *testing.T) {
rows := internal.MustLoadTestData("testdata/srp/calculate_verifier.csv")
t.Run("generated test data", func(t *testing.T) {
for _, row := range rows {
username := row[0]
password := row[1]
salt := internal.MustDecodeHex(row[2])
expected := internal.MustDecodeHex(row[3])
assert.Equal(t, expected, PasswordVerifier(username, password, salt))
}
})
t.Run("username/pass are case insensitive", func(t *testing.T) {
row := rows[0]
username := row[0]
password := row[1]
salt := internal.MustDecodeHex(row[2])
first := PasswordVerifier(strings.ToLower(username), strings.ToLower(password), salt)
second := PasswordVerifier(strings.ToUpper(username), strings.ToUpper(password), salt)
assert.Equal(t, first, second)
})
}
func TestServerPublicKey(t *testing.T) {
rows := internal.MustLoadTestData("testdata/srp/calculate_server_public_key.csv")
for _, row := range rows {
verifier := internal.MustDecodeHex(row[0])
privateKey := internal.MustDecodeHex(row[1])
expected := internal.MustDecodeHex(row[2])
assert.Equal(t, expected, ServerPublicKey(verifier, privateKey))
}
}
func TestCalculateU(t *testing.T) {
rows := internal.MustLoadTestData("testdata/srp/calculate_u.csv")
for _, row := range rows {
clientPublic := internal.MustDecodeHex(row[0])
serverPublic := internal.MustDecodeHex(row[1])
expected := internal.MustDecodeHex(row[2])
assert.Equal(t, expected, calculateU(clientPublic, serverPublic))
}
}
func TestServerSKey(t *testing.T) {
rows := internal.MustLoadTestData("testdata/srp/calculate_server_s.csv")
for _, row := range rows {
clientPublic := internal.MustDecodeHex(row[0])
verifier := internal.MustDecodeHex(row[1])
u := internal.MustDecodeHex(row[2])
serverPrivate := internal.MustDecodeHex(row[3])
expected := internal.MustDecodeHex(row[4])
assert.Equal(t, expected, calculateServerSKey(clientPublic, verifier, u, serverPrivate))
}
}
func TestInterleave(t *testing.T) {
rows := internal.MustLoadTestData("testdata/srp/calculate_interleaved.csv")
for _, row := range rows {
s := internal.MustDecodeHex(row[0])
expected := internal.MustDecodeHex(row[1])
assert.Equal(t, expected, calculateInterleave(s))
}
}
func TestServerSessionKey(t *testing.T) {
rows := internal.MustLoadTestData("testdata/srp/calculate_server_session_key.csv")
for _, row := range rows {
clientPublic := internal.MustDecodeHex(row[0])
serverPrivate := internal.MustDecodeHex(row[1])
verifier := internal.MustDecodeHex(row[2])
expected := internal.MustDecodeHex(row[3])
serverPublic := ServerPublicKey(verifier, serverPrivate)
assert.Equal(t, expected, SessionKey(clientPublic, serverPublic, serverPrivate, verifier))
}
}