Skip to content

Commit 907ebd6

Browse files
fregieLoyalsoldier
andauthored
Fix: TLS ECC certificate failed to handshake (#352)
Co-authored-by: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
1 parent 6cafb1c commit 907ebd6

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.16
44

55
require (
66
github.com/go-sql-driver/mysql v1.6.0
7-
github.com/huandu/go-clone v1.2.2
87
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
98
github.com/refraction-networking/utls v0.0.0-20201210053706-2179f286686b
109
github.com/shadowsocks/go-shadowsocks2 v0.1.5

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
158158
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
159159
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
160160
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
161-
github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c=
162-
github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U=
163-
github.com/huandu/go-clone v1.2.2 h1:u6acA9meOiaf9arN8iOR17WcRLE9vab2PmCh6xdHTuw=
164-
github.com/huandu/go-clone v1.2.2/go.mod h1:bPJ9bAG8fjyAEBRFt6toaGUZcGFGL3f6g5u6yW+9W14=
165161
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
166162
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
167163
github.com/jhump/protoreflect v1.8.2 h1:k2xE7wcUomeqwY0LDCYA16y4WWfyTcMx5mKhk0d4ua0=
@@ -308,7 +304,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
308304
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
309305
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
310306
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
311-
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
312307
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
313308
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
314309
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=

tunnel/tls/server.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
"sync/atomic"
1818
"time"
1919

20-
"github.com/huandu/go-clone"
21-
2220
"github.com/p4gefau1t/trojan-go/common"
2321
"github.com/p4gefau1t/trojan-go/config"
2422
"github.com/p4gefau1t/trojan-go/log"
@@ -50,7 +48,6 @@ type Server struct {
5048
cancel context.CancelFunc
5149
underlay tunnel.Server
5250
nextHTTP int32
53-
setNextHTTPOnce sync.Once
5451
portOverrider map[string]int
5552
}
5653

@@ -107,8 +104,7 @@ func (s *Server) acceptLoop() {
107104
if s.verifySNI && !matched {
108105
return nil, common.NewError("sni mismatched: " + hello.ServerName + ", expected: " + s.sni)
109106
}
110-
keyPairCopied := clone.Clone(&s.keyPair[0]).(*tls.Certificate)
111-
return keyPairCopied, nil
107+
return &s.keyPair[0], nil
112108
},
113109
}
114110

@@ -209,6 +205,8 @@ func (s *Server) AcceptPacket(tunnel.Tunnel) (tunnel.PacketConn, error) {
209205

210206
func (s *Server) checkKeyPairLoop(checkRate time.Duration, keyPath string, certPath string, password string) {
211207
var lastKeyBytes, lastCertBytes []byte
208+
ticker := time.NewTicker(checkRate)
209+
212210
for {
213211
log.Debug("checking cert...")
214212
keyBytes, err := ioutil.ReadFile(keyPath)
@@ -234,11 +232,13 @@ func (s *Server) checkKeyPairLoop(checkRate time.Duration, keyPath string, certP
234232
lastKeyBytes = keyBytes
235233
lastCertBytes = certBytes
236234
}
235+
237236
select {
238-
case <-time.After(checkRate):
237+
case <-ticker.C:
239238
continue
240239
case <-s.ctx.Done():
241240
log.Debug("exiting")
241+
ticker.Stop()
242242
return
243243
}
244244
}

0 commit comments

Comments
 (0)