-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtlsechoserver.go
53 lines (44 loc) · 947 Bytes
/
tlsechoserver.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
package main
import (
"crypto/rand"
"crypto/tls"
"fmt"
"net"
"time"
)
func TLSEchoServer(port string) {
service := port
cert, err := tls.LoadX509KeyPair("somerandomfile.pem", "private.pem") // both of these are a PEM file, that i cant supply
checkError(err)
config := tls.Config{Certificates: []tls.Certificate{cert}}
now := time.Now()
config.Time = func() time.Time { return now }
config.Rand = rand.Reader
listener, err := tls.Listen("tcp", service, &config)
checkError(err)
fmt.Println("Listening")
for {
conn, err := listener.Accept()
if err != nil {
fmt.Println(err.Error())
continue
}
fmt.Println("Accepted")
go handleClientTLS(conn)
}
}
func handleClientTLS(conn net.Conn) {
defer conn.Close()
var buf [512]byte
for {
fmt.Println("Trying to read")
n, err := conn.Read(buf[0:])
if err != nil {
fmt.Println(err)
}
_, err2 := conn.Write(buf[0:n])
if err2 != nil {
return
}
}
}