update README.md

This commit is contained in:
wenyifan
2022-09-08 00:12:01 +08:00
parent a983817b8d
commit c2ab6cbe5f
4 changed files with 29 additions and 25 deletions

View File

@ -51,14 +51,15 @@ func handler(conn net.Conn, targetAddress string, fakeAddress string) {
}
waitCh := make(chan int, 1)
go processHandshake(conn, fakeConn, waitCh)
go processHandshake(fakeConn, conn, waitCh)
go processHandshake(conn, fakeConn, waitCh, "client")
go processHandshake(fakeConn, conn, waitCh, "server")
<-waitCh
//Clean up previous buffered data
conn.SetDeadline(time.Now())
conn.SetDeadline(time.Time{})
fakeConn.Close()
realConnection, err := net.Dial("tcp", targetAddress)
if err != nil {
@ -132,26 +133,22 @@ func handler(conn net.Conn, targetAddress string, fakeAddress string) {
//}()
}
func processHandshake(src net.Conn, dst net.Conn, waitCh chan int) {
func processHandshake(src net.Conn, dst net.Conn, waitCh chan int, srcType string) {
buf := make([]byte, 32*1024)
for {
nr, er := src.Read(buf)
if nr > 0 {
header := ParseAndVerifyTLSHeader(buf[0:nr])
nw, ew := dst.Write(buf[0:nr])
if header != nil && header.Type == ChangeCipherSpec {
//fmt.Println(header.toString())
fmt.Println("[Server] handshake complete")
if header.ChangeCipherSpecNext == AppData {
dst.Close()
waitCh <- 1
} else {
src.Close()
waitCh <- 1
return
if srcType == "client" {
header := ParseAndVerifyTLSHeader(buf[0:nr])
if header != nil {
if header.Type == ChangeCipherSpec {
fmt.Println("[Server] handshake complete")
waitCh <- 1
break
}
//fmt.Println(header.toString())
}
break
}
if nw < 0 || nr < nw {
nw = 0
@ -175,5 +172,4 @@ func processHandshake(src net.Conn, dst net.Conn, waitCh chan int) {
break
}
}
waitCh <- 1
}