Skip to content

Commit c1989bf

Browse files
committed
constant time string comparison for socks5 credential validation
1 parent 6b05fcc commit c1989bf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

routine.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wireproxy
22

33
import (
44
"context"
5+
"crypto/subtle"
56
"errors"
67
"fmt"
78
"io"
@@ -110,7 +111,9 @@ func (config *Socks5Config) SpawnRoutine(vt *VirtualTun) {
110111
}
111112

112113
func (c CredentialValidator) Valid(username, password string) bool {
113-
return c.username == username && c.password == password
114+
u := subtle.ConstantTimeCompare([]byte(c.username), []byte(username))
115+
p := subtle.ConstantTimeCompare([]byte(c.password), []byte(password))
116+
return u&p == 1
114117
}
115118

116119
func connForward(bufSize int, from io.ReadWriteCloser, to io.ReadWriteCloser) {

0 commit comments

Comments
 (0)