-
Notifications
You must be signed in to change notification settings - Fork 40
/
main.go
54 lines (45 loc) · 913 Bytes
/
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
package main
import (
"io/ioutil"
"mmtls/mars"
"os"
"github.com/anonymous5l/console"
)
func SaveSessionToFile(session *mars.Session) error {
o, err := os.OpenFile("session", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
if err != nil {
return err
}
defer o.Close()
o.Write(session.SaveSession())
return nil
}
func LoadSessionFromFile() (*mars.Session, error) {
o, err := os.Open("session")
if err != nil {
return nil, err
}
defer o.Close()
buf, err := ioutil.ReadAll(o)
if err != nil {
return nil, err
}
session, err := mars.LoadSession(buf)
if err != nil {
return nil, err
}
return session, nil
}
func main() {
client := mars.NewMMTLSClient()
if session, err := LoadSessionFromFile(); err == nil {
client.Session = session
}
if err := client.Handshake(); err != nil {
console.Err("%s", err)
return
}
if client.Session != nil {
SaveSessionToFile(client.Session)
}
}