Browse Source

Add documentation for timeattack

tags/v2.0.0-rc1
9seconds 5 years ago
parent
commit
a3bae795c4
4 changed files with 18 additions and 3 deletions
  1. 8
    0
      mtglib/init.go
  2. 3
    0
      timeattack/detector.go
  3. 6
    3
      timeattack/init.go
  4. 1
    0
      timeattack/noop.go

+ 8
- 0
mtglib/init.go View File

129
 	Send(context.Context, Event)
129
 	Send(context.Context, Event)
130
 }
130
 }
131
 
131
 
132
+// TimeAttackDetector is an abstraction that checks a time, taken from
133
+// the faketls client hello message. This timestamp is encoded into
134
+// client-generated random bytes and can be extracted after some client
135
+// hello verification.
136
+//
137
+// This is mostly to prevent replay attacks.
132
 type TimeAttackDetector interface {
138
 type TimeAttackDetector interface {
139
+	// Valid returns an error if timestamp is invalid or should not be
140
+	// accepted.
133
 	Valid(time.Time) error
141
 	Valid(time.Time) error
134
 }
142
 }
135
 
143
 

+ 3
- 0
timeattack/detector.go View File

29
 	return nil
29
 	return nil
30
 }
30
 }
31
 
31
 
32
+// NewDetector returns a new TimeAttackDetector which validates that
33
+// timestamp belongs to intervar [X-duration, X+duration], so a small
34
+// timeshift is acceptable.
32
 func NewDetector(duration time.Duration) mtglib.TimeAttackDetector {
35
 func NewDetector(duration time.Duration) mtglib.TimeAttackDetector {
33
 	return detector{
36
 	return detector{
34
 		Duration: duration,
37
 		Duration: duration,

+ 6
- 3
timeattack/init.go View File

1
+// TimeAttack has implementation of mtglib.TimeAttackDetector>
1
 package timeattack
2
 package timeattack
2
 
3
 
3
 import "time"
4
 import "time"
4
 
5
 
5
-const (
6
-	DefaultDuration = 5 * time.Second
7
-)
6
+// DefaultDuration is a default duration when timestamps are acceptable.
7
+//
8
+// It means that all timestamps which are X-DefaultDuration <= X <=
9
+// X+DefaultDuration are fine.
10
+const DefaultDuration = 5 * time.Second

+ 1
- 0
timeattack/noop.go View File

10
 
10
 
11
 func (n noop) Valid(_ time.Time) error { return nil }
11
 func (n noop) Valid(_ time.Time) error { return nil }
12
 
12
 
13
+// NewNoop returns TimeAttackDetector which accepts all timestamps.
13
 func NewNoop() mtglib.TimeAttackDetector {
14
 func NewNoop() mtglib.TimeAttackDetector {
14
 	return noop{}
15
 	return noop{}
15
 }
16
 }

Loading…
Cancel
Save