Fix compile errors

This commit is contained in:
yuhan6665
2023-11-12 12:08:30 -05:00
parent 870716f6af
commit d3f9ac0cd1
2 changed files with 9 additions and 17 deletions
+5 -12
View File
@@ -19,7 +19,6 @@ import (
"hash"
"io"
"math/big"
"sync/atomic"
"time"
)
@@ -75,17 +74,11 @@ func (hs *serverHandshakeStateTLS13) handshake() error {
hs.suite = cipherSuiteTLS13ByID(hs.hello.cipherSuite)
c.cipherSuite = hs.suite.id
hs.transcript = hs.suite.hash.New()
/*
// For Go 1.20 TLS
key, _ := generateECDHEKey(c.config.rand(), X25519)
copy(hs.hello.serverShare.data, key.PublicKey().Bytes())
peerKey, _ := key.Curve().NewPublicKey(hs.clientHello.keyShares[hs.clientHello.keyShares[0].group].data)
hs.sharedKey, _ = key.ECDH(peerKey)
*/
// For Go 1.19 TLS
params, _ := generateECDHEParameters(c.config.rand(), X25519)
copy(hs.hello.serverShare.data, params.PublicKey())
hs.sharedKey = params.SharedKey(hs.clientHello.keyShares[hs.clientHello.keyShares[0].group].data)
key, _ := generateECDHEKey(c.config.rand(), X25519)
copy(hs.hello.serverShare.data, key.PublicKey().Bytes())
peerKey, _ := key.Curve().NewPublicKey(hs.clientHello.keyShares[hs.clientHello.keyShares[0].group].data)
hs.sharedKey, _ = key.ECDH(peerKey)
c.serverName = hs.clientHello.serverName
}
+4 -5
View File
@@ -32,7 +32,6 @@ import (
"runtime"
"strings"
"sync"
"sync/atomic"
"time"
"github.com/pires/go-proxyproto"
@@ -302,7 +301,7 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
if handshakeLen-len(s2cSaved) > 0 {
io.ReadFull(target, buf[:handshakeLen-len(s2cSaved)])
}
if n, err := target.Read(buf); !hs.c.handshakeComplete() {
if n, err := target.Read(buf); !hs.c.isHandshakeComplete.Load() {
if err != nil {
conn.Close()
}
@@ -318,7 +317,7 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
if err != nil {
break
}
atomic.StoreUint32(&hs.c.handshakeStatus, 1)
hs.c.isHandshakeComplete.Store(true)
break
}
mutex.Unlock()
@@ -339,9 +338,9 @@ func Server(ctx context.Context, conn net.Conn, config *Config) (*Conn, error) {
waitGroup.Wait()
target.Close()
if config.Show {
fmt.Printf("REALITY remoteAddr: %v\ths.c.handshakeStatus: %v\n", remoteAddr, atomic.LoadUint32(&hs.c.handshakeStatus))
fmt.Printf("REALITY remoteAddr: %v\ths.c.handshakeStatus: %v\n", remoteAddr, hs.c.isHandshakeComplete.Load())
}
if atomic.LoadUint32(&hs.c.handshakeStatus) == 1 {
if hs.c.isHandshakeComplete.Load() {
return hs.c, nil
}
conn.Close()