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

+ 7
- 0
mtproto/connection_options.go View File

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

Loading…
Cancel
Save