forked from willscott/talexmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.go
85 lines (71 loc) · 2.16 KB
/
proxy.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
package main
import (
"crypto/tls"
"flag"
"fmt"
"net"
"os"
"sync"
"./xmpp"
talekcommon "github.com/privacylab/talek/common"
"github.com/privacylab/talek/libtalek"
)
func main() {
serverPort := flag.Int("port", 5222, "port number to listen on")
talekConfig := flag.String("config", "talek.conf", "Talek client configuration")
flag.Parse()
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", *serverPort))
if err != nil {
panic(err)
}
defer listener.Close()
var contacts = make(map[string]chan<- []byte)
var messagebus = make(chan xmpp.Message)
var connectbus = make(chan xmpp.Connect)
var disconnectbus = make(chan xmpp.Disconnect)
talekconf := libtalek.ClientConfigFromFile(*talekConfig)
if talekconf == nil {
panic("Could not load talek configuration file")
}
leader := talekcommon.NewFrontendRPC("rpc", talekconf.FrontendAddr)
backend := libtalek.NewClient("talexmpp", *talekconf, leader)
// restore from saved contact state
am := AccountManager{Online: contacts, Backend: backend, lock: &sync.Mutex{}}
if _, err := os.Stat("./cert.pem"); err != nil && os.IsNotExist(err) {
MakeSelfSignedCert()
}
var cert, _ = tls.LoadX509KeyPair("./cert.pem", "./key.pem")
var tlsConfig = tls.Config{
MinVersion: tls.VersionTLS10,
Certificates: []tls.Certificate{cert},
CipherSuites: []uint16{tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
}
xmppServer := &xmpp.Server{
Accounts: am,
ConnectBus: connectbus,
Extensions: []xmpp.Extension{
&xmpp.NormalMessageExtension{MessageBus: messagebus},
&xmpp.RosterExtension{Accounts: am},
&GlueExtension{},
&RosterManagementExtension{Accounts: am, Client: backend},
},
DisconnectBus: disconnectbus,
Domain: "localhost",
TLSConfig: &tlsConfig,
}
go am.routeRoutine(messagebus)
go am.connectRoutine(connectbus)
go am.disconnectRoutine(disconnectbus)
for {
conn, err := listener.Accept()
if err != nil {
panic(err)
}
go xmppServer.TCPAnswer(conn)
}
}