I'm trying to setup a tcp socket system with TLS and I have big amount of data in response. I know that the TLS only support 2^14 bytes data, but most of the time I will have more than this, for example there is some part of the code which is return back 170.000 user. I wondering how can I solve this issue with TLS. Of course I want some kind of encryption between the client and server. My current code is basic implementation of the tls.
func Handle() {
conf := TLS()
listener, err = tls.Listen("tcp", "0.0.0.0:7777", &conf)
checkError(err)
defer listener.Close()
for {
conn, err := listener.Accept()
checkError(err)
go handleRequest(conn, db)
}
}
func TLS() tls.Config {
cert, err := tls.LoadX509KeyPair("certs/publickey.cer", "certs/private.key")
checkError(err)
tlsConfig := tls.Config{Certificates: []tls.Certificate{cert}}
tlsConfig.Time = func() time.Time { return time.Now() }
tlsConfig.Rand = rand.Reader
return tlsConfig
}
On client side:
func withTls() {
conn, err := tls.Dial(
"tcp",
"127.0.0.1:7777",
&tls.Config{
InsecureSkipVerify: true,
ServerName: "127.0.0.1",
})
checkError(err)
conn.Write([]byte(text))
var buf [16000]byte
n, err := conn.Read(buf[0:])
checkError(err)
conn.Close()
}
What is your offer to use for encryption? Without the TLS on the clientside I got the whole response of the server. The encryption is important because there is communication between servers.
The current speed avarage 15ms/req, I want to keep this speed, which is depend on the data size, but it isn't related to TLS.