commit 5b4397bff8f83dced4c415f5232442ae59f5072d Author: Yawning Angel yawning@schwanenlied.me Date: Sat Jan 19 11:42:24 2019 +0000
Clean up static analysis warnings
Mostly but not entirely discarding error return values of things that can not possibly fail despite the API returning errors. --- common/drbg/hash_drbg.go | 2 +- common/ntor/ntor.go | 10 ++++---- common/socks5/rfc1929.go | 4 ++-- common/socks5/socks5.go | 22 +++++++++--------- common/socks5/socks_test.go | 10 +++++--- obfs4proxy/obfs4proxy.go | 32 +++++++++++++------------- obfs4proxy/pt_extras.go | 6 ++--- transports/meeklite/meek.go | 4 ++-- transports/obfs2/obfs2.go | 6 ++--- transports/obfs3/obfs3.go | 8 +++---- transports/obfs4/framing/framing_test.go | 2 +- transports/obfs4/handshake_ntor.go | 24 +++++++++---------- transports/scramblesuit/conn.go | 12 +++++----- transports/scramblesuit/handshake_ticket.go | 10 ++++---- transports/scramblesuit/handshake_uniformdh.go | 14 +++++------ transports/scramblesuit/hkdf_expand.go | 6 ++--- transports/transports.go | 16 +++++++++---- 17 files changed, 99 insertions(+), 89 deletions(-)
diff --git a/common/drbg/hash_drbg.go b/common/drbg/hash_drbg.go index ea283ca..3d1a469 100644 --- a/common/drbg/hash_drbg.go +++ b/common/drbg/hash_drbg.go @@ -139,7 +139,7 @@ func (drbg *HashDrbg) Seed(seed int64) {
// NextBlock returns the next 8 byte DRBG block. func (drbg *HashDrbg) NextBlock() []byte { - drbg.sip.Write(drbg.ofb[:]) + _, _ = drbg.sip.Write(drbg.ofb[:]) copy(drbg.ofb[:], drbg.sip.Sum(nil))
ret := make([]byte, Size) diff --git a/common/ntor/ntor.go b/common/ntor/ntor.go index d5218db..48508bf 100644 --- a/common/ntor/ntor.go +++ b/common/ntor/ntor.go @@ -385,21 +385,21 @@ func ntorCommon(secretInput bytes.Buffer, id *NodeID, b *PublicKey, x *PublicKey
// KEY_SEED = H(secret_input, t_key) h := hmac.New(sha256.New, tKey) - h.Write(secretInput.Bytes()) + _, _ = h.Write(secretInput.Bytes()) tmp := h.Sum(nil) copy(keySeed[:], tmp)
// verify = H(secret_input, t_verify) h = hmac.New(sha256.New, tVerify) - h.Write(secretInput.Bytes()) + _, _ = h.Write(secretInput.Bytes()) verify := h.Sum(nil)
// auth_input = verify | ID | B | Y | X | PROTOID | "Server" authInput := bytes.NewBuffer(verify) - authInput.Write(suffix.Bytes()) - authInput.Write([]byte("Server")) + _, _ = authInput.Write(suffix.Bytes()) + _, _ = authInput.Write([]byte("Server")) h = hmac.New(sha256.New, tMac) - h.Write(authInput.Bytes()) + _, _ = h.Write(authInput.Bytes()) tmp = h.Sum(nil) copy(auth[:], tmp)
diff --git a/common/socks5/rfc1929.go b/common/socks5/rfc1929.go index f8176f1..d7849df 100644 --- a/common/socks5/rfc1929.go +++ b/common/socks5/rfc1929.go @@ -39,8 +39,8 @@ func (req *Request) authRFC1929() (err error) { sendErrResp := func() { // Swallow write/flush errors, the auth failure is the relevant error. resp := []byte{authRFC1929Ver, authRFC1929Fail} - req.rw.Write(resp[:]) - req.flushBuffers() + _, _ = req.rw.Write(resp[:]) + _ = req.flushBuffers() }
// The client sends a Username/Password request. diff --git a/common/socks5/socks5.go b/common/socks5/socks5.go index 876f934..a6f785d 100644 --- a/common/socks5/socks5.go +++ b/common/socks5/socks5.go @@ -257,15 +257,15 @@ func (req *Request) readCommand() error {
var err error if err = req.readByteVerify("version", version); err != nil { - req.Reply(ReplyGeneralFailure) + _ = req.Reply(ReplyGeneralFailure) return err } if err = req.readByteVerify("command", cmdConnect); err != nil { - req.Reply(ReplyCommandNotSupported) + _ = req.Reply(ReplyCommandNotSupported) return err } if err = req.readByteVerify("reserved", rsv); err != nil { - req.Reply(ReplyGeneralFailure) + _ = req.Reply(ReplyGeneralFailure) return err }
@@ -273,49 +273,49 @@ func (req *Request) readCommand() error { var atyp byte var host string if atyp, err = req.readByte(); err != nil { - req.Reply(ReplyGeneralFailure) + _ = req.Reply(ReplyGeneralFailure) return err } switch atyp { case atypIPv4: var addr []byte if addr, err = req.readBytes(net.IPv4len); err != nil { - req.Reply(ReplyGeneralFailure) + _ = req.Reply(ReplyGeneralFailure) return err } host = net.IPv4(addr[0], addr[1], addr[2], addr[3]).String() case atypDomainName: var alen byte if alen, err = req.readByte(); err != nil { - req.Reply(ReplyGeneralFailure) + _ = req.Reply(ReplyGeneralFailure) return err } if alen == 0 { - req.Reply(ReplyGeneralFailure) + _ = req.Reply(ReplyGeneralFailure) return fmt.Errorf("domain name with 0 length") } var addr []byte if addr, err = req.readBytes(int(alen)); err != nil { - req.Reply(ReplyGeneralFailure) + _ = req.Reply(ReplyGeneralFailure) return err } host = string(addr) case atypIPv6: var rawAddr []byte if rawAddr, err = req.readBytes(net.IPv6len); err != nil { - req.Reply(ReplyGeneralFailure) + _ = req.Reply(ReplyGeneralFailure) return err } addr := make(net.IP, net.IPv6len) copy(addr[:], rawAddr[:]) host = fmt.Sprintf("[%s]", addr.String()) default: - req.Reply(ReplyAddressNotSupported) + _ = req.Reply(ReplyAddressNotSupported) return fmt.Errorf("unsupported address type 0x%02x", atyp) } var rawPort []byte if rawPort, err = req.readBytes(2); err != nil { - req.Reply(ReplyGeneralFailure) + _ = req.Reply(ReplyGeneralFailure) return err } port := int(rawPort[0])<<8 | int(rawPort[1]) diff --git a/common/socks5/socks_test.go b/common/socks5/socks_test.go index 720476f..3e331fb 100644 --- a/common/socks5/socks_test.go +++ b/common/socks5/socks_test.go @@ -56,12 +56,16 @@ func (c *testReadWriter) Write(buf []byte) (n int, err error) { return c.writeBuf.Write(buf) }
-func (c *testReadWriter) writeHex(str string) (n int, err error) { +func (c *testReadWriter) writeHex(str string) { var buf []byte + var err error + if buf, err = hex.DecodeString(str); err != nil { - return + panic("writeHex: malformed hex: " + err.Error()) + } + if _, err = c.readBuf.Write(buf); err != nil { + panic("writeHex: buffered write failed: " + err.Error()) } - return c.readBuf.Write(buf) }
func (c *testReadWriter) readHex() string { diff --git a/obfs4proxy/obfs4proxy.go b/obfs4proxy/obfs4proxy.go index 0770455..6de361b 100644 --- a/obfs4proxy/obfs4proxy.go +++ b/obfs4proxy/obfs4proxy.go @@ -75,23 +75,25 @@ func clientSetup() (launched bool, listeners []net.Listener) { for _, name := range ptClientInfo.MethodNames { t := transports.Get(name) if t == nil { - pt.CmethodError(name, "no such transport is supported") + _ = pt.CmethodError(name, "no such transport is supported") continue }
f, err := t.ClientFactory(stateDir) if err != nil { - pt.CmethodError(name, "failed to get ClientFactory") + _ = pt.CmethodError(name, "failed to get ClientFactory") continue }
ln, err := net.Listen("tcp", socksAddr) if err != nil { - pt.CmethodError(name, err.Error()) + _ = pt.CmethodError(name, err.Error()) continue }
- go clientAcceptLoop(f, ln, ptClientProxy) + go func() { + _ = clientAcceptLoop(f, ln, ptClientProxy) + }() pt.Cmethod(name, socks5.Version(), ln.Addr())
log.Infof("%s - registered listener: %s", name, ln.Addr()) @@ -137,7 +139,7 @@ func clientHandler(f base.ClientFactory, conn net.Conn, proxyURI *url.URL) { args, err := f.ParseArgs(&socksReq.Args) if err != nil { log.Errorf("%s(%s) - invalid arguments: %s", name, addrStr, err) - socksReq.Reply(socks5.ReplyGeneralFailure) + _ = socksReq.Reply(socks5.ReplyGeneralFailure) return }
@@ -149,7 +151,7 @@ func clientHandler(f base.ClientFactory, conn net.Conn, proxyURI *url.URL) { // This should basically never happen, since config protocol // verifies this. log.Errorf("%s(%s) - failed to obtain proxy dialer: %s", name, addrStr, log.ElideError(err)) - socksReq.Reply(socks5.ReplyGeneralFailure) + _ = socksReq.Reply(socks5.ReplyGeneralFailure) return } dialFn = dialer.Dial @@ -157,7 +159,7 @@ func clientHandler(f base.ClientFactory, conn net.Conn, proxyURI *url.URL) { remote, err := f.Dial("tcp", socksReq.Target, dialFn, args) if err != nil { log.Errorf("%s(%s) - outgoing connection failed: %s", name, addrStr, log.ElideError(err)) - socksReq.Reply(socks5.ErrorToReplyCode(err)) + _ = socksReq.Reply(socks5.ErrorToReplyCode(err)) return } defer remote.Close() @@ -172,8 +174,6 @@ func clientHandler(f base.ClientFactory, conn net.Conn, proxyURI *url.URL) { } else { log.Infof("%s(%s) - closed connection", name, addrStr) } - - return }
func serverSetup() (launched bool, listeners []net.Listener) { @@ -186,23 +186,25 @@ func serverSetup() (launched bool, listeners []net.Listener) { name := bindaddr.MethodName t := transports.Get(name) if t == nil { - pt.SmethodError(name, "no such transport is supported") + _ = pt.SmethodError(name, "no such transport is supported") continue }
f, err := t.ServerFactory(stateDir, &bindaddr.Options) if err != nil { - pt.SmethodError(name, err.Error()) + _ = pt.SmethodError(name, err.Error()) continue }
ln, err := net.ListenTCP("tcp", bindaddr.Addr) if err != nil { - pt.SmethodError(name, err.Error()) + _ = pt.SmethodError(name, err.Error()) continue }
- go serverAcceptLoop(f, ln, &ptServerInfo) + go func() { + _ = serverAcceptLoop(f, ln, &ptServerInfo) + }() if args := f.Args(); args != nil { pt.SmethodArgs(name, ln.Addr(), *args) } else { @@ -262,8 +264,6 @@ func serverHandler(f base.ServerFactory, conn net.Conn, info *pt.ServerInfo) { } else { log.Infof("%s(%s) - closed connection", name, addrStr) } - - return }
func copyLoop(a net.Conn, b net.Conn) error { @@ -326,7 +326,7 @@ func main() {
// Determine if this is a client or server, initialize the common state. var ptListeners []net.Listener - launched := false + var launched bool isClient, err := ptIsClient() if err != nil { golog.Fatalf("[ERROR]: %s - must be run as a managed transport", execName) diff --git a/obfs4proxy/pt_extras.go b/obfs4proxy/pt_extras.go index f490fbc..dfe6d0f 100644 --- a/obfs4proxy/pt_extras.go +++ b/obfs4proxy/pt_extras.go @@ -43,19 +43,19 @@ import (
func ptEnvError(msg string) error { line := []byte(fmt.Sprintf("ENV-ERROR %s\n", msg)) - pt.Stdout.Write(line) + _, _ = pt.Stdout.Write(line) return errors.New(msg) }
func ptProxyError(msg string) error { line := []byte(fmt.Sprintf("PROXY-ERROR %s\n", msg)) - pt.Stdout.Write(line) + _, _ = pt.Stdout.Write(line) return errors.New(msg) }
func ptProxyDone() { line := []byte("PROXY DONE\n") - pt.Stdout.Write(line) + _, _ = pt.Stdout.Write(line) }
func ptIsClient() (bool, error) { diff --git a/transports/meeklite/meek.go b/transports/meeklite/meek.go index ca52a4a..a99556b 100644 --- a/transports/meeklite/meek.go +++ b/transports/meeklite/meek.go @@ -216,7 +216,7 @@ func (c *meekConn) SetWriteDeadline(t time.Time) error { }
func (c *meekConn) enqueueWrite(b []byte) (ok bool) { - defer func() { recover() }() + defer func() { _ = recover() }() c.workerWrChan <- b return true } @@ -273,7 +273,7 @@ loop: // If the poll interval has elapsed, issue a request. case sndBuf = <-c.workerWrChan: // If there is data pending a send, issue a request. - case _ = <-c.workerCloseChan: + case <-c.workerCloseChan: break loop }
diff --git a/transports/obfs2/obfs2.go b/transports/obfs2/obfs2.go index 66e0dbb..7eaaa96 100644 --- a/transports/obfs2/obfs2.go +++ b/transports/obfs2/obfs2.go @@ -362,9 +362,9 @@ func mac(s, x []byte) []byte { // H(x) is SHA256 of x. // MAC(s, x) = H(s | x | s) h := sha256.New() - h.Write(s) - h.Write(x) - h.Write(s) + _, _ = h.Write(s) + _, _ = h.Write(x) + _, _ = h.Write(s) return h.Sum(nil) }
diff --git a/transports/obfs3/obfs3.go b/transports/obfs3/obfs3.go index f25d1bd..26b4728 100644 --- a/transports/obfs3/obfs3.go +++ b/transports/obfs3/obfs3.go @@ -235,17 +235,17 @@ func (conn *obfs3Conn) kdf(sharedSecret []byte) error { // RESP_KEY = RESP_SECRET[:KEYLEN] // RESP_COUNTER = RESP_SECRET[KEYLEN:] initHmac := hmac.New(sha256.New, sharedSecret) - initHmac.Write([]byte(initiatorKdfString)) + _, _ = initHmac.Write([]byte(initiatorKdfString)) initSecret := initHmac.Sum(nil) initHmac.Reset() - initHmac.Write([]byte(initiatorMagicString)) + _, _ = initHmac.Write([]byte(initiatorMagicString)) initMagic := initHmac.Sum(nil)
respHmac := hmac.New(sha256.New, sharedSecret) - respHmac.Write([]byte(responderKdfString)) + _, _ = respHmac.Write([]byte(responderKdfString)) respSecret := respHmac.Sum(nil) respHmac.Reset() - respHmac.Write([]byte(responderMagicString)) + _, _ = respHmac.Write([]byte(responderMagicString)) respMagic := respHmac.Sum(nil)
// The INIT_KEY value keys a block cipher (in CTR mode) used to diff --git a/transports/obfs4/framing/framing_test.go b/transports/obfs4/framing/framing_test.go index 03e0d3b..f34a3a6 100644 --- a/transports/obfs4/framing/framing_test.go +++ b/transports/obfs4/framing/framing_test.go @@ -158,7 +158,7 @@ func BenchmarkEncoder_Encode(b *testing.B) { b.Fatal("buffer.Read() failed:", err) }
- n, err = encoder.Encode(frame[:], chopBuf[:n]) + n, _ = encoder.Encode(frame[:], chopBuf[:n]) transfered += n - FrameOverhead } if transfered != len(payload) { diff --git a/transports/obfs4/handshake_ntor.go b/transports/obfs4/handshake_ntor.go index 99f3925..6629c46 100644 --- a/transports/obfs4/handshake_ntor.go +++ b/transports/obfs4/handshake_ntor.go @@ -137,7 +137,7 @@ func (hs *clientHandshake) generateHandshake() ([]byte, error) { var buf bytes.Buffer
hs.mac.Reset() - hs.mac.Write(hs.keypair.Representative().Bytes()[:]) + _, _ = hs.mac.Write(hs.keypair.Representative().Bytes()[:]) mark := hs.mac.Sum(nil)[:markLength]
// The client handshake is X | P_C | M_C | MAC(X | P_C | M_C | E) where: @@ -161,9 +161,9 @@ func (hs *clientHandshake) generateHandshake() ([]byte, error) {
// Calculate and write the MAC. hs.mac.Reset() - hs.mac.Write(buf.Bytes()) + _, _ = hs.mac.Write(buf.Bytes()) hs.epochHour = []byte(strconv.FormatInt(getEpochHour(), 10)) - hs.mac.Write(hs.epochHour) + _, _ = hs.mac.Write(hs.epochHour) buf.Write(hs.mac.Sum(nil)[:macLength])
return buf.Bytes(), nil @@ -185,7 +185,7 @@ func (hs *clientHandshake) parseServerHandshake(resp []byte) (int, []byte, error
// Derive the mark. hs.mac.Reset() - hs.mac.Write(hs.serverRepresentative.Bytes()[:]) + _, _ = hs.mac.Write(hs.serverRepresentative.Bytes()[:]) hs.serverMark = hs.mac.Sum(nil)[:markLength] }
@@ -201,8 +201,8 @@ func (hs *clientHandshake) parseServerHandshake(resp []byte) (int, []byte, error
// Validate the MAC. hs.mac.Reset() - hs.mac.Write(resp[:pos+markLength]) - hs.mac.Write(hs.epochHour) + _, _ = hs.mac.Write(resp[:pos+markLength]) + _, _ = hs.mac.Write(hs.epochHour) macCmp := hs.mac.Sum(nil)[:macLength] macRx := resp[pos+markLength : pos+markLength+macLength] if !hmac.Equal(macCmp, macRx) { @@ -262,7 +262,7 @@ func (hs *serverHandshake) parseClientHandshake(filter *replayfilter.ReplayFilte
// Derive the mark. hs.mac.Reset() - hs.mac.Write(hs.clientRepresentative.Bytes()[:]) + _, _ = hs.mac.Write(hs.clientRepresentative.Bytes()[:]) hs.clientMark = hs.mac.Sum(nil)[:markLength] }
@@ -282,8 +282,8 @@ func (hs *serverHandshake) parseClientHandshake(filter *replayfilter.ReplayFilte // Allow epoch to be off by up to a hour in either direction. epochHour := []byte(strconv.FormatInt(getEpochHour()+int64(off), 10)) hs.mac.Reset() - hs.mac.Write(resp[:pos+markLength]) - hs.mac.Write(epochHour) + _, _ = hs.mac.Write(resp[:pos+markLength]) + _, _ = hs.mac.Write(epochHour) macCmp := hs.mac.Sum(nil)[:macLength] macRx := resp[pos+markLength : pos+markLength+macLength] if hmac.Equal(macCmp, macRx) { @@ -329,7 +329,7 @@ func (hs *serverHandshake) generateHandshake() ([]byte, error) { var buf bytes.Buffer
hs.mac.Reset() - hs.mac.Write(hs.keypair.Representative().Bytes()[:]) + _, _ = hs.mac.Write(hs.keypair.Representative().Bytes()[:]) mark := hs.mac.Sum(nil)[:markLength]
// The server handshake is Y | AUTH | P_S | M_S | MAC(Y | AUTH | P_S | M_S | E) where: @@ -355,8 +355,8 @@ func (hs *serverHandshake) generateHandshake() ([]byte, error) {
// Calculate and write the MAC. hs.mac.Reset() - hs.mac.Write(buf.Bytes()) - hs.mac.Write(hs.epochHour) // Set in hs.parseClientHandshake() + _, _ = hs.mac.Write(buf.Bytes()) + _, _ = hs.mac.Write(hs.epochHour) // Set in hs.parseClientHandshake() buf.Write(hs.mac.Sum(nil)[:macLength])
return buf.Bytes(), nil diff --git a/transports/scramblesuit/conn.go b/transports/scramblesuit/conn.go index 335be6e..715d20a 100644 --- a/transports/scramblesuit/conn.go +++ b/transports/scramblesuit/conn.go @@ -245,7 +245,7 @@ func (conn *ssConn) makePacket(w io.Writer, pktType byte, data []byte, padLen in // Encrypt the packet, and calculate the MAC. conn.txCrypto.s.XORKeyStream(pkt, pkt) conn.txCrypto.mac.Reset() - conn.txCrypto.mac.Write(pkt) + _, _ = conn.txCrypto.mac.Write(pkt) mac := conn.txCrypto.mac.Sum(nil)[:macLength]
// Write out MAC | Packet. Note that this does not go onto the network @@ -273,7 +273,7 @@ func (conn *ssConn) readPackets() error { break } mac := make([]byte, macLength) - conn.receiveBuffer.Read(mac) + _, _ = conn.receiveBuffer.Read(mac) conn.receiveState.mac = mac }
@@ -283,12 +283,12 @@ func (conn *ssConn) readPackets() error { break } hdr := make([]byte, pktHdrLength) - conn.receiveBuffer.Read(hdr) + _, _ = conn.receiveBuffer.Read(hdr)
// Add the encrypted packet header to the HMAC instance, and then // decrypt it so that the length of the packet can be determined. conn.rxCrypto.mac.Reset() - conn.rxCrypto.mac.Write(hdr) + _, _ = conn.rxCrypto.mac.Write(hdr) conn.rxCrypto.s.XORKeyStream(hdr, hdr)
// Store the plaintext packet header, and host byte order length @@ -311,8 +311,8 @@ func (conn *ssConn) readPackets() error { break } data = make([]byte, conn.receiveState.totalLen) - conn.receiveBuffer.Read(data) - conn.rxCrypto.mac.Write(data) + _, _ = conn.receiveBuffer.Read(data) + _, _ = conn.rxCrypto.mac.Write(data) conn.rxCrypto.s.XORKeyStream(data, data) }
diff --git a/transports/scramblesuit/handshake_ticket.go b/transports/scramblesuit/handshake_ticket.go index 16b57d6..9672e1b 100644 --- a/transports/scramblesuit/handshake_ticket.go +++ b/transports/scramblesuit/handshake_ticket.go @@ -106,7 +106,7 @@ func (s *ssTicketStore) storeTicket(addr net.Addr, rawT []byte) { // are ignored because the handshake code will just use UniformDH if a // ticket is not available. s.store[addr.String()] = t - s.serialize() + _ = s.serialize() }
func (s *ssTicketStore) getTicket(addr net.Addr) (*ssTicket, error) { @@ -198,7 +198,7 @@ func (hs *ssTicketClientHandshake) generateHandshake() ([]byte, error) { hs.mac.Reset()
// The client handshake is T | P | M | MAC(T | P | M | E) - hs.mac.Write(hs.ticket.ticket[:]) + _, _ = hs.mac.Write(hs.ticket.ticket[:]) m := hs.mac.Sum(nil)[:macLength] p, err := makePad(hs.padLen) if err != nil { @@ -212,9 +212,9 @@ func (hs *ssTicketClientHandshake) generateHandshake() ([]byte, error) {
// Calculate and write the MAC. e := []byte(strconv.FormatInt(getEpochHour(), 10)) - hs.mac.Write(p) - hs.mac.Write(m) - hs.mac.Write(e) + _, _ = hs.mac.Write(p) + _, _ = hs.mac.Write(m) + _, _ = hs.mac.Write(e) buf.Write(hs.mac.Sum(nil)[:macLength])
hs.mac.Reset() diff --git a/transports/scramblesuit/handshake_uniformdh.go b/transports/scramblesuit/handshake_uniformdh.go index 3e8ed59..5a79d64 100644 --- a/transports/scramblesuit/handshake_uniformdh.go +++ b/transports/scramblesuit/handshake_uniformdh.go @@ -76,7 +76,7 @@ func (hs *ssDHClientHandshake) generateHandshake() ([]byte, error) { if err != nil { return nil, err } - hs.mac.Write(x) + _, _ = hs.mac.Write(x) mC := hs.mac.Sum(nil)[:macLength] pC, err := makePad(hs.padLen) if err != nil { @@ -90,9 +90,9 @@ func (hs *ssDHClientHandshake) generateHandshake() ([]byte, error) {
// Calculate and write the MAC. hs.epochHour = []byte(strconv.FormatInt(getEpochHour(), 10)) - hs.mac.Write(pC) - hs.mac.Write(mC) - hs.mac.Write(hs.epochHour) + _, _ = hs.mac.Write(pC) + _, _ = hs.mac.Write(mC) + _, _ = hs.mac.Write(hs.epochHour) buf.Write(hs.mac.Sum(nil)[:macLength])
return buf.Bytes(), nil @@ -113,7 +113,7 @@ func (hs *ssDHClientHandshake) parseServerHandshake(resp []byte) (int, []byte, e return 0, nil, err } hs.mac.Reset() - hs.mac.Write(y) + _, _ = hs.mac.Write(y) hs.serverMark = hs.mac.Sum(nil)[:macLength] }
@@ -136,8 +136,8 @@ func (hs *ssDHClientHandshake) parseServerHandshake(resp []byte) (int, []byte, e pos += uniformdh.Size
// Validate the MAC. - hs.mac.Write(resp[uniformdh.Size : pos+macLength]) - hs.mac.Write(hs.epochHour) + _, _ = hs.mac.Write(resp[uniformdh.Size : pos+macLength]) + _, _ = hs.mac.Write(hs.epochHour) macCmp := hs.mac.Sum(nil)[:macLength] macRx := resp[pos+macLength : pos+2*macLength] if !hmac.Equal(macCmp, macRx) { diff --git a/transports/scramblesuit/hkdf_expand.go b/transports/scramblesuit/hkdf_expand.go index 9626b38..5f4f4b4 100644 --- a/transports/scramblesuit/hkdf_expand.go +++ b/transports/scramblesuit/hkdf_expand.go @@ -50,9 +50,9 @@ func hkdfExpand(hashFn func() hash.Hash, prk []byte, info []byte, l int) []byte ctr := byte(1) for toAppend > 0 { h.Reset() - h.Write(t) - h.Write(info) - h.Write([]byte{ctr}) + _, _ = h.Write(t) + _, _ = h.Write(info) + _, _ = h.Write([]byte{ctr}) t = h.Sum(nil) ctr++
diff --git a/transports/transports.go b/transports/transports.go index 6301c8b..921666a 100644 --- a/transports/transports.go +++ b/transports/transports.go @@ -84,11 +84,17 @@ func Get(name string) base.Transport {
// Init initializes all of the integrated transports. func Init() error { - Register(new(meeklite.Transport)) - Register(new(obfs2.Transport)) - Register(new(obfs3.Transport)) - Register(new(obfs4.Transport)) - Register(new(scramblesuit.Transport)) + for _, v := range []base.Transport{ + new(meeklite.Transport), + new(obfs2.Transport), + new(obfs3.Transport), + new(obfs4.Transport), + new(scramblesuit.Transport), + } { + if err := Register(v); err != nil { + return err + } + }
return nil }