Browse Source

Improve: use crypto/rand

pull/225/head
xjasonlyu 2 years ago
parent
commit
4a8bf64cb1
  1. 4
      component/simple-obfs/http.go
  2. 11
      component/simple-obfs/obfs.go
  3. 6
      component/simple-obfs/tls.go

4
component/simple-obfs/http.go

@ -2,10 +2,10 @@ package obfs
import (
"bytes"
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"math/rand"
"net"
"net/http"
@ -65,7 +65,7 @@ func (ho *HTTPObfs) Write(b []byte) (int, error) {
randBytes := make([]byte, 16)
rand.Read(randBytes)
req, _ := http.NewRequest("GET", fmt.Sprintf("http://%s/", ho.host), bytes.NewBuffer(b[:]))
req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", rand.Int()%54, rand.Int()%2))
req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", randInt()%54, randInt()%2))
req.Header.Set("Upgrade", "websocket")
req.Header.Set("Connection", "Upgrade")
req.Host = ho.host

11
component/simple-obfs/obfs.go

@ -1,4 +1,15 @@
// Package obfs provides obfuscation functionality for Shadowsocks protocol.
package obfs
import (
"crypto/rand"
"math"
"math/big"
)
// Ref: github.com/Dreamacro/clash/component/simple-obfs
func randInt() int {
n, _ := rand.Int(rand.Reader, big.NewInt(math.MaxInt))
return int(n.Int64())
}

6
component/simple-obfs/tls.go

@ -2,19 +2,15 @@ package obfs
import (
"bytes"
"crypto/rand"
"encoding/binary"
"io"
"math/rand"
"net"
"time"
"github.com/xjasonlyu/tun2socks/v2/common/pool"
)
func init() {
rand.Seed(time.Now().Unix())
}
const (
chunkSize = 1 << 14 // 2 ** 14 == 16 * 1024
)

Loading…
Cancel
Save