Add client and service

This commit is contained in:
世界 2023-02-20 12:52:48 +08:00
parent 320d58c57a
commit 6c9bdfc858
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
16 changed files with 1173 additions and 0 deletions

44
tls_wrapper.go Normal file
View file

@ -0,0 +1,44 @@
package shadowtls
import (
"context"
"crypto/tls"
"net"
"github.com/sagernet/sing/common"
)
type (
TLSSessionIDGeneratorFunc func(clientHello []byte, sessionID []byte) error
TLSHandshakeFunc func(
ctx context.Context,
conn net.Conn,
sessionIDGenerator TLSSessionIDGeneratorFunc, // for shadow-tls version 3
) error
)
func DefaultTLSHandshakeFunc(password string, config *tls.Config) TLSHandshakeFunc {
return func(ctx context.Context, conn net.Conn, sessionIDGenerator TLSSessionIDGeneratorFunc) error {
tlsConfig := &sTLSConfig{
Rand: config.Rand,
Time: config.Time,
VerifyPeerCertificate: config.VerifyPeerCertificate,
RootCAs: config.RootCAs,
NextProtos: config.NextProtos,
ServerName: config.ServerName,
InsecureSkipVerify: config.InsecureSkipVerify,
CipherSuites: config.CipherSuites,
MinVersion: config.MinVersion,
MaxVersion: config.MaxVersion,
CurvePreferences: common.Map(config.CurvePreferences, func(it tls.CurveID) sTLSCurveID {
return sTLSCurveID(it)
}),
SessionTicketsDisabled: config.SessionTicketsDisabled,
Renegotiation: sTLSRenegotiationSupport(config.Renegotiation),
SessionIDGenerator: generateSessionID(password),
}
tlsConn := sTLSClient(conn, tlsConfig)
return tlsConn.HandshakeContext(ctx)
}
}