116 lines
2.2 KiB
Go
116 lines
2.2 KiB
Go
package shadow
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/md5"
|
|
"crypto/tls"
|
|
"fmt"
|
|
utls "github.com/refraction-networking/utls"
|
|
"io/ioutil"
|
|
"net"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestHandshake(t *testing.T) {
|
|
dial, err := tls.DialWithDialer(&net.Dialer{
|
|
Timeout: time.Second * 5,
|
|
}, "tcp", "evan.run:443", &tls.Config{
|
|
ServerName: "evan.run",
|
|
})
|
|
|
|
err = dial.Handshake()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
time.Sleep(time.Minute)
|
|
}
|
|
|
|
func TestMd5(t *testing.T) {
|
|
key := "Passwd"
|
|
passwd := []byte(key)
|
|
|
|
buf := make([]byte, 32)
|
|
srcCode := md5.Sum(RandomByte(16))
|
|
copy(buf[0:], srcCode[0:])
|
|
buffer := bytes.NewBuffer(srcCode[:])
|
|
|
|
sum := md5.Sum(passwd)
|
|
buffer.Write(sum[:])
|
|
|
|
hash := md5.Sum(buffer.Bytes())
|
|
copy(buf[16:], hash[0:])
|
|
fmt.Println(buf)
|
|
|
|
vBuf := make([]byte, 32)
|
|
copy(vBuf, buf[0:16])
|
|
verifyBuf := bytes.NewBuffer(vBuf)
|
|
verifyBuf.Write(sum[:])
|
|
|
|
verifyHash := md5.Sum(buffer.Bytes())
|
|
if bytes.Equal(verifyHash[:], buf[16:32]) {
|
|
fmt.Println("GOOD")
|
|
}
|
|
if VerifyKey(buf, key) {
|
|
fmt.Println("VerifyKey GOOD")
|
|
}
|
|
|
|
}
|
|
|
|
func TestAes(t *testing.T) {
|
|
key := []byte("1234567812345678")
|
|
data := []byte("AVC")
|
|
|
|
e := AesEncryptCBC(data, key)
|
|
d := AesDecryptCBC(e, key)
|
|
|
|
fmt.Println(string(d))
|
|
}
|
|
|
|
func TestTLSFingerprint(t *testing.T) {
|
|
|
|
transport := http.Transport{
|
|
DialTLS: func(network, adr string) (net.Conn, error) {
|
|
dial, err := net.Dial(network, adr)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return wrapTLSClient(dial, time.Second*5)
|
|
},
|
|
}
|
|
client := http.Client{
|
|
Transport: &transport,
|
|
CheckRedirect: nil,
|
|
Jar: nil,
|
|
Timeout: 0,
|
|
}
|
|
get, err := client.Get("https://client.tlsfingerprint.io:8443/")
|
|
if err != nil {
|
|
return
|
|
}
|
|
all, err := ioutil.ReadAll(get.Body)
|
|
if err != nil {
|
|
return
|
|
}
|
|
fmt.Println(string(all))
|
|
|
|
}
|
|
|
|
func wrapTLSClient(conn net.Conn, timeout time.Duration) (net.Conn, error) {
|
|
var err error
|
|
|
|
conn.SetDeadline(time.Now().Add(timeout))
|
|
defer conn.SetDeadline(time.Time{})
|
|
|
|
tlsConn := utls.UClient(conn, &utls.Config{ServerName: "client.tlsfingerprint.io"}, utls.HelloChrome_102)
|
|
|
|
if err = tlsConn.Handshake(); err != nil {
|
|
fmt.Println(err.Error())
|
|
tlsConn.Close()
|
|
return nil, err
|
|
}
|
|
|
|
return tlsConn, err
|
|
}
|