Fix lint issues

This commit is contained in:
9seconds
2021-03-25 17:40:38 +03:00
parent c3e8e8b1fe
commit 6d92d5fe21
5 changed files with 24 additions and 17 deletions
+2 -2
View File
@@ -44,7 +44,7 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {
// mac is calculated for the whole record, not only // mac is calculated for the whole record, not only
// for the payload part // for the payload part
mac := hmac.New(sha256.New, secret) mac := hmac.New(sha256.New, secret)
rec.Dump(mac) rec.Dump(mac) // nolint: errcheck
computedRandom := mac.Sum(nil) computedRandom := mac.Sum(nil)
@@ -64,7 +64,7 @@ func ParseClientHello(secret, handshake []byte) (ClientHello, error) {
hello.SessionID = make([]byte, handshake[ClientHelloSessionIDOffset]) hello.SessionID = make([]byte, handshake[ClientHelloSessionIDOffset])
copy(hello.SessionID, handshake[ClientHelloSessionIDOffset+1:]) copy(hello.SessionID, handshake[ClientHelloSessionIDOffset+1:])
cipherSuiteOffset := ClientHelloSessionIDOffset + 1 + len(hello.SessionID) + 2 cipherSuiteOffset := ClientHelloSessionIDOffset + len(hello.SessionID) + 3 // nolint: gomnd
hello.CipherSuite = binary.BigEndian.Uint16(handshake[cipherSuiteOffset : cipherSuiteOffset+2]) hello.CipherSuite = binary.BigEndian.Uint16(handshake[cipherSuiteOffset : cipherSuiteOffset+2])
return hello, nil return hello, nil
+2
View File
@@ -13,6 +13,8 @@ const (
HandshakeTypeClient = 0x01 HandshakeTypeClient = 0x01
HandshakeTypeServer = 0x02 HandshakeTypeServer = 0x02
ChangeCipherValue = 0x01
) )
var ( var (
+3 -3
View File
@@ -12,10 +12,10 @@ var bytesBufferPool = sync.Pool{
} }
func acquireBytesBuffer() *bytes.Buffer { func acquireBytesBuffer() *bytes.Buffer {
return bytesBufferPool.Get().(*bytes.Buffer) return bytesBufferPool.Get().(*bytes.Buffer)
} }
func releaseBytesBuffer(b *bytes.Buffer) { func releaseBytesBuffer(b *bytes.Buffer) {
b.Reset() b.Reset()
bytesBufferPool.Put(b) bytesBufferPool.Put(b)
} }
+14 -10
View File
@@ -23,30 +23,30 @@ func SendWelcomePacket(writer io.Writer, secret []byte, clientHello ClientHello)
rec.Version = record.Version12 rec.Version = record.Version12
generateServerHello(&rec.Payload, clientHello) generateServerHello(&rec.Payload, clientHello)
rec.Dump(buf) rec.Dump(buf) // nolint: errcheck
rec.Reset() rec.Reset()
rec.Type = record.TypeChangeCipherSpec rec.Type = record.TypeChangeCipherSpec
rec.Version = record.Version12 rec.Version = record.Version12
rec.Payload.WriteByte(0x01) rec.Payload.WriteByte(ChangeCipherValue)
rec.Dump(buf) rec.Dump(buf) // nolint: errcheck
rec.Reset() rec.Reset()
rec.Type = record.TypeApplicationData rec.Type = record.TypeApplicationData
rec.Version = record.Version12 rec.Version = record.Version12
if _, err := io.CopyN(&rec.Payload, rand.Reader, int64(1024+mrand.Intn(3092))); err != nil { if _, err := io.CopyN(&rec.Payload, rand.Reader, int64(1024+mrand.Intn(3092))); err != nil { // nolint: gomnd
panic(err) panic(err)
} }
rec.Dump(buf) rec.Dump(buf) // nolint: errcheck
packet := buf.Bytes() packet := buf.Bytes()
mac := hmac.New(sha256.New, secret) mac := hmac.New(sha256.New, secret)
mac.Write(clientHello.Random[:]) mac.Write(clientHello.Random[:]) // nolint: errcheck
mac.Write(packet) mac.Write(packet) // nolint: errcheck
copy(packet[WelcomePacketRandomOffset:], mac.Sum(nil)) copy(packet[WelcomePacketRandomOffset:], mac.Sum(nil))
@@ -75,7 +75,11 @@ func generateServerHello(writer io.Writer, clientHello ClientHello) {
bodyBuf.Write(serverHelloSuffix) bodyBuf.Write(serverHelloSuffix)
scalar := [32]byte{} scalar := [32]byte{}
rand.Read(scalar[:])
if _, err := rand.Read(scalar[:]); err != nil {
panic(err)
}
curve, _ := curve25519.X25519(scalar[:], curve25519.Basepoint) curve, _ := curve25519.X25519(scalar[:], curve25519.Basepoint)
bodyBuf.Write(curve) bodyBuf.Write(curve)
@@ -83,6 +87,6 @@ func generateServerHello(writer io.Writer, clientHello ClientHello) {
binary.BigEndian.PutUint32(header[:], uint32(bodyBuf.Len())) binary.BigEndian.PutUint32(header[:], uint32(bodyBuf.Len()))
header[0] = HandshakeTypeServer header[0] = HandshakeTypeServer
writer.Write(header[:]) writer.Write(header[:]) // nolint: errcheck
bodyBuf.WriteTo(writer) bodyBuf.WriteTo(writer) // nolint: errcheck
} }
+3 -2
View File
@@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"io"
"net" "net"
"sync" "sync"
"time" "time"
@@ -121,7 +122,7 @@ func (p *Proxy) Shutdown() {
p.workerPool.Release() p.workerPool.Release()
} }
func (p *Proxy) doFakeTLSHandshake(ctx *streamContext, conn net.Conn) error { func (p *Proxy) doFakeTLSHandshake(ctx *streamContext, conn io.ReadWriter) error {
rec := record.AcquireRecord() rec := record.AcquireRecord()
defer record.ReleaseRecord(rec) defer record.ReleaseRecord(rec)
@@ -202,7 +203,7 @@ func (p *Proxy) doTelegramCall(ctx *streamContext) error {
return nil return nil
} }
func NewProxy(opts ProxyOpts) (*Proxy, error) { // nolint: cyclop func NewProxy(opts ProxyOpts) (*Proxy, error) { // nolint: cyclop, funlen
switch { switch {
case opts.Network == nil: case opts.Network == nil:
return nil, ErrNetworkIsNotDefined return nil, ErrNetworkIsNotDefined