mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 11:34:01 +03:00
Add documentation for timeattack
This commit is contained in:
@@ -129,7 +129,15 @@ type EventStream interface {
|
|||||||
Send(context.Context, Event)
|
Send(context.Context, Event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TimeAttackDetector is an abstraction that checks a time, taken from
|
||||||
|
// the faketls client hello message. This timestamp is encoded into
|
||||||
|
// client-generated random bytes and can be extracted after some client
|
||||||
|
// hello verification.
|
||||||
|
//
|
||||||
|
// This is mostly to prevent replay attacks.
|
||||||
type TimeAttackDetector interface {
|
type TimeAttackDetector interface {
|
||||||
|
// Valid returns an error if timestamp is invalid or should not be
|
||||||
|
// accepted.
|
||||||
Valid(time.Time) error
|
Valid(time.Time) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ func (d detector) Valid(then time.Time) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDetector returns a new TimeAttackDetector which validates that
|
||||||
|
// timestamp belongs to intervar [X-duration, X+duration], so a small
|
||||||
|
// timeshift is acceptable.
|
||||||
func NewDetector(duration time.Duration) mtglib.TimeAttackDetector {
|
func NewDetector(duration time.Duration) mtglib.TimeAttackDetector {
|
||||||
return detector{
|
return detector{
|
||||||
Duration: duration,
|
Duration: duration,
|
||||||
|
|||||||
+6
-3
@@ -1,7 +1,10 @@
|
|||||||
|
// TimeAttack has implementation of mtglib.TimeAttackDetector>
|
||||||
package timeattack
|
package timeattack
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
const (
|
// DefaultDuration is a default duration when timestamps are acceptable.
|
||||||
DefaultDuration = 5 * time.Second
|
//
|
||||||
)
|
// It means that all timestamps which are X-DefaultDuration <= X <=
|
||||||
|
// X+DefaultDuration are fine.
|
||||||
|
const DefaultDuration = 5 * time.Second
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ type noop struct{}
|
|||||||
|
|
||||||
func (n noop) Valid(_ time.Time) error { return nil }
|
func (n noop) Valid(_ time.Time) error { return nil }
|
||||||
|
|
||||||
|
// NewNoop returns TimeAttackDetector which accepts all timestamps.
|
||||||
func NewNoop() mtglib.TimeAttackDetector {
|
func NewNoop() mtglib.TimeAttackDetector {
|
||||||
return noop{}
|
return noop{}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user