mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 18:04:03 +03:00
Add EventReplayAttack
This commit is contained in:
@@ -99,3 +99,16 @@ func (e EventIPBlocklisted) StreamID() string {
|
||||
func (e EventIPBlocklisted) Timestamp() time.Time {
|
||||
return e.CreatedAt
|
||||
}
|
||||
|
||||
type EventReplayAttack struct {
|
||||
CreatedAt time.Time
|
||||
ConnID string
|
||||
}
|
||||
|
||||
func (e EventReplayAttack) StreamID() string {
|
||||
return e.ConnID
|
||||
}
|
||||
|
||||
func (e EventReplayAttack) Timestamp() time.Time {
|
||||
return e.CreatedAt
|
||||
}
|
||||
|
||||
@@ -87,6 +87,16 @@ func (suite *EventsTestSuite) TestEventIPBlocklisted() {
|
||||
suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
|
||||
}
|
||||
|
||||
func (suite *EventsTestSuite) TestEventReplayAttack() {
|
||||
evt := mtglib.EventReplayAttack{
|
||||
CreatedAt: time.Now(),
|
||||
ConnID: "CONNID",
|
||||
}
|
||||
|
||||
suite.Equal("CONNID", evt.StreamID())
|
||||
suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
|
||||
}
|
||||
|
||||
func TestEvents(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &EventsTestSuite{})
|
||||
|
||||
@@ -166,6 +166,10 @@ func (p *Proxy) doFakeTLSHandshake(ctx *streamContext) bool {
|
||||
|
||||
if p.antiReplayCache.SeenBefore(hello.SessionID) {
|
||||
p.logger.Warning("replay attack has been detected!")
|
||||
p.eventStream.Send(p.ctx, EventReplayAttack{
|
||||
CreatedAt: time.Now(),
|
||||
ConnID: ctx.connID,
|
||||
})
|
||||
p.doDomainFronting(ctx, rewind)
|
||||
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user