diff --git a/handshake_server_tls13.go b/handshake_server_tls13.go index d1a4f2e..2cf4587 100644 --- a/handshake_server_tls13.go +++ b/handshake_server_tls13.go @@ -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 } diff --git a/tls.go b/tls.go index 1e7af81..4603082 100644 --- a/tls.go +++ b/tls.go @@ -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()