mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 09:44:03 +03:00
Add secure mode
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
)
|
)
|
||||||
@@ -90,6 +91,9 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo
|
|||||||
publicIPv6 net.IP, publicIPv6Port uint16,
|
publicIPv6 net.IP, publicIPv6Port uint16,
|
||||||
statsIP net.IP, statsPort uint16,
|
statsIP net.IP, statsPort uint16,
|
||||||
secret, adtag string) (*Config, error) {
|
secret, adtag string) (*Config, error) {
|
||||||
|
if strings.HasPrefix(secret, "dd") {
|
||||||
|
secret = secret[2:]
|
||||||
|
}
|
||||||
if len(secret) != 32 {
|
if len(secret) != 32 {
|
||||||
return nil, errors.New("Telegram demands secret of length 32")
|
return nil, errors.New("Telegram demands secret of length 32")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ const (
|
|||||||
ConnectionTypeUnknown ConnectionType = iota
|
ConnectionTypeUnknown ConnectionType = iota
|
||||||
ConnectionTypeAbridged
|
ConnectionTypeAbridged
|
||||||
ConnectionTypeIntermediate
|
ConnectionTypeIntermediate
|
||||||
|
ConnectionTypeSecure
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConnectionProtocol* define which connection protocols to use.
|
// ConnectionProtocol* define which connection protocols to use.
|
||||||
@@ -53,6 +54,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
ConnectionTagAbridged = []byte{0xef, 0xef, 0xef, 0xef}
|
ConnectionTagAbridged = []byte{0xef, 0xef, 0xef, 0xef}
|
||||||
ConnectionTagIntermediate = []byte{0xee, 0xee, 0xee, 0xee}
|
ConnectionTagIntermediate = []byte{0xee, 0xee, 0xee, 0xee}
|
||||||
|
ConnectionTagSecure = []byte{0xdd, 0xdd, 0xdd, 0xdd}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tag maps connection type to the corresponding handshake tag.
|
// Tag maps connection type to the corresponding handshake tag.
|
||||||
@@ -62,6 +64,8 @@ func (t ConnectionType) Tag() ([]byte, error) {
|
|||||||
return ConnectionTagAbridged, nil
|
return ConnectionTagAbridged, nil
|
||||||
case ConnectionTypeIntermediate:
|
case ConnectionTypeIntermediate:
|
||||||
return ConnectionTagIntermediate, nil
|
return ConnectionTagIntermediate, nil
|
||||||
|
case ConnectionTypeSecure:
|
||||||
|
return ConnectionTagSecure, nil
|
||||||
default:
|
default:
|
||||||
return nil, errors.Errorf("Unknown connection type %d", t)
|
return nil, errors.Errorf("Unknown connection type %d", t)
|
||||||
}
|
}
|
||||||
@@ -75,6 +79,9 @@ func ConnectionTagFromHandshake(magic []byte) (ConnectionType, error) {
|
|||||||
if bytes.Equal(magic, ConnectionTagAbridged) {
|
if bytes.Equal(magic, ConnectionTagAbridged) {
|
||||||
return ConnectionTypeAbridged, nil
|
return ConnectionTypeAbridged, nil
|
||||||
}
|
}
|
||||||
|
if bytes.Equal(magic, ConnectionTagSecure) {
|
||||||
|
return ConnectionTypeSecure, nil
|
||||||
|
}
|
||||||
|
|
||||||
return ConnectionTypeUnknown, errors.New("Unknown handshake protocol")
|
return ConnectionTypeUnknown, errors.New("Unknown handshake protocol")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user