mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Propagate network to proxy object
This commit is contained in:
@@ -17,6 +17,9 @@ var (
|
|||||||
ErrIPBlocklistIsNotDefined = errors.New("ip blocklist is not defined")
|
ErrIPBlocklistIsNotDefined = errors.New("ip blocklist is not defined")
|
||||||
ErrEventStreamIsNotDefined = errors.New("event stream is not defined")
|
ErrEventStreamIsNotDefined = errors.New("event stream is not defined")
|
||||||
ErrLoggerIsNotDefined = errors.New("logger is not defined")
|
ErrLoggerIsNotDefined = errors.New("logger is not defined")
|
||||||
|
|
||||||
|
errCannotSendWelcomePacket = errors.New("cannot send welcome packet")
|
||||||
|
errReplayAttackDetected = errors.New("replay attack detected")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
+6
-4
@@ -27,6 +27,7 @@ type Proxy struct {
|
|||||||
telegram *telegram.Telegram
|
telegram *telegram.Telegram
|
||||||
|
|
||||||
secret Secret
|
secret Secret
|
||||||
|
network Network
|
||||||
antiReplayCache AntiReplayCache
|
antiReplayCache AntiReplayCache
|
||||||
timeAttackDetector TimeAttackDetector
|
timeAttackDetector TimeAttackDetector
|
||||||
ipBlocklist IPBlocklist
|
ipBlocklist IPBlocklist
|
||||||
@@ -139,13 +140,13 @@ func (p *Proxy) doFakeTLSHandshake(ctx *streamContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if p.antiReplayCache.SeenBefore(hello.SessionID) {
|
if p.antiReplayCache.SeenBefore(hello.SessionID) {
|
||||||
p.logger.Warning("anti replay attack was detected")
|
return errReplayAttackDetected
|
||||||
|
|
||||||
return fmt.Errorf("anti replay attack from %s", ctx.ClientIP().String())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := faketls.SendWelcomePacket(ctx.clientConn, p.secret.Key[:], hello); err != nil {
|
if err := faketls.SendWelcomePacket(ctx.clientConn, p.secret.Key[:], hello); err != nil {
|
||||||
return fmt.Errorf("cannot send a welcome packet: %w", err)
|
p.logger.InfoError("cannot send welcome packet", err)
|
||||||
|
|
||||||
|
return errCannotSendWelcomePacket
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.clientConn = &faketls.Conn{
|
ctx.clientConn = &faketls.Conn{
|
||||||
@@ -249,6 +250,7 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) { // nolint: cyclop, funlen
|
|||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
ctxCancel: cancel,
|
ctxCancel: cancel,
|
||||||
secret: opts.Secret,
|
secret: opts.Secret,
|
||||||
|
network: opts.Network,
|
||||||
antiReplayCache: opts.AntiReplayCache,
|
antiReplayCache: opts.AntiReplayCache,
|
||||||
timeAttackDetector: opts.TimeAttackDetector,
|
timeAttackDetector: opts.TimeAttackDetector,
|
||||||
ipBlocklist: opts.IPBlocklist,
|
ipBlocklist: opts.IPBlocklist,
|
||||||
|
|||||||
Reference in New Issue
Block a user