完善架构

This commit is contained in:
2312708932@qq.com
2024-12-14 11:12:28 +08:00
parent 40054eb12e
commit dbba58be58
5 changed files with 22 additions and 15 deletions

View File

@@ -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
View File

@@ -0,0 +1,12 @@
package tls2
import (
"crypto/tls"
)
func GetClientTLSConfig() *tls.Config {
return &tls.Config{
InsecureSkipVerify: true,
NextProtos: []string{"goodlink"},
}
}

View File

@@ -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"},
} }
} }

View File

@@ -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

View File

@@ -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())