Browse Source

Add secure mode

tags/0.10
9seconds 7 years ago
parent
commit
3d8ffdcc56
2 changed files with 11 additions and 0 deletions
  1. 4
    0
      config/config.go
  2. 7
    0
      mtproto/connection_options.go

+ 4
- 0
config/config.go View File

@@ -5,6 +5,7 @@ import (
5 5
 	"fmt"
6 6
 	"net"
7 7
 	"strconv"
8
+	"strings"
8 9
 
9 10
 	"github.com/juju/errors"
10 11
 )
@@ -90,6 +91,9 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo
90 91
 	publicIPv6 net.IP, publicIPv6Port uint16,
91 92
 	statsIP net.IP, statsPort uint16,
92 93
 	secret, adtag string) (*Config, error) {
94
+	if strings.HasPrefix(secret, "dd") {
95
+		secret = secret[2:]
96
+	}
93 97
 	if len(secret) != 32 {
94 98
 		return nil, errors.New("Telegram demands secret of length 32")
95 99
 	}

+ 7
- 0
mtproto/connection_options.go View File

@@ -39,6 +39,7 @@ const (
39 39
 	ConnectionTypeUnknown ConnectionType = iota
40 40
 	ConnectionTypeAbridged
41 41
 	ConnectionTypeIntermediate
42
+	ConnectionTypeSecure
42 43
 )
43 44
 
44 45
 // ConnectionProtocol* define which connection protocols to use.
@@ -53,6 +54,7 @@ const (
53 54
 var (
54 55
 	ConnectionTagAbridged     = []byte{0xef, 0xef, 0xef, 0xef}
55 56
 	ConnectionTagIntermediate = []byte{0xee, 0xee, 0xee, 0xee}
57
+	ConnectionTagSecure       = []byte{0xdd, 0xdd, 0xdd, 0xdd}
56 58
 )
57 59
 
58 60
 // Tag maps connection type to the corresponding handshake tag.
@@ -62,6 +64,8 @@ func (t ConnectionType) Tag() ([]byte, error) {
62 64
 		return ConnectionTagAbridged, nil
63 65
 	case ConnectionTypeIntermediate:
64 66
 		return ConnectionTagIntermediate, nil
67
+	case ConnectionTypeSecure:
68
+		return ConnectionTagSecure, nil
65 69
 	default:
66 70
 		return nil, errors.Errorf("Unknown connection type %d", t)
67 71
 	}
@@ -75,6 +79,9 @@ func ConnectionTagFromHandshake(magic []byte) (ConnectionType, error) {
75 79
 	if bytes.Equal(magic, ConnectionTagAbridged) {
76 80
 		return ConnectionTypeAbridged, nil
77 81
 	}
82
+	if bytes.Equal(magic, ConnectionTagSecure) {
83
+		return ConnectionTypeSecure, nil
84
+	}
78 85
 
79 86
 	return ConnectionTypeUnknown, errors.New("Unknown handshake protocol")
80 87
 }

Loading…
Cancel
Save