Quellcode durchsuchen

Add documentation for timeattack

tags/v2.0.0-rc1
9seconds vor 5 Jahren
Ursprung
Commit
a3bae795c4
4 geänderte Dateien mit 18 neuen und 3 gelöschten Zeilen
  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 Datei anzeigen

@@ -129,7 +129,15 @@ type EventStream interface {
129 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 138
 type TimeAttackDetector interface {
139
+	// Valid returns an error if timestamp is invalid or should not be
140
+	// accepted.
133 141
 	Valid(time.Time) error
134 142
 }
135 143
 

+ 3
- 0
timeattack/detector.go Datei anzeigen

@@ -29,6 +29,9 @@ func (d detector) Valid(then time.Time) error {
29 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 35
 func NewDetector(duration time.Duration) mtglib.TimeAttackDetector {
33 36
 	return detector{
34 37
 		Duration: duration,

+ 6
- 3
timeattack/init.go Datei anzeigen

@@ -1,7 +1,10 @@
1
+// TimeAttack has implementation of mtglib.TimeAttackDetector>
1 2
 package timeattack
2 3
 
3 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 Datei anzeigen

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

Laden…
Abbrechen
Speichern