diff options
Diffstat (limited to 'finger')
-rw-r--r-- | finger/serve.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/finger/serve.go b/finger/serve.go index f959373..cb8f0fd 100644 --- a/finger/serve.go +++ b/finger/serve.go @@ -2,6 +2,7 @@ package finger import ( "context" + "crypto/tls" "fmt" "io" "net" @@ -41,6 +42,31 @@ func NewServer( return fs, nil } +func NewTLSServer( + ctx context.Context, + hostname string, + network string, + address string, + handler types.Handler, + baseLog logging.Logger, + tlsConfig *tls.Config, +) (types.Server, error) { + fs := &fingerServer{handler: handler} + + hostname = internal.JoinDefaultPort(hostname, "79") + address = internal.JoinDefaultPort(address, "79") + + var err error + fs.Server, err = internal.NewServer(ctx, hostname, network, address, baseLog, fs.handleConn) + if err != nil { + return nil, err + } + + fs.Listener = tls.NewListener(fs.Listener, tlsConfig) + + return fs, nil +} + func (fs *fingerServer) handleConn(conn net.Conn) { request, err := ParseRequest(conn) if err != nil { @@ -51,6 +77,11 @@ func (fs *fingerServer) handleConn(conn net.Conn) { request.Server = fs request.RemoteAddr = conn.RemoteAddr() + if tlsconn, ok := conn.(*tls.Conn); ok { + state := tlsconn.ConnectionState() + request.TLSState = &state + } + defer func() { if r := recover(); r != nil { _ = fs.LogError("msg", "panic in handler", "err", r) |