mirror of
https://gitee.com/konyshe/goodlink.git
synced 2025-09-26 20:51:22 +08:00
完善架构
This commit is contained in:
@@ -47,11 +47,11 @@ func PKCS7UnPadding(origData []byte) []byte {
|
|||||||
func EncodeTest() {
|
func EncodeTest() {
|
||||||
orig := "hello world"
|
orig := "hello world"
|
||||||
key := "123456781234567812345678"
|
key := "123456781234567812345678"
|
||||||
fmt.Println("ԭ<EFBFBD>ģ<EFBFBD>", orig)
|
fmt.Println("原文:", orig)
|
||||||
|
|
||||||
encryptCode := Encrypt(orig, key)
|
encryptCode := Encrypt(orig, key)
|
||||||
fmt.Println("<EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>", encryptCode)
|
fmt.Println("密文:", encryptCode)
|
||||||
|
|
||||||
decryptCode := Decrypt(encryptCode, key)
|
decryptCode := Decrypt(encryptCode, key)
|
||||||
fmt.Println("<EFBFBD><EFBFBD><EFBFBD>ܽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", decryptCode)
|
fmt.Println("解密结果:", decryptCode)
|
||||||
}
|
}
|
||||||
|
12
tls2/client.go
Normal file
12
tls2/client.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package tls2
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetClientTLSConfig() *tls.Config {
|
||||||
|
return &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
NextProtos: []string{"goodlink"},
|
||||||
|
}
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package tunnel
|
package tls2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
@@ -9,15 +9,8 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getClientTLSConfig() *tls.Config {
|
|
||||||
return &tls.Config{
|
|
||||||
InsecureSkipVerify: true,
|
|
||||||
NextProtos: []string{"quic-echo-example"},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup a bare-bones TLS config for the server
|
// Setup a bare-bones TLS config for the server
|
||||||
func getServerTLSConfig() *tls.Config {
|
func GetServerTLSConfig() *tls.Config {
|
||||||
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@@ -36,6 +29,6 @@ func getServerTLSConfig() *tls.Config {
|
|||||||
}
|
}
|
||||||
return &tls.Config{
|
return &tls.Config{
|
||||||
Certificates: []tls.Certificate{tlsCert},
|
Certificates: []tls.Certificate{tlsCert},
|
||||||
NextProtos: []string{"quic-echo-example"},
|
NextProtos: []string{"goodlink"},
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -8,6 +8,7 @@ import (
|
|||||||
"gogo/workpool"
|
"gogo/workpool"
|
||||||
"goodlink/proxy"
|
"goodlink/proxy"
|
||||||
"goodlink/tools"
|
"goodlink/tools"
|
||||||
|
"goodlink/tls2"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -43,7 +44,7 @@ func (c *TunnelClient) process_client3(conn *net.UDPConn, remoteAddr *net.UDPAdd
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
log.Printf("process_client3 quic.Dial: %v==>%v\n", conn.LocalAddr(), remoteAddr)
|
log.Printf("process_client3 quic.Dial: %v==>%v\n", conn.LocalAddr(), remoteAddr)
|
||||||
new_quic_conn, err := quic.Dial(context.Background(), conn, remoteAddr, getClientTLSConfig(), nil)
|
new_quic_conn, err := quic.Dial(context.Background(), conn, remoteAddr, tls2.GetClientTLSConfig(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("process_client3 quic.Dial: %v\n", err)
|
log.Printf("process_client3 quic.Dial: %v\n", err)
|
||||||
return
|
return
|
||||||
|
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"goodlink/proxy"
|
"goodlink/proxy"
|
||||||
|
"goodlink/tls2"
|
||||||
"goodlink/tools"
|
"goodlink/tools"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
@@ -86,7 +87,7 @@ func (c *TunnelServer) process_server5(conn *net.UDPConn, tun_remote_addr *net.U
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("quic.Listen: %v\n", conn.LocalAddr())
|
log.Printf("quic.Listen: %v\n", conn.LocalAddr())
|
||||||
listener, err := quic.Listen(conn, getServerTLSConfig(), nil)
|
listener, err := quic.Listen(conn, tls2.GetServerTLSConfig(), nil)
|
||||||
tools.AssertErrorToNilf("process_client3 quic.Listen: %v", err)
|
tools.AssertErrorToNilf("process_client3 quic.Listen: %v", err)
|
||||||
|
|
||||||
log.Printf("process_server5 listener.Accept: %v\n", conn.LocalAddr())
|
log.Printf("process_server5 listener.Accept: %v\n", conn.LocalAddr())
|
||||||
|
Reference in New Issue
Block a user