Browse Source

protocol: update connection to TLS after sending identity

Signed-off-by: Maciek Borzecki <maciek.borzecki@gmail.com>
bboozzoo/golang
Maciek Borzecki 5 years ago
parent
commit
34f26d176a
1 changed files with 14 additions and 2 deletions
  1. +14
    -2
      protocol/connection.go

+ 14
- 2
protocol/connection.go View File

@ -23,7 +23,7 @@ import (
) )
type Connection struct { type Connection struct {
conn net.Conn
conn *tls.Conn
} }
type Configuration struct { type Configuration struct {
@ -48,7 +48,19 @@ func Dial(ctx context.Context, where string, conf *Configuration) (*Connection,
log.Debugf("identity sent") log.Debugf("identity sent")
return &Connection{conn: conn}, nil
// upgrade to secure connection
tlsConf := tls.Config{
InsecureSkipVerify: true,
Certificates: []tls.Certificate{*conf.Cert},
}
tlsConn := tls.Server(conn, &tlsConf)
if err := tlsConn.Handshake(); err != nil {
log.Errorf("TLS handshake failed: %v", err)
return nil, err
}
return &Connection{conn: tlsConn}, nil
} }
func (c *Connection) Close() error { func (c *Connection) Close() error {


Loading…
Cancel
Save