|
|
@@ -78,19 +78,32 @@ func (p *Proxy) ServeConn(conn essentials.Conn) {
|
|
78
|
78
|
ctx.logger.Info("Stream has been finished")
|
|
79
|
79
|
}()
|
|
80
|
80
|
|
|
81
|
|
- if !p.doFakeTLSHandshake(ctx) {
|
|
|
81
|
+ noise, ok := p.doFakeTLSHandshake(ctx)
|
|
|
82
|
+ if !ok {
|
|
82
|
83
|
return
|
|
83
|
84
|
}
|
|
84
|
85
|
|
|
85
|
|
- if err := p.doObfuscatedHandshake(ctx); err != nil {
|
|
86
|
|
- p.logger.InfoError("obfuscated handshake is failed", err)
|
|
|
86
|
+ clientConn, err := p.doppelGanger.NewConn(ctx.clientConn)
|
|
|
87
|
+ if err != nil {
|
|
|
88
|
+ ctx.logger.InfoError("cannot wrap into doppelganger connection", err)
|
|
|
89
|
+ return
|
|
|
90
|
+ }
|
|
|
91
|
+ defer clientConn.Stop()
|
|
87
|
92
|
|
|
|
93
|
+ if _, err := clientConn.Write(noise); err != nil {
|
|
|
94
|
+ ctx.logger.InfoError("cannot send the first packet", err)
|
|
88
|
95
|
return
|
|
89
|
96
|
}
|
|
90
|
97
|
|
|
91
|
|
- if err := p.doTelegramCall(ctx); err != nil {
|
|
92
|
|
- p.logger.WarningError("cannot dial to telegram", err)
|
|
|
98
|
+ ctx.clientConn = clientConn
|
|
93
|
99
|
|
|
|
100
|
+ if err := p.doObfuscatedHandshake(ctx); err != nil {
|
|
|
101
|
+ ctx.logger.InfoError("obfuscated handshake is failed", err)
|
|
|
102
|
+ return
|
|
|
103
|
+ }
|
|
|
104
|
+
|
|
|
105
|
+ if err := p.doTelegramCall(ctx); err != nil {
|
|
|
106
|
+ ctx.logger.WarningError("cannot dial to telegram", err)
|
|
94
|
107
|
return
|
|
95
|
108
|
}
|
|
96
|
109
|
|
|
|
@@ -163,7 +176,7 @@ func (p *Proxy) Shutdown() {
|
|
163
|
176
|
p.blocklist.Shutdown()
|
|
164
|
177
|
}
|
|
165
|
178
|
|
|
166
|
|
-func (p *Proxy) doFakeTLSHandshake(ctx *streamContext) bool {
|
|
|
179
|
+func (p *Proxy) doFakeTLSHandshake(ctx *streamContext) ([]byte, bool) {
|
|
167
|
180
|
rewind := newConnRewind(ctx.clientConn)
|
|
168
|
181
|
|
|
169
|
182
|
clientHello, err := fake.ReadClientHello(
|
|
|
@@ -175,31 +188,25 @@ func (p *Proxy) doFakeTLSHandshake(ctx *streamContext) bool {
|
|
175
|
188
|
if err != nil {
|
|
176
|
189
|
p.logger.InfoError("cannot read client hello", err)
|
|
177
|
190
|
p.doDomainFronting(ctx, rewind)
|
|
178
|
|
- return false
|
|
|
191
|
+ return nil, false
|
|
179
|
192
|
}
|
|
180
|
193
|
|
|
181
|
194
|
if p.antiReplayCache.SeenBefore(clientHello.SessionID) {
|
|
182
|
195
|
p.logger.Warning("replay attack has been detected!")
|
|
183
|
196
|
p.eventStream.Send(p.ctx, NewEventReplayAttack(ctx.streamID))
|
|
184
|
197
|
p.doDomainFronting(ctx, rewind)
|
|
185
|
|
- return false
|
|
|
198
|
+ return nil, false
|
|
186
|
199
|
}
|
|
187
|
200
|
|
|
188
|
|
- _, err = fake.SendServerHello(ctx.clientConn, p.secret.Key[:], clientHello)
|
|
|
201
|
+ noise, err := fake.SendServerHello(ctx.clientConn, p.secret.Key[:], clientHello)
|
|
189
|
202
|
if err != nil {
|
|
190
|
203
|
p.logger.InfoError("cannot send welcome packet", err)
|
|
191
|
|
- return false
|
|
|
204
|
+ return nil, false
|
|
192
|
205
|
}
|
|
193
|
206
|
|
|
194
|
207
|
ctx.clientConn = tls.New(ctx.clientConn, true, true)
|
|
195
|
208
|
|
|
196
|
|
- ctx.clientConn, err = p.doppelGanger.NewConn(ctx.clientConn)
|
|
197
|
|
- if err != nil {
|
|
198
|
|
- p.logger.WarningError("cannot create connection", err)
|
|
199
|
|
- return false
|
|
200
|
|
- }
|
|
201
|
|
-
|
|
202
|
|
- return true
|
|
|
209
|
+ return noise, true
|
|
203
|
210
|
}
|
|
204
|
211
|
|
|
205
|
212
|
func (p *Proxy) doObfuscatedHandshake(ctx *streamContext) error {
|