Skip to content
Snippets Groups Projects
Commit 822b9680 authored by Daniel Lublin's avatar Daniel Lublin
Browse files

Merge branch 'defaultport' into 'master'

Allow passing only host to Connect, which will use default port

See merge request !6
parents e6badb38 548b0db8
No related branches found
No related tags found
1 merge request!6Allow passing only host to Connect, which will use default port
......@@ -8,6 +8,8 @@ import (
"errors"
"fmt"
"net"
"strconv"
"strings"
"time"
)
......@@ -43,7 +45,9 @@ const (
)
const (
AES_SIV_CMAC_256 = 0x0f
AES_SIV_CMAC_256 = 0x0f
DEFAULT_NTSKE_PORT = 4460
DEFAULT_NTP_PORT = 123
)
const alpn = "ntske/1"
......@@ -322,6 +326,7 @@ func NewListener(listener net.Listener) (*KeyExchange, error) {
}
// Connect connects to host:port and establishes an NTS-KE connection.
// If :port is left out, protocol default port is used.
// No further action is done.
func Connect(hostport string, config *tls.Config, debug bool) (*KeyExchange, error) {
config.NextProtos = []string{alpn}
......@@ -329,17 +334,23 @@ func Connect(hostport string, config *tls.Config, debug bool) (*KeyExchange, err
ke := new(KeyExchange)
ke.Debug = debug
ke.hostport = hostport
host, _, _ := net.SplitHostPort(hostport)
host, _, err := net.SplitHostPort(ke.hostport)
if err != nil {
if !strings.Contains(err.Error(), "missing port in address") {
return nil, err
}
ke.hostport = net.JoinHostPort(ke.hostport, strconv.Itoa(DEFAULT_NTSKE_PORT))
}
ke.Meta.Server = host // Default to same server for NTP as NTS
ke.Meta.Port = 123 // Default port for NTP
var err error
ke.Meta.Port = DEFAULT_NTP_PORT
if ke.Debug {
fmt.Printf("Connecting to KE server %v\n", ke.hostport)
}
ke.Conn, err = tls.DialWithDialer(&net.Dialer{
Timeout: time.Second * 5,
}, "tcp", hostport, config)
}, "tcp", ke.hostport, config)
if err != nil {
return nil, err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment