TLS connections implemented

This commit is contained in:
Andreas Neue 2016-08-06 20:08:42 +02:00
parent e6579a4b9a
commit ace62fe367
1 changed files with 23 additions and 1 deletions

View File

@ -3,6 +3,8 @@
package ircd
import (
"crypto/rand"
"crypto/tls"
"fmt"
"net"
"os"
@ -148,7 +150,7 @@ func (sv *Server) listen(laddr string) {
os.Exit(-1)
}
for {
time.Sleep(1 * time.Millisecond)
time.Sleep(10 * time.Millisecond)
conn, err := listen.Accept()
if err != nil {
xlog.Error(err.Error())
@ -160,6 +162,26 @@ func (sv *Server) listen(laddr string) {
}
func (sv *Server) listenTls(laddr string) {
cert, err := tls.LoadX509KeyPair("cert/server.pem", "cert/server.key")
if err != nil {
xlog.Fatal(err.Error())
}
cfg := tls.Config{Certificates: []tls.Certificate{cert}}
cfg.Rand = rand.Reader
listen, err := tls.Listen("tcp", laddr, &cfg)
if err != nil {
xlog.Fatal(err.Error())
}
for {
time.Sleep(10 * time.Millisecond)
conn, err := listen.Accept()
if err != nil {
xlog.Error(err.Error())
} else {
NewRemoteClient(sv, conn)
sv.connectionsCount++
}
}
}
func (sv *Server) dispatcher() (err error) {