-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
108 lines (100 loc) · 2.6 KB
/
main.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
package main
import (
"VSPAKE/check"
"VSPAKE/client"
"VSPAKE/common"
"VSPAKE/server"
"fmt"
)
func hex(b []byte) string {
hex := "["
for _, v := range b {
hex += fmt.Sprintf(" 0x%02x ,", v)
}
hex += "]"
return hex
}
func Autopolish(s string) []byte {
b := make([]byte, 32)
for i := 0; i < len(b); i++ {
b[i] = 0xff
}
// fmt.Println("b", b)
copy(b, s)
return b
}
func main() {
// for ii := 0; ii < 100; ii++ {
fmt.Println("-----------------------")
cliname := Autopolish("client_user_Alice")
servname := Autopolish("server_user_Bob")
passwd := Autopolish("password")
hkey := common.GetHashKey(servname, cliname, passwd)
_, client := client.InitClient(passwd, cliname)
_, server := server.InitClient(hkey, servname)
recvthing := client.ClientHello()
// fmt.Println("client hello", hex(recvthing))
server.RecvHelloMessage(recvthing)
recvthing = server.ServerKeyExchange()
// fmt.Println("server key exchange", hex(recvthing))
client.Update(recvthing)
recvthing = client.SendClientKeyExchange()
// fmt.Println("client key exchange", hex(recvthing))
server.Update(recvthing)
// server.PrintpK()
// client.PrintpK()
keq := check.CheckK(server, client)
if !keq {
server.Printall()
client.Printall()
return
}
client.GetAuthentKeys()
server.GetAuthentKeys()
fmt.Println("PreMasterSecret eqal?", check.CheckPreMasterSecret(server, client))
fmt.Println("akey eqal?", check.Checkakey(server, client))
//explicit mutual aythentication
client.GetKDFs()
server.GetKDFs()
recvthing = server.SendKDF1()
ans := client.AuthenticateKDF1(recvthing)
if ans {
fmt.Println("KDF1 pass")
} else {
fmt.Println("KDF1 fail")
// return
}
recvthing = client.SendKDF2()
ans = server.AuthenticateKDF2(recvthing)
if ans {
fmt.Println("KDF2 pass")
} else {
fmt.Println("KDF2 fail")
// return
}
//Compute master secret and session key
client.GetMasterSecretAndKey()
server.GetMasterSecretAndKey()
fmt.Println("MasterSecret eqal?", check.CheckMasterSecret(server, client))
fmt.Println("SessionKey eqal?", check.CheckSessionKey(server, client))
cz := client.Checkzero()
if !cz {
fmt.Println("client check zero fail")
// return
}
cz = server.Checkzero()
if !cz {
fmt.Println("client check zero fail")
// return
}
//send and recv message
cAead, _ := client.Getgcm()
sAead, _ := server.Getgcm()
recvthing = client.SendText([]byte("hello"), cAead)
detext, _ := server.DecryptText(recvthing, sAead)
fmt.Println("server recv", string(detext))
recvthing = server.SendText([]byte("world"), sAead)
detext, _ = client.DecryptText(recvthing, cAead)
fmt.Println("client recv", string(detext))
// }
}