Преглед изворни кода

Merge pull request #15 from 9seconds/secure

Support secure mode
tags/0.10
Sergey Arkhipov пре 7 година
родитељ
комит
c71c90420e
No account linked to committer's email address
3 измењених фајлова са 45 додато и 1 уклоњено
  1. 36
    1
      README.md
  2. 2
    0
      config/config.go
  3. 7
    0
      mtproto/connection_options.go

+ 36
- 1
README.md Прегледај датотеку

91
 $ head -c 512 /dev/urandom | md5sum | cut -f 1 -d ' '
91
 $ head -c 512 /dev/urandom | md5sum | cut -f 1 -d ' '
92
 ```
92
 ```
93
 
93
 
94
+## Secure mode
95
+
96
+If you want to support new secure mode, please prepend `dd` to the
97
+secret. For example, secret `cf18fa8ea0267057e2c61a5f7322a8e7` should
98
+be `ddcf18fa8ea0267057e2c61a5f7322a8e7`. But pay attention that some
99
+old clients won't support this mode. If this is not your case, I would
100
+suggest to go with this mode.
101
+
102
+Oneliners to generate such secrets:
103
+
104
+```console
105
+$ echo dd$(openssl rand -hex 16)
106
+```
107
+
108
+or
109
+
110
+```console
111
+$ echo dd$(head -c 512 /dev/urandom | md5sum | cut -f 1 -d ' ')
112
+```
113
+
114
+
115
+# How to run the tool
116
+
94
 Now run the tool:
117
 Now run the tool:
95
 
118
 
96
 ```console
119
 ```console
97
 $ mtg <secret>
120
 $ mtg <secret>
98
 ```
121
 ```
99
 
122
 
123
+How to run the tool with ADTag:
124
+
125
+```console
126
+$ mtg <secret> <adtag>
127
+```
128
+
100
 This tool will listen on port 3128 by default with the given secret.
129
 This tool will listen on port 3128 by default with the given secret.
101
 
130
 
102
 # One-line runner
131
 # One-line runner
103
 
132
 
104
-```
133
+```console
105
 $ docker run --name mtg --restart=unless-stopped -p 3128:3128 -p 3129:3129 -d nineseconds/mtg $(openssl rand -hex 16)
134
 $ docker run --name mtg --restart=unless-stopped -p 3128:3128 -p 3129:3129 -d nineseconds/mtg $(openssl rand -hex 16)
106
 ```
135
 ```
107
 
136
 
137
+or in secret mode:
138
+
139
+```console
140
+$ docker run --name mtg --restart=unless-stopped -p 3128:3128 -p 3129:3129 -d nineseconds/mtg dd$(openssl rand -hex 16)
141
+```
142
+
108
 You will have this tool up and running on port 3128. Now curl
143
 You will have this tool up and running on port 3128. Now curl
109
 `localhost:3129` to get `tg://` links or do `docker logs mtg`. Also,
144
 `localhost:3129` to get `tg://` links or do `docker logs mtg`. Also,
110
 port 3129 will show you some statistics if you are interested in.
145
 port 3129 will show you some statistics if you are interested in.

+ 2
- 0
config/config.go Прегледај датотеку

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
+	secret = strings.TrimPrefix(secret, "dd")
93
 	if len(secret) != 32 {
95
 	if len(secret) != 32 {
94
 		return nil, errors.New("Telegram demands secret of length 32")
96
 		return nil, errors.New("Telegram demands secret of length 32")
95
 	}
97
 	}

+ 7
- 0
mtproto/connection_options.go Прегледај датотеку

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…
Откажи
Сачувај