Rod Hynes 1 год назад
Родитель
Сommit
bf9fbda91e

+ 1 - 4
psiphon/common/inproxy/discoverySTUN.go

@@ -115,11 +115,8 @@ func discoverNATMapping(
 	response3Fields := parseSTUNMessage(response3)
 	if response3Fields.xorAddr.String() == response2Fields.xorAddr.String() {
 		return NATMappingAddressDependent, nil
-	} else {
-		return NATMappingAddressPortDependent, nil
 	}
-
-	return NATMappingUnknown, nil
+	return NATMappingAddressPortDependent, nil
 }
 
 // RFC5780: 4.4.  Determining NAT Filtering Behavior

+ 1 - 18
psiphon/common/regen/regen_test.go

@@ -36,7 +36,6 @@ limitations under the License.
 package regen
 
 import (
-	"encoding/hex"
 	"fmt"
 	"math"
 	"math/rand"
@@ -58,7 +57,7 @@ const (
 	MaxSupportedRepeatCount = 1000
 )
 
-func ExampleGenerate() {
+func ExampleGenerateString() {
 	pattern := "[ab]{5}"
 	bytes, _ := GenerateString(pattern)
 
@@ -94,22 +93,6 @@ func ExampleNewGenerator() {
 	// Matches!
 }
 
-func ExampleByteModeGenerator() {
-	for i := 0; i < 100; i++ {
-		gen, err := NewGenerator(`([\x00-\x6a])\x00\x01\x02[\x00-\xff]{5}`, &GeneratorArgs{
-			ByteMode: true,
-		})
-		if err != nil {
-			panic(err)
-		}
-		x, err := gen.Generate()
-		if err != nil {
-			panic(err)
-		}
-		fmt.Println(hex.EncodeToString(x))
-	}
-}
-
 func ExampleNewGenerator_perl() {
 	pattern := `\d{5}`
 

+ 6 - 2
psiphon/common/tun/tun_darwin.go

@@ -266,7 +266,9 @@ func configureServerInterface(
 	tunDeviceName string) error {
 
 	// TODO: fix or remove the following broken code
-	return errors.Trace(errUnsupported)
+	if true {
+		return errors.Trace(errUnsupported)
+	}
 
 	// Set tun device network addresses and MTU
 
@@ -388,7 +390,9 @@ func configureClientInterface(
 	tunDeviceName string) error {
 
 	// TODO: fix or remove the following broken code
-	return errors.Trace(errUnsupported)
+	if true {
+		return errors.Trace(errUnsupported)
+	}
 
 	// Set tun device network addresses and MTU
 

+ 4 - 4
psiphon/common/tun/tun_test.go

@@ -326,7 +326,7 @@ type testServer struct {
 	metricsUpdater MetricsUpdater
 	tunServer      *Server
 	unixListener   net.Listener
-	clientConns    *common.Conns
+	clientConns    *common.Conns[net.Conn]
 	workers        *sync.WaitGroup
 }
 
@@ -376,7 +376,7 @@ func startTestServer(
 		metricsUpdater: metricsUpdater,
 		tunServer:      tunServer,
 		unixListener:   unixListener,
-		clientConns:    common.NewConns(),
+		clientConns:    common.NewConns[net.Conn](),
 		workers:        new(sync.WaitGroup),
 	}
 
@@ -550,7 +550,7 @@ func (client *testClient) stop() {
 type testTCPServer struct {
 	listenerIPAddress string
 	tcpListener       net.Listener
-	clientConns       *common.Conns
+	clientConns       *common.Conns[net.Conn]
 	workers           *sync.WaitGroup
 }
 
@@ -588,7 +588,7 @@ func startTestTCPServer(useIPv6 bool) (*testTCPServer, error) {
 	server := &testTCPServer{
 		listenerIPAddress: hostIPaddress,
 		tcpListener:       tcpListener,
-		clientConns:       common.NewConns(),
+		clientConns:       common.NewConns[net.Conn](),
 		workers:           new(sync.WaitGroup),
 	}
 

+ 0 - 2
psiphon/dataStore.go

@@ -424,8 +424,6 @@ func StreamingStoreServerEntries(
 			n = 0
 		}
 	}
-
-	return nil
 }
 
 // ImportEmbeddedServerEntries loads, decodes, and stores a list of server

+ 1 - 1
psiphon/server/server_test.go

@@ -1081,7 +1081,7 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
 		err := RunServices(serverConfigJSON)
 		if err != nil {
 			// TODO: wrong goroutine for t.FatalNow()
-			t.Fatalf("error running server: %s", err)
+			t.Errorf("error running server: %s", err)
 		}
 	}()
 

+ 2 - 2
psiphon/upstreamproxy/go-ntlm/ntlm/message_authenticate_test.go

@@ -41,7 +41,7 @@ func TestAuthenticateNtlmV1(t *testing.T) {
 		t.Error("Could not parse authenticate message")
 	}
 
-	a.String()
+	_ = a.String()
 
 	outBytes := a.Bytes()
 
@@ -92,7 +92,7 @@ func TestAuthenticateNtlmV2(t *testing.T) {
 		t.Errorf("Length of payload is incorrect got: %d, should be %d", len(a.Payload), 356)
 	}
 
-	a.String()
+	_ = a.String()
 
 	// Generate the bytes from the message and reparse it and make sure that works
 	bytes := a.Bytes()

+ 1 - 1
psiphon/upstreamproxy/go-ntlm/ntlm/message_challenge_test.go

@@ -47,7 +47,7 @@ func TestDecodeChallenge(t *testing.T) {
 		t.Error("Payload length is not long enough")
 	}
 
-	challenge.String()
+	_ = challenge.String()
 
 	outBytes := challenge.Bytes()
 

+ 4 - 4
psiphon/upstreamproxy/go-ntlm/ntlm/ntlmv1_test.go

@@ -139,7 +139,7 @@ func TestNtlmV1(t *testing.T) {
 	challengeMessageBytes, _ := hex.DecodeString("4e544c4d53535000020000000c000c003800000033820a820123456789abcdef00000000000000000000000000000000060070170000000f530065007200760065007200")
 	challengeMessage, err := ParseChallengeMessage(challengeMessageBytes)
 	if err == nil {
-		challengeMessage.String()
+		_ = challengeMessage.String()
 	} else {
 		t.Errorf("Could not parse challenge message: %s", err)
 	}
@@ -156,7 +156,7 @@ func TestNtlmV1(t *testing.T) {
 	authenticateMessageBytes, err := hex.DecodeString("4e544c4d5353500003000000180018006c00000018001800840000000c000c00480000000800080054000000100010005c000000100010009c000000358280e20501280a0000000f44006f006d00610069006e00550073006500720043004f004d005000550054004500520098def7b87f88aa5dafe2df779688a172def11c7d5ccdef1367c43011f30298a2ad35ece64f16331c44bdbed927841f94518822b1b3f350c8958682ecbb3e3cb7")
 	authenticateMessage, err := ParseAuthenticateMessage(authenticateMessageBytes, 1)
 	if err == nil {
-		authenticateMessage.String()
+		_ = authenticateMessage.String()
 	} else {
 		t.Errorf("Could not parse authenticate message: %s", err)
 	}
@@ -204,7 +204,7 @@ func TestNTLMv1WithClientChallenge(t *testing.T) {
 	challengeMessageBytes, _ := hex.DecodeString("4e544c4d53535000020000000c000c003800000033820a820123456789abcdef00000000000000000000000000000000060070170000000f530065007200760065007200")
 	challengeMessage, err := ParseChallengeMessage(challengeMessageBytes)
 	if err == nil {
-		challengeMessage.String()
+		_ = challengeMessage.String()
 	} else {
 		t.Errorf("Could not parse challenge message: %s", err)
 	}
@@ -223,7 +223,7 @@ func TestNTLMv1WithClientChallenge(t *testing.T) {
 	authenticateMessageBytes, _ := hex.DecodeString("4e544c4d5353500003000000180018006c00000018001800840000000c000c00480000000800080054000000100010005c000000000000009c000000358208820501280a0000000f44006f006d00610069006e00550073006500720043004f004d0050005500540045005200aaaaaaaaaaaaaaaa000000000000000000000000000000007537f803ae367128ca458204bde7caf81e97ed2683267232")
 	authenticateMessage, err := ParseAuthenticateMessage(authenticateMessageBytes, 1)
 	if err == nil {
-		authenticateMessage.String()
+		_ = authenticateMessage.String()
 	} else {
 		t.Errorf("Could not parse authenticate message: %s", err)
 	}

+ 3 - 3
psiphon/upstreamproxy/go-ntlm/ntlm/ntlmv2_test.go

@@ -65,7 +65,7 @@ func TestNTLMv2(t *testing.T) {
 	challengeMessageBytes, _ := hex.DecodeString("4e544c4d53535000020000000c000c003800000033828ae20123456789abcdef00000000000000002400240044000000060070170000000f53006500720076006500720002000c0044006f006d00610069006e0001000c0053006500720076006500720000000000")
 	challengeMessage, err := ParseChallengeMessage(challengeMessageBytes)
 	if err == nil {
-		challengeMessage.String()
+		_ = challengeMessage.String()
 	} else {
 		t.Errorf("Could not parse challenge message: %s", err)
 	}
@@ -100,7 +100,7 @@ func TestNTLMv2(t *testing.T) {
 
 	authenticateMessage, err := ParseAuthenticateMessage(authenticateMessageBytes, 2)
 	if err == nil {
-		authenticateMessage.String()
+		_ = authenticateMessage.String()
 	} else {
 		t.Errorf("Could not parse authenticate message: %s", err)
 	}
@@ -119,7 +119,7 @@ func TestNTLMv2(t *testing.T) {
 
 	// Have the server generate an initial challenge message
 	challenge, err := server.GenerateChallengeMessage()
-	challenge.String()
+	_ = challenge.String()
 
 	// Have the client process this server challenge message
 	client = new(V2ClientSession)

+ 14 - 8
psiphon/upstreamproxy/go-ntlm/ntlm/signature.go

@@ -28,10 +28,8 @@ func (n *NtlmsspMessageSignature) String() string {
 func (n *NtlmsspMessageSignature) Bytes() []byte {
 	if n.ByteData != nil {
 		return n.ByteData
-	} else {
-		return concat(n.Version, n.RandomPad, n.CheckSum, n.SeqNum)
 	}
-	return nil
+	return concat(n.Version, n.RandomPad, n.CheckSum, n.SeqNum)
 }
 
 // Define SEAL(Handle, SigningKey, SeqNum, Message) as
@@ -62,10 +60,14 @@ func mac(negFlags uint32, handle *rc4P.Cipher, signingKey []byte, seqNum uint32,
 // Set NTLMSSP_MESSAGE_SIGNATURE.Checksum to RC4(Handle, NTLMSSP_MESSAGE_SIGNATURE.Checksum)
 // Set NTLMSSP_MESSAGE_SIGNATURE.SeqNum to RC4(Handle, 0x00000000)
 // If (connection oriented)
-//   Set NTLMSSP_MESSAGE_SIGNATURE.SeqNum to NTLMSSP_MESSAGE_SIGNATURE.SeqNum XOR SeqNum
-//   Set SeqNum to SeqNum + 1
+//
+//	Set NTLMSSP_MESSAGE_SIGNATURE.SeqNum to NTLMSSP_MESSAGE_SIGNATURE.SeqNum XOR SeqNum
+//	Set SeqNum to SeqNum + 1
+//
 // Else
-//   Set NTLMSSP_MESSAGE_SIGNATURE.SeqNum to NTLMSSP_MESSAGE_SIGNATURE.SeqNum XOR (application supplied SeqNum)
+//
+//	Set NTLMSSP_MESSAGE_SIGNATURE.SeqNum to NTLMSSP_MESSAGE_SIGNATURE.SeqNum XOR (application supplied SeqNum)
+//
 // EndIf
 // Set NTLMSSP_MESSAGE_SIGNATURE.RandomPad to 0
 // End
@@ -91,9 +93,13 @@ func macWithoutExtendedSessionSecurity(handle *rc4P.Cipher, seqNum uint32, messa
 // Define MAC(Handle, SigningKey, SeqNum, Message) as
 // Set NTLMSSP_MESSAGE_SIGNATURE.Version to 0x00000001
 // if Key Exchange Key Negotiated
-//   Set NTLMSSP_MESSAGE_SIGNATURE.Checksum to RC4(Handle, HMAC_MD5(SigningKey, ConcatenationOf(SeqNum, Message))[0..7])
+//
+//	Set NTLMSSP_MESSAGE_SIGNATURE.Checksum to RC4(Handle, HMAC_MD5(SigningKey, ConcatenationOf(SeqNum, Message))[0..7])
+//
 // else
-//   Set NTLMSSP_MESSAGE_SIGNATURE.Checksum to HMAC_MD5(SigningKey, ConcatenationOf(SeqNum, Message))[0..7]
+//
+//	Set NTLMSSP_MESSAGE_SIGNATURE.Checksum to HMAC_MD5(SigningKey, ConcatenationOf(SeqNum, Message))[0..7]
+//
 // end
 // Set NTLMSSP_MESSAGE_SIGNATURE.SeqNum to SeqNum
 // Set SeqNum to SeqNum + 1