mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 14:04:02 +03:00
Update golangci-lint
This commit is contained in:
@@ -56,7 +56,7 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {
|
||||
if len(handshake)-4 != int(handshakeLength) {
|
||||
return hello,
|
||||
fmt.Errorf("incorrect handshake size. manifested=%d, real=%d",
|
||||
handshakeLength, len(handshake)-4) // nolint: gomnd
|
||||
handshakeLength, len(handshake)-4) //nolint: gomnd
|
||||
}
|
||||
|
||||
copy(hello.Random[:], handshake[ClientHelloRandomOffset:])
|
||||
@@ -72,7 +72,7 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {
|
||||
// mac is calculated for the whole record, not only
|
||||
// for the payload part
|
||||
mac := hmac.New(sha256.New, secret)
|
||||
rec.Dump(mac) // nolint: errcheck
|
||||
rec.Dump(mac) //nolint: errcheck
|
||||
|
||||
computedRandom := mac.Sum(nil)
|
||||
|
||||
@@ -100,7 +100,7 @@ func parseSessionID(hello *ClientHello, handshake []byte) {
|
||||
}
|
||||
|
||||
func parseCipherSuite(hello *ClientHello, handshake []byte) {
|
||||
cipherSuiteOffset := ClientHelloSessionIDOffset + len(hello.SessionID) + 3 // nolint: gomnd
|
||||
cipherSuiteOffset := ClientHelloSessionIDOffset + len(hello.SessionID) + 3 //nolint: gomnd
|
||||
hello.CipherSuite = binary.BigEndian.Uint16(handshake[cipherSuiteOffset : cipherSuiteOffset+2])
|
||||
}
|
||||
|
||||
|
||||
@@ -25,14 +25,14 @@ func (c *Conn) Read(p []byte) (int, error) {
|
||||
|
||||
for {
|
||||
if err := rec.Read(c.Conn); err != nil {
|
||||
return 0, err // nolint: wrapcheck
|
||||
return 0, err //nolint: wrapcheck
|
||||
}
|
||||
|
||||
switch rec.Type { // nolint: exhaustive
|
||||
switch rec.Type { //nolint: exhaustive
|
||||
case record.TypeApplicationData:
|
||||
rec.Payload.WriteTo(&c.readBuffer) // nolint: errcheck
|
||||
rec.Payload.WriteTo(&c.readBuffer) //nolint: errcheck
|
||||
|
||||
return c.readBuffer.Read(p) // nolint: wrapcheck
|
||||
return c.readBuffer.Read(p) //nolint: wrapcheck
|
||||
case record.TypeChangeCipherSpec:
|
||||
default:
|
||||
return 0, fmt.Errorf("unsupported record type %v", rec.Type)
|
||||
@@ -60,13 +60,13 @@ func (c *Conn) Write(p []byte) (int, error) {
|
||||
|
||||
rec.Payload.Reset()
|
||||
rec.Payload.Write(p[:chunkSize])
|
||||
rec.Dump(sendBuffer) // nolint: errcheck
|
||||
rec.Dump(sendBuffer) //nolint: errcheck
|
||||
|
||||
p = p[chunkSize:]
|
||||
}
|
||||
|
||||
if _, err := c.Conn.Write(sendBuffer.Bytes()); err != nil {
|
||||
return 0, err // nolint: wrapcheck
|
||||
return 0, err //nolint: wrapcheck
|
||||
}
|
||||
|
||||
return lenP, nil
|
||||
|
||||
@@ -24,13 +24,13 @@ type ConnMock struct {
|
||||
func (m *ConnMock) Read(p []byte) (int, error) {
|
||||
m.Called(p)
|
||||
|
||||
return m.readBuffer.Read(p) // nolint: wrapcheck
|
||||
return m.readBuffer.Read(p) //nolint: wrapcheck
|
||||
}
|
||||
|
||||
func (m *ConnMock) Write(p []byte) (int, error) {
|
||||
m.Called(p)
|
||||
|
||||
return m.writeBuffer.Write(p) // nolint: wrapcheck
|
||||
return m.writeBuffer.Write(p) //nolint: wrapcheck
|
||||
}
|
||||
|
||||
type ConnTestSuite struct {
|
||||
@@ -61,14 +61,14 @@ func (suite *ConnTestSuite) TestRead() {
|
||||
rec.Version = record.Version12
|
||||
|
||||
rec.Payload.WriteByte(0x01)
|
||||
rec.Dump(&suite.connMock.readBuffer) // nolint: errcheck
|
||||
rec.Dump(&suite.connMock.readBuffer) //nolint: errcheck
|
||||
rec.Reset()
|
||||
|
||||
rec.Type = record.TypeApplicationData
|
||||
rec.Version = record.Version12
|
||||
|
||||
rec.Payload.Write([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
||||
rec.Dump(&suite.connMock.readBuffer) // nolint: errcheck
|
||||
rec.Dump(&suite.connMock.readBuffer) //nolint: errcheck
|
||||
|
||||
resultBuffer := &bytes.Buffer{}
|
||||
buf := make([]byte, 2)
|
||||
@@ -95,14 +95,14 @@ func (suite *ConnTestSuite) TestReadUnexpected() {
|
||||
rec.Version = record.Version12
|
||||
|
||||
rec.Payload.WriteByte(0x01)
|
||||
rec.Dump(&suite.connMock.readBuffer) // nolint: errcheck
|
||||
rec.Dump(&suite.connMock.readBuffer) //nolint: errcheck
|
||||
rec.Reset()
|
||||
|
||||
rec.Type = record.TypeHandshake
|
||||
rec.Version = record.Version12
|
||||
|
||||
rec.Payload.Write([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
||||
rec.Dump(&suite.connMock.readBuffer) // nolint: errcheck
|
||||
rec.Dump(&suite.connMock.readBuffer) //nolint: errcheck
|
||||
|
||||
buf := make([]byte, 2)
|
||||
|
||||
@@ -141,7 +141,7 @@ func (suite *ConnTestSuite) TestWrite() {
|
||||
|
||||
suite.Equal(record.TypeApplicationData, rec.Type)
|
||||
suite.Equal(record.Version12, rec.Version)
|
||||
rec.Payload.WriteTo(buf) // nolint: errcheck
|
||||
rec.Payload.WriteTo(buf) //nolint: errcheck
|
||||
}
|
||||
|
||||
suite.Equal(dataToRec, buf.Bytes())
|
||||
|
||||
@@ -12,7 +12,7 @@ var bytesBufferPool = sync.Pool{
|
||||
}
|
||||
|
||||
func acquireBytesBuffer() *bytes.Buffer {
|
||||
return bytesBufferPool.Get().(*bytes.Buffer) // nolint: forcetypeassert
|
||||
return bytesBufferPool.Get().(*bytes.Buffer) //nolint: forcetypeassert
|
||||
}
|
||||
|
||||
func releaseBytesBuffer(b *bytes.Buffer) {
|
||||
|
||||
@@ -11,7 +11,7 @@ var recordPool = sync.Pool{
|
||||
}
|
||||
|
||||
func AcquireRecord() *Record {
|
||||
return recordPool.Get().(*Record) // nolint: forcetypeassert
|
||||
return recordPool.Get().(*Record) //nolint: forcetypeassert
|
||||
}
|
||||
|
||||
func ReleaseRecord(r *Record) {
|
||||
|
||||
@@ -23,24 +23,24 @@ func SendWelcomePacket(writer io.Writer, secret []byte, clientHello ClientHello)
|
||||
rec.Version = record.Version12
|
||||
|
||||
generateServerHello(&rec.Payload, clientHello)
|
||||
rec.Dump(buf) // nolint: errcheck
|
||||
rec.Dump(buf) //nolint: errcheck
|
||||
rec.Reset()
|
||||
|
||||
rec.Type = record.TypeChangeCipherSpec
|
||||
rec.Version = record.Version12
|
||||
rec.Payload.WriteByte(ChangeCipherValue)
|
||||
|
||||
rec.Dump(buf) // nolint: errcheck
|
||||
rec.Dump(buf) //nolint: errcheck
|
||||
rec.Reset()
|
||||
|
||||
rec.Type = record.TypeApplicationData
|
||||
rec.Version = record.Version12
|
||||
|
||||
if _, err := io.CopyN(&rec.Payload, rand.Reader, int64(1024+mrand.Intn(3092))); err != nil { // nolint: gomnd
|
||||
if _, err := io.CopyN(&rec.Payload, rand.Reader, int64(1024+mrand.Intn(3092))); err != nil { //nolint: gomnd
|
||||
panic(err)
|
||||
}
|
||||
|
||||
rec.Dump(buf) // nolint: errcheck
|
||||
rec.Dump(buf) //nolint: errcheck
|
||||
|
||||
packet := buf.Bytes()
|
||||
mac := hmac.New(sha256.New, secret)
|
||||
@@ -51,7 +51,7 @@ func SendWelcomePacket(writer io.Writer, secret []byte, clientHello ClientHello)
|
||||
copy(packet[WelcomePacketRandomOffset:], mac.Sum(nil))
|
||||
|
||||
if _, err := writer.Write(packet); err != nil {
|
||||
return err // nolint: wrapcheck
|
||||
return err //nolint: wrapcheck
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -87,6 +87,6 @@ func generateServerHello(writer io.Writer, clientHello ClientHello) {
|
||||
binary.BigEndian.PutUint32(header[:], uint32(bodyBuf.Len()))
|
||||
header[0] = HandshakeTypeServer
|
||||
|
||||
writer.Write(header[:]) // nolint: errcheck
|
||||
bodyBuf.WriteTo(writer) // nolint: errcheck
|
||||
writer.Write(header[:]) //nolint: errcheck
|
||||
bodyBuf.WriteTo(writer) //nolint: errcheck
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func (suite *ClientHandshakeTestSuite) SetupSuite() {
|
||||
|
||||
func (suite *ClientHandshakeTestSuite) TestCannotRead() {
|
||||
buf := bytes.NewBuffer([]byte{1, 2, 3})
|
||||
_, _, _, err := obfuscated2.ClientHandshake([]byte{1, 2, 3}, buf) // nolint: dogsled
|
||||
_, _, _, err := obfuscated2.ClientHandshake([]byte{1, 2, 3}, buf) //nolint: dogsled
|
||||
|
||||
suite.Error(err)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ type Conn struct {
|
||||
func (c Conn) Read(p []byte) (int, error) {
|
||||
n, err := c.Conn.Read(p)
|
||||
if err != nil {
|
||||
return n, err // nolint: wrapcheck
|
||||
return n, err //nolint: wrapcheck
|
||||
}
|
||||
|
||||
c.Decryptor.XORKeyStream(p, p[:n])
|
||||
@@ -33,5 +33,5 @@ func (c Conn) Write(p []byte) (int, error) {
|
||||
payload := buf.Bytes()
|
||||
c.Encryptor.XORKeyStream(payload, payload)
|
||||
|
||||
return c.Conn.Write(payload) // nolint: wrapcheck
|
||||
return c.Conn.Write(payload) //nolint: wrapcheck
|
||||
}
|
||||
|
||||
@@ -23,20 +23,20 @@ var handshakeConnectionType = []byte{0xdd, 0xdd, 0xdd, 0xdd}
|
||||
|
||||
// A structure of obfuscated2 handshake frame is following:
|
||||
//
|
||||
// [frameOffsetFirst:frameOffsetKey:frameOffsetIV:frameOffsetMagic:frameOffsetDC:frameOffsetEnd].
|
||||
// [frameOffsetFirst:frameOffsetKey:frameOffsetIV:frameOffsetMagic:frameOffsetDC:frameOffsetEnd].
|
||||
//
|
||||
// - 8 bytes of noise
|
||||
// - 32 bytes of AES Key
|
||||
// - 16 bytes of AES IV
|
||||
// - 4 bytes of 'connection type' - this has some setting like a connection type
|
||||
// - 2 bytes of 'DC'. DC is little endian int16
|
||||
// - 2 bytes of noise
|
||||
// - 8 bytes of noise
|
||||
// - 32 bytes of AES Key
|
||||
// - 16 bytes of AES IV
|
||||
// - 4 bytes of 'connection type' - this has some setting like a connection type
|
||||
// - 2 bytes of 'DC'. DC is little endian int16
|
||||
// - 2 bytes of noise
|
||||
type handshakeFrame struct {
|
||||
data [handshakeFrameLen]byte
|
||||
}
|
||||
|
||||
func (h *handshakeFrame) dc() int {
|
||||
idx := int16(h.data[handshakeFrameOffsetDC]) | int16(h.data[handshakeFrameOffsetDC+1])<<8 // nolint: gomnd, lll // little endian for int16 is here
|
||||
idx := int16(h.data[handshakeFrameOffsetDC]) | int16(h.data[handshakeFrameOffsetDC+1])<<8 //nolint: gomnd, lll // little endian for int16 is here
|
||||
|
||||
switch {
|
||||
case idx > 0:
|
||||
|
||||
@@ -57,7 +57,7 @@ func (suite *HandshakeFrameTestSuite) TestDC() {
|
||||
suite.T().Run(strconv.Itoa(int(incoming)), func(t *testing.T) {
|
||||
frame := handshakeFrame{}
|
||||
|
||||
rand.Read(frame.data[:]) // nolint: errcheck
|
||||
rand.Read(frame.data[:]) //nolint: errcheck
|
||||
|
||||
frame.data[handshakeFrameOffsetDC] = byte(incoming)
|
||||
frame.data[handshakeFrameOffsetDC+1] = byte(incoming >> 8)
|
||||
|
||||
@@ -21,7 +21,7 @@ var (
|
||||
)
|
||||
|
||||
func acquireSha256Hasher() hash.Hash {
|
||||
return sha256HasherPool.Get().(hash.Hash) // nolint: forcetypeassert
|
||||
return sha256HasherPool.Get().(hash.Hash) //nolint: forcetypeassert
|
||||
}
|
||||
|
||||
func releaseSha256Hasher(h hash.Hash) {
|
||||
@@ -30,7 +30,7 @@ func releaseSha256Hasher(h hash.Hash) {
|
||||
}
|
||||
|
||||
func acquireBytesBuffer() *bytes.Buffer {
|
||||
return bytesBufferPool.Get().(*bytes.Buffer) // nolint: forcetypeassert
|
||||
return bytesBufferPool.Get().(*bytes.Buffer) //nolint: forcetypeassert
|
||||
}
|
||||
|
||||
func releaseBytesBuffer(buf *bytes.Buffer) {
|
||||
|
||||
@@ -47,12 +47,12 @@ func generateServerHanshakeFrame() serverHandshakeFrame {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if frame.data[0] == 0xef { // nolint: gomnd // taken from tg sources
|
||||
if frame.data[0] == 0xef { //nolint: gomnd // taken from tg sources
|
||||
continue
|
||||
}
|
||||
|
||||
switch binary.LittleEndian.Uint32(frame.data[:4]) {
|
||||
case 0x44414548, 0x54534f50, 0x20544547, 0x4954504f, 0xeeeeeeee: // nolint: gomnd // taken from tg sources
|
||||
case 0x44414548, 0x54534f50, 0x20544547, 0x4954504f, 0xeeeeeeee: //nolint: gomnd // taken from tg sources
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ func FuzzServerSend(f *testing.F) {
|
||||
Once().
|
||||
Run(func(args mock.Arguments) {
|
||||
message := make([]byte, len(data))
|
||||
handshakeData.decryptor.XORKeyStream(message, args.Get(0).([]byte)) // nolint: forcetypeassert
|
||||
handshakeData.decryptor.XORKeyStream(message, args.Get(0).([]byte)) //nolint: forcetypeassert
|
||||
assert.Equal(t, message, data)
|
||||
})
|
||||
|
||||
@@ -45,7 +45,7 @@ func FuzzServerReceive(f *testing.F) {
|
||||
Run(func(args mock.Arguments) {
|
||||
message := make([]byte, len(data))
|
||||
handshakeData.encryptor.XORKeyStream(message, data)
|
||||
copy(args.Get(0).([]byte), message) // nolint: forcetypeassert
|
||||
copy(args.Get(0).([]byte), message) //nolint: forcetypeassert
|
||||
})
|
||||
|
||||
n, err := handshakeData.proxyConn.Read(buffer)
|
||||
|
||||
@@ -30,7 +30,7 @@ func (suite *ServerHandshakeTestSuite) TestSendToTelegram() {
|
||||
Once().
|
||||
Run(func(args mock.Arguments) {
|
||||
message := make([]byte, len(messageToTelegram))
|
||||
suite.data.decryptor.XORKeyStream(message, args.Get(0).([]byte)) // nolint: forcetypeassert
|
||||
suite.data.decryptor.XORKeyStream(message, args.Get(0).([]byte)) //nolint: forcetypeassert
|
||||
suite.Equal(messageToTelegram, message)
|
||||
})
|
||||
|
||||
@@ -50,7 +50,7 @@ func (suite *ServerHandshakeTestSuite) TestRecieveFromTelegram() {
|
||||
Run(func(args mock.Arguments) {
|
||||
message := make([]byte, len(messageFromTelegram))
|
||||
suite.data.encryptor.XORKeyStream(message, messageFromTelegram)
|
||||
copy(args.Get(0).([]byte), message) // nolint: forcetypeassert
|
||||
copy(args.Get(0).([]byte), message) //nolint: forcetypeassert
|
||||
})
|
||||
|
||||
n, err := suite.data.proxyConn.Read(buffer)
|
||||
|
||||
@@ -11,7 +11,7 @@ var copyBufferPool = sync.Pool{
|
||||
}
|
||||
|
||||
func acquireCopyBuffer() *[]byte {
|
||||
return copyBufferPool.Get().(*[]byte) // nolint: forcetypeassert
|
||||
return copyBufferPool.Get().(*[]byte) //nolint: forcetypeassert
|
||||
}
|
||||
|
||||
func releaseCopyBuffer(buf *[]byte) {
|
||||
|
||||
@@ -35,8 +35,8 @@ func Relay(ctx context.Context, log Logger, telegramConn, clientConn essentials.
|
||||
}
|
||||
|
||||
func pump(log Logger, src, dst essentials.Conn, direction string) {
|
||||
defer src.CloseRead() // nolint: errcheck
|
||||
defer dst.CloseWrite() // nolint: errcheck
|
||||
defer src.CloseRead() //nolint: errcheck
|
||||
defer dst.CloseWrite() //nolint: errcheck
|
||||
|
||||
copyBuffer := acquireCopyBuffer()
|
||||
defer releaseCopyBuffer(copyBuffer)
|
||||
|
||||
Reference in New Issue
Block a user