Kaynağa Gözat

Merge pull request #15 from 9seconds/secure

Support secure mode
tags/0.10
Sergey Arkhipov 7 yıl önce
ebeveyn
işleme
c71c90420e
No account linked to committer's email address
3 değiştirilmiş dosya ile 45 ekleme ve 1 silme
  1. 36
    1
      README.md
  2. 2
    0
      config/config.go
  3. 7
    0
      mtproto/connection_options.go

+ 36
- 1
README.md Dosyayı Görüntüle

@@ -91,20 +91,55 @@ or
91 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 117
 Now run the tool:
95 118
 
96 119
 ```console
97 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 129
 This tool will listen on port 3128 by default with the given secret.
101 130
 
102 131
 # One-line runner
103 132
 
104
-```
133
+```console
105 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 143
 You will have this tool up and running on port 3128. Now curl
109 144
 `localhost:3129` to get `tg://` links or do `docker logs mtg`. Also,
110 145
 port 3129 will show you some statistics if you are interested in.

+ 2
- 0
config/config.go Dosyayı Görüntüle

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

+ 7
- 0
mtproto/connection_options.go Dosyayı Görüntüle

@@ -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…
İptal
Kaydet