Add secure mode

This commit is contained in:
9seconds
2018-07-10 09:37:04 +03:00
parent 25d02cf120
commit 3d8ffdcc56
2 changed files with 11 additions and 0 deletions
+4
View File
@@ -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")
} }
+7
View File
@@ -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")
} }