TLS server

You can set up a listener just like a normal socket connection, but with encryption. Just call the TLS Listen() function, and provide it your certificate and private key. The certificate and key generated using the previous examples will work.

The following program will create a TLS server and echo back any data received, then close the connection. The server will not require or verify client certificates, but the code to do so is left commented out for reference in case you want to authenticate clients with certificates:

package mainimport (   "bufio"   "crypto/tls"   "fmt"   "log"   "net"   "os")func printUsage() {   fmt.Println(os.Args[0] + ` - Start a TLS echo serverServer will echo one message received back to client.Provide a certificate ...

Get Security with Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.