mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-29 13:35:20 -05:00
fix lint issues in tls mirror
This commit is contained in:
committed by
Xiaokang Wang (Shelikhoo)
parent
19025d330e
commit
800e6f03c9
2
.github/linters/.golangci.yml
vendored
2
.github/linters/.golangci.yml
vendored
@@ -50,7 +50,7 @@ linters:
|
|||||||
- builtin$
|
- builtin$
|
||||||
- examples$
|
- examples$
|
||||||
issues:
|
issues:
|
||||||
new: true
|
new: false
|
||||||
formatters:
|
formatters:
|
||||||
enable:
|
enable:
|
||||||
- gofmt
|
- gofmt
|
||||||
|
|||||||
@@ -294,7 +294,7 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.Ciphersuites != nil && len(c.Ciphersuites) > 0 {
|
if len(c.Ciphersuites) > 0 {
|
||||||
config.CipherSuites = make([]uint16, 0, len(c.Ciphersuites))
|
config.CipherSuites = make([]uint16, 0, len(c.Ciphersuites))
|
||||||
for _, cs := range c.Ciphersuites {
|
for _, cs := range c.Ciphersuites {
|
||||||
config.CipherSuites = append(config.CipherSuites, uint16(cs))
|
config.CipherSuites = append(config.CipherSuites, uint16(cs))
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
// NewMirroredTLSConn creates a new mirrored TLS connection.
|
// NewMirroredTLSConn creates a new mirrored TLS connection.
|
||||||
// No stable interface
|
// No stable interface
|
||||||
func NewMirroredTLSConn(ctx context.Context, clientConn net.Conn, serverConn net.Conn, onC2SMessage, onS2CMessage tlsmirror.MessageHook, closable common.Closable, explicitNonceDetection tlsmirror.ExplicitNonceDetection) tlsmirror.InsertableTLSConn {
|
func NewMirroredTLSConn(ctx context.Context, clientConn net.Conn, serverConn net.Conn, onC2SMessage, onS2CMessage tlsmirror.MessageHook, closable common.Closable, explicitNonceDetection tlsmirror.ExplicitNonceDetection) tlsmirror.InsertableTLSConn {
|
||||||
|
|
||||||
explicitNonceDetectionReady, explicitNonceDetectionOver := context.WithCancel(ctx)
|
explicitNonceDetectionReady, explicitNonceDetectionOver := context.WithCancel(ctx)
|
||||||
c := &conn{
|
c := &conn{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
@@ -462,7 +461,7 @@ func (c *conn) GetApplicationDataExplicitNonceReservedOverheadHeaderLength() (in
|
|||||||
if c.tls12ExplicitNonce == nil {
|
if c.tls12ExplicitNonce == nil {
|
||||||
return 0, newError("explicit nonce info is not ready")
|
return 0, newError("explicit nonce info is not ready")
|
||||||
}
|
}
|
||||||
if *c.tls12ExplicitNonce == true {
|
if *c.tls12ExplicitNonce {
|
||||||
return 8, nil
|
return 8, nil
|
||||||
}
|
}
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package mirrorbase
|
package mirrorbase
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-cmp/cmp"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/go-cmp/cmp"
|
||||||
|
|
||||||
"github.com/v2fly/v2ray-core/v5/common/crypto"
|
"github.com/v2fly/v2ray-core/v5/common/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ func (s *clientConnState) WriteMessage(message []byte) error {
|
|||||||
return newError("failed to get explicit nonce reserved overhead header length").Base(err)
|
return newError("failed to get explicit nonce reserved overhead header length").Base(err)
|
||||||
}
|
}
|
||||||
buffer := make([]byte, explicitNonceReservedOverheadHeaderLength, explicitNonceReservedOverheadHeaderLength+len(message)+s.encryptor.NonceSize())
|
buffer := make([]byte, explicitNonceReservedOverheadHeaderLength, explicitNonceReservedOverheadHeaderLength+len(message)+s.encryptor.NonceSize())
|
||||||
buffer, err = s.encryptor.Seal(buffer[:], message)
|
buffer, err = s.encryptor.Seal(buffer, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newError("failed to encrypt message").Base(err)
|
return newError("failed to encrypt message").Base(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,7 @@ func (s *connState) WriteMessage(message []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer := make([]byte, explicitNonceReservedOverheadHeaderLength, explicitNonceReservedOverheadHeaderLength+len(message)+s.decryptor.NonceSize())
|
buffer := make([]byte, explicitNonceReservedOverheadHeaderLength, explicitNonceReservedOverheadHeaderLength+len(message)+s.decryptor.NonceSize())
|
||||||
buffer, err = s.encryptor.Seal(buffer[:], message)
|
buffer, err = s.encryptor.Seal(buffer, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newError("failed to encrypt message").Base(err)
|
return newError("failed to encrypt message").Base(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import "encoding/binary"
|
|||||||
// @param data_OWNERSHIP_RELINQUISHED - The payload, this reference is consumed and should not be used after this call.
|
// @param data_OWNERSHIP_RELINQUISHED - The payload, this reference is consumed and should not be used after this call.
|
||||||
// @param padding - The number of padding bytes to add to the data.
|
// @param padding - The number of padding bytes to add to the data.
|
||||||
func Pack(data_OWNERSHIP_RELINQUISHED []byte, paddingLength int) []byte {
|
func Pack(data_OWNERSHIP_RELINQUISHED []byte, paddingLength int) []byte {
|
||||||
data := append(data_OWNERSHIP_RELINQUISHED, make([]byte, paddingLength)...)
|
data := append(data_OWNERSHIP_RELINQUISHED, make([]byte, paddingLength)...) //nolint:gocritic
|
||||||
dataLength := len(data_OWNERSHIP_RELINQUISHED)
|
dataLength := len(data_OWNERSHIP_RELINQUISHED)
|
||||||
data = binary.BigEndian.AppendUint32(data, uint32(dataLength))
|
data = binary.BigEndian.AppendUint32(data, uint32(dataLength))
|
||||||
return data
|
return data
|
||||||
@@ -47,9 +47,8 @@ func Pad(paddingLength int) []byte {
|
|||||||
case 4:
|
case 4:
|
||||||
return []byte{0, 0, 0, 0}
|
return []byte{0, 0, 0, 0}
|
||||||
default:
|
default:
|
||||||
return append(make([]byte, paddingLength))
|
return append(make([]byte, paddingLength)) //nolint:gocritic, govet, staticcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unpack extracts the data and padding from the given padded data. It
|
// Unpack extracts the data and padding from the given padded data. It
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ func (generator *TrafficGenerator) GenerateNextTraffic(ctx context.Context) erro
|
|||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
resp, err := httpRoundTripper.RoundTrip(httpReq)
|
resp, err := httpRoundTripper.RoundTrip(httpReq) //nolint:bodyclose
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return newError("failed to send HTTP request").Base(err).AtWarning()
|
return newError("failed to send HTTP request").Base(err).AtWarning()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ func (c *unclaimedConnection) tick() {
|
|||||||
defer c.access.Unlock()
|
defer c.access.Unlock()
|
||||||
if !c.claimed {
|
if !c.claimed {
|
||||||
c.claimed = true
|
c.claimed = true
|
||||||
c.Conn.Close()
|
c.Conn.Close() //nolint: staticcheck
|
||||||
c.Conn = nil
|
c.Conn = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user