|
|
@@ -3,6 +3,7 @@ package faketls
|
|
3
|
3
|
import (
|
|
4
|
4
|
"crypto/hmac"
|
|
5
|
5
|
"crypto/sha256"
|
|
|
6
|
+ "crypto/subtle"
|
|
6
|
7
|
"encoding/binary"
|
|
7
|
8
|
"fmt"
|
|
8
|
9
|
"time"
|
|
|
@@ -39,10 +40,7 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {
|
|
39
|
40
|
}
|
|
40
|
41
|
|
|
41
|
42
|
copy(hello.Random[:], handshake[ClientHelloRandomOffset:])
|
|
42
|
|
-
|
|
43
|
|
- for i := ClientHelloRandomOffset; i < ClientHelloRandomOffset+RandomLen; i++ {
|
|
44
|
|
- handshake[i] = 0
|
|
45
|
|
- }
|
|
|
43
|
+ copy(handshake[ClientHelloRandomOffset:], clientHelloEmptyRandom)
|
|
46
|
44
|
|
|
47
|
45
|
rec := record.AcquireRecord()
|
|
48
|
46
|
defer record.ReleaseRecord(rec)
|
|
|
@@ -62,10 +60,8 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {
|
|
62
|
60
|
computedRandom[i] ^= hello.Random[i]
|
|
63
|
61
|
}
|
|
64
|
62
|
|
|
65
|
|
- for i := 0; i < RandomLen-4; i++ {
|
|
66
|
|
- if computedRandom[i] != 0 {
|
|
67
|
|
- return hello, ErrBadDigest
|
|
68
|
|
- }
|
|
|
63
|
+ if subtle.ConstantTimeCompare(clientHelloEmptyRandom[:RandomLen-4], computedRandom[:RandomLen-4]) != 1 {
|
|
|
64
|
+ return hello, ErrBadDigest
|
|
69
|
65
|
}
|
|
70
|
66
|
|
|
71
|
67
|
timestamp := int64(binary.LittleEndian.Uint32(computedRandom[RandomLen-4:]))
|