Add a --protocol-min-version option to router
To allow users to forgo compatibility with Weave Net 1.0 in order to avoid #912, by setting --protocol-min-version=2. Defaults to --protocol-min-version=1, i.e. compatible but vulnerable.
This commit is contained in:
1 parent
882f14d50c
commit
14d346db8b
5 files changed
+77
-65
No files matched your search
+25
-18
@@ -32,28 +32,30 @@ func main() {
|
|||||||
runtime.GOMAXPROCS(procs)
|
runtime.GOMAXPROCS(procs)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
config weave.Config
|
config weave.Config
|
||||||
justVersion bool
|
justVersion bool
|
||||||
ifaceName string
|
protocolMinVersion int
|
||||||
routerName string
|
ifaceName string
|
||||||
nickName string
|
routerName string
|
||||||
password string
|
nickName string
|
||||||
wait int
|
password string
|
||||||
pktdebug bool
|
wait int
|
||||||
logLevel string
|
pktdebug bool
|
||||||
prof string
|
logLevel string
|
||||||
bufSzMB int
|
prof string
|
||||||
noDiscovery bool
|
bufSzMB int
|
||||||
httpAddr string
|
noDiscovery bool
|
||||||
iprangeCIDR string
|
httpAddr string
|
||||||
ipsubnetCIDR string
|
iprangeCIDR string
|
||||||
peerCount int
|
ipsubnetCIDR string
|
||||||
apiPath string
|
peerCount int
|
||||||
peers []string
|
apiPath string
|
||||||
|
peers []string
|
||||||
)
|
)
|
||||||
|
|
||||||
mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit")
|
mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit")
|
||||||
mflag.IntVar(&config.Port, []string{"#port", "-port"}, weave.Port, "router port")
|
mflag.IntVar(&config.Port, []string{"#port", "-port"}, weave.Port, "router port")
|
||||||
|
mflag.IntVar(&protocolMinVersion, []string{"-min-protocol-version"}, weave.ProtocolMinVersion, "minimum weave protocol version")
|
||||||
mflag.StringVar(&ifaceName, []string{"#iface", "-iface"}, "", "name of interface to capture/inject from (disabled if blank)")
|
mflag.StringVar(&ifaceName, []string{"#iface", "-iface"}, "", "name of interface to capture/inject from (disabled if blank)")
|
||||||
mflag.StringVar(&routerName, []string{"#name", "-name"}, "", "name of router (defaults to MAC of interface)")
|
mflag.StringVar(&routerName, []string{"#name", "-name"}, "", "name of router (defaults to MAC of interface)")
|
||||||
mflag.StringVar(&nickName, []string{"#nickname", "-nickname"}, "", "nickname of peer (defaults to hostname)")
|
mflag.StringVar(&nickName, []string{"#nickname", "-nickname"}, "", "nickname of peer (defaults to hostname)")
|
||||||
@@ -82,6 +84,11 @@ func main() {
|
|||||||
Log.Println("Command line options:", options())
|
Log.Println("Command line options:", options())
|
||||||
Log.Println("Command line peers:", peers)
|
Log.Println("Command line peers:", peers)
|
||||||
|
|
||||||
|
if protocolMinVersion < weave.ProtocolMinVersion || protocolMinVersion > weave.ProtocolMaxVersion {
|
||||||
|
Log.Fatalf("--min-protocol-version must be in range [%d,%d]", weave.ProtocolMinVersion, weave.ProtocolMaxVersion)
|
||||||
|
}
|
||||||
|
config.ProtocolMinVersion = byte(protocolMinVersion)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if ifaceName != "" {
|
if ifaceName != "" {
|
||||||
|
|||||||
@@ -285,10 +285,12 @@ func (conn *LocalConnection) run(actionChan <-chan ConnectionAction, finished ch
|
|||||||
|
|
||||||
conn.TCPConn.SetLinger(0)
|
conn.TCPConn.SetLinger(0)
|
||||||
intro, err := ProtocolIntroParams{
|
intro, err := ProtocolIntroParams{
|
||||||
Features: conn.makeFeatures(),
|
MinVersion: conn.Router.ProtocolMinVersion,
|
||||||
Conn: conn.TCPConn,
|
MaxVersion: ProtocolMaxVersion,
|
||||||
Password: conn.Router.Password,
|
Features: conn.makeFeatures(),
|
||||||
Outbound: conn.outbound,
|
Conn: conn.TCPConn,
|
||||||
|
Password: conn.Router.Password,
|
||||||
|
Outbound: conn.outbound,
|
||||||
}.DoIntro()
|
}.DoIntro()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
+22
-24
@@ -10,9 +10,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Protocol = "weave"
|
Protocol = "weave"
|
||||||
ProtocolMinVersion byte = 1
|
ProtocolMinVersion = 1
|
||||||
ProtocolVersion byte = 2
|
ProtocolMaxVersion = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -48,10 +48,12 @@ type ProtocolIntroConn interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ProtocolIntroParams struct {
|
type ProtocolIntroParams struct {
|
||||||
Features map[string]string
|
MinVersion byte
|
||||||
Conn ProtocolIntroConn
|
MaxVersion byte
|
||||||
Password []byte
|
Features map[string]string
|
||||||
Outbound bool
|
Conn ProtocolIntroConn
|
||||||
|
Password []byte
|
||||||
|
Outbound bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ProtocolIntroResults struct {
|
type ProtocolIntroResults struct {
|
||||||
@@ -63,15 +65,11 @@ type ProtocolIntroResults struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (params ProtocolIntroParams) DoIntro() (res ProtocolIntroResults, err error) {
|
func (params ProtocolIntroParams) DoIntro() (res ProtocolIntroResults, err error) {
|
||||||
return params.doIntro(ProtocolVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (params ProtocolIntroParams) doIntro(maxVersion byte) (res ProtocolIntroResults, err error) {
|
|
||||||
if err = params.Conn.SetDeadline(time.Now().Add(HeaderTimeout)); err != nil {
|
if err = params.Conn.SetDeadline(time.Now().Add(HeaderTimeout)); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.Version, err = params.exchangeProtocolHeader(maxVersion); err != nil {
|
if res.Version, err = params.exchangeProtocolHeader(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,12 +99,12 @@ func (params ProtocolIntroParams) doIntro(maxVersion byte) (res ProtocolIntroRes
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (params ProtocolIntroParams) exchangeProtocolHeader(maxVersion byte) (byte, error) {
|
func (params ProtocolIntroParams) exchangeProtocolHeader() (byte, error) {
|
||||||
// Write in a separate goroutine to avoid the possibility of
|
// Write in a separate goroutine to avoid the possibility of
|
||||||
// deadlock. The result channel is of size 1 so that the
|
// deadlock. The result channel is of size 1 so that the
|
||||||
// goroutine does not linger even if we encounter an error on
|
// goroutine does not linger even if we encounter an error on
|
||||||
// the read side.
|
// the read side.
|
||||||
sendHeader := append(ProtocolBytes, ProtocolMinVersion, maxVersion)
|
sendHeader := append(ProtocolBytes, params.MinVersion, params.MaxVersion)
|
||||||
writeDone := make(chan error, 1)
|
writeDone := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
_, err := params.Conn.Write(sendHeader)
|
_, err := params.Conn.Write(sendHeader)
|
||||||
@@ -127,27 +125,27 @@ func (params ProtocolIntroParams) exchangeProtocolHeader(maxVersion byte) (byte,
|
|||||||
|
|
||||||
theirMinVersion := header[len(ProtocolBytes)]
|
theirMinVersion := header[len(ProtocolBytes)]
|
||||||
minVersion := theirMinVersion
|
minVersion := theirMinVersion
|
||||||
if ProtocolMinVersion > minVersion {
|
if params.MinVersion > minVersion {
|
||||||
minVersion = ProtocolMinVersion
|
minVersion = params.MinVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
theirVersion := header[len(ProtocolBytes)+1]
|
theirMaxVersion := header[len(ProtocolBytes)+1]
|
||||||
version := theirVersion
|
maxVersion := theirMaxVersion
|
||||||
if version > maxVersion {
|
if maxVersion > params.MaxVersion {
|
||||||
version = maxVersion
|
maxVersion = params.MaxVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
if minVersion > version {
|
if minVersion > maxVersion {
|
||||||
return 0, fmt.Errorf("remote version range [%d,%d] is incompatible with ours [%d,%d]",
|
return 0, fmt.Errorf("remote version range [%d,%d] is incompatible with ours [%d,%d]",
|
||||||
theirMinVersion, theirVersion,
|
theirMinVersion, theirMaxVersion,
|
||||||
ProtocolMinVersion, maxVersion)
|
params.MinVersion, params.MaxVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := <-writeDone; err != nil {
|
if err := <-writeDone; err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return version, nil
|
return maxVersion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// The V1 procotol consists of the protocol identification/version
|
// The V1 procotol consists of the protocol identification/version
|
||||||
|
|||||||
+16
-12
@@ -33,10 +33,10 @@ func connPair() (ProtocolIntroConn, ProtocolIntroConn) {
|
|||||||
return &a, &b
|
return &a, &b
|
||||||
}
|
}
|
||||||
|
|
||||||
func doIntro(t *testing.T, ver byte, params ProtocolIntroParams) <-chan ProtocolIntroResults {
|
func doIntro(t *testing.T, params ProtocolIntroParams) <-chan ProtocolIntroResults {
|
||||||
ch := make(chan ProtocolIntroResults, 1)
|
ch := make(chan ProtocolIntroResults, 1)
|
||||||
go func() {
|
go func() {
|
||||||
res, err := params.doIntro(ver)
|
res, err := params.DoIntro()
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
ch <- res
|
ch <- res
|
||||||
}()
|
}()
|
||||||
@@ -45,17 +45,21 @@ func doIntro(t *testing.T, ver byte, params ProtocolIntroParams) <-chan Protocol
|
|||||||
|
|
||||||
func doProtocolIntro(t *testing.T, aver, bver byte, password []byte) byte {
|
func doProtocolIntro(t *testing.T, aver, bver byte, password []byte) byte {
|
||||||
aconn, bconn := connPair()
|
aconn, bconn := connPair()
|
||||||
aresch := doIntro(t, aver, ProtocolIntroParams{
|
aresch := doIntro(t, ProtocolIntroParams{
|
||||||
Features: map[string]string{"Name": "A"},
|
MinVersion: ProtocolMinVersion,
|
||||||
Conn: aconn,
|
MaxVersion: aver,
|
||||||
Outbound: true,
|
Features: map[string]string{"Name": "A"},
|
||||||
Password: password,
|
Conn: aconn,
|
||||||
|
Outbound: true,
|
||||||
|
Password: password,
|
||||||
})
|
})
|
||||||
bresch := doIntro(t, bver, ProtocolIntroParams{
|
bresch := doIntro(t, ProtocolIntroParams{
|
||||||
Features: map[string]string{"Name": "B"},
|
MinVersion: ProtocolMinVersion,
|
||||||
Conn: bconn,
|
MaxVersion: bver,
|
||||||
Outbound: false,
|
Features: map[string]string{"Name": "B"},
|
||||||
Password: password,
|
Conn: bconn,
|
||||||
|
Outbound: false,
|
||||||
|
Password: password,
|
||||||
})
|
})
|
||||||
ares := <-aresch
|
ares := <-aresch
|
||||||
bres := <-bresch
|
bres := <-bresch
|
||||||
|
|||||||
+8
-7
@@ -28,13 +28,14 @@ const (
|
|||||||
type LogFrameFunc func(string, []byte, *EthernetDecoder)
|
type LogFrameFunc func(string, []byte, *EthernetDecoder)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Port int
|
Port int
|
||||||
Iface *net.Interface
|
ProtocolMinVersion byte
|
||||||
Password []byte
|
Iface *net.Interface
|
||||||
ConnLimit int
|
Password []byte
|
||||||
PeerDiscovery bool
|
ConnLimit int
|
||||||
BufSz int
|
PeerDiscovery bool
|
||||||
LogFrame LogFrameFunc
|
BufSz int
|
||||||
|
LogFrame LogFrameFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
type Router struct {
|
type Router struct {
|
||||||
|
|||||||
Reference in new issue
Block a user