diff --git a/nas/auth.go b/nas/auth.go index 249ae9d..22f84a9 100644 --- a/nas/auth.go +++ b/nas/auth.go @@ -159,7 +159,7 @@ func handleAuthRequest(moduleName string, w http.ResponseWriter, r *http.Request param.Set(key, common.Base64DwcEncoding.EncodeToString([]byte(value))) } response = []byte(param.Encode()) - response = []byte(strings.Replace(string(response), "%2A", "*", -1)) + response = []byte(strings.ReplaceAll(string(response), "%2A", "*")) } // DWC treats the response like a null terminated string @@ -167,7 +167,10 @@ func handleAuthRequest(moduleName string, w http.ResponseWriter, r *http.Request w.Header().Set("Content-Type", "text/plain") w.Header().Set("Content-Length", strconv.Itoa(len(response))) - w.Write(response) + _, err = w.Write(response) + if err != nil { + logging.Error("NAS", "Error writing response:", err) + } } func acctcreate() map[string]string { diff --git a/nas/conntest.go b/nas/conntest.go index 034e5bf..6403e2c 100644 --- a/nas/conntest.go +++ b/nas/conntest.go @@ -23,5 +23,5 @@ func handleConnectionTest(w http.ResponseWriter) { w.Header().Set("X-Organization", "Nintendo") w.Header().Set("Connection", "Keep-Alive") w.WriteHeader(200) - w.Write([]byte(response)) + _, _ = w.Write([]byte(response)) } diff --git a/nas/https.go b/nas/https.go index 492b410..5006760 100644 --- a/nas/https.go +++ b/nas/https.go @@ -75,7 +75,7 @@ func startHTTPSProxy(config common.Config) { } }() - if !(exploitWii || exploitDS) { + if !exploitWii && !exploitDS { // Only handle real TLS requests for { conn, err := l.Accept() @@ -86,7 +86,7 @@ func startHTTPSProxy(config common.Config) { go func() { moduleName := "NAS-TLS:" + conn.RemoteAddr().String() - conn.SetDeadline(time.Now().UTC().Add(25 * time.Second)) + _ = conn.SetDeadline(time.Now().UTC().Add(25 * time.Second)) handleRealTLS(moduleName, conn, nasAddr) }() @@ -241,7 +241,7 @@ func startHTTPSProxy(config common.Config) { moduleName := "NAS-TLS:" + conn.RemoteAddr().String() - conn.SetDeadline(time.Now().UTC().Add(5 * time.Second)) + _ = conn.SetDeadline(time.Now().UTC().Add(5 * time.Second)) handleTLS(moduleName, conn, nasAddr, serverCertsRecordWii, rsaKeyWii, serverCertsRecordDS, rsaKeyDS) }() @@ -259,7 +259,9 @@ func handleTLS(moduleName string, rawConn net.Conn, nasAddr string, serverCertsR conn := newBufferedConn(rawConn) - defer conn.Close() + defer func() { + _ = conn.Close() + }() // Read client hello // fmt.Printf("Client Hello:\n") @@ -316,7 +318,7 @@ func handleTLS(moduleName string, rawConn net.Conn, nasAddr string, serverCertsR } } - conn.SetDeadline(time.Now().UTC().Add(25 * time.Second)) + _ = conn.SetDeadline(time.Now().UTC().Add(25 * time.Second)) // logging.Info(moduleName, "Forwarding client hello:", aurora.Cyan(fmt.Sprintf("% X ", helloBytes))) handleRealTLS(moduleName, conn, nasAddr) @@ -684,7 +686,9 @@ func proxyConsoleTLS(moduleName string, conn bufferedConn, nasAddr string, versi panic(err) } - defer newConn.Close() + defer func() { + _ = newConn.Close() + }() // Read bytes from the HTTP server and forward them through the TLS connection go func() { @@ -734,11 +738,7 @@ func proxyConsoleTLS(moduleName string, conn bufferedConn, nasAddr string, versi index += n total += n - for { - if index < 5 { - break - } - + for index < 5 { if buf[0] < 0x15 || buf[0] > 0x17 { logging.Error(moduleName, "Invalid record type") return @@ -842,7 +842,9 @@ func handleRealTLS(moduleName string, conn net.Conn, nasAddr string) { panic(err) } - defer newConn.Close() + defer func() { + _ = newConn.Close() + }() // Read bytes from the HTTP server and forward them through the TLS connection go func() { diff --git a/nas/main.go b/nas/main.go index 283dd7f..a23ceff 100644 --- a/nas/main.go +++ b/nas/main.go @@ -195,7 +195,7 @@ func replyHTTPError(w http.ResponseWriter, errorCode int, errorString string) { w.Header().Set("Connection", "close") w.Header().Set("Server", "Nintendo") w.WriteHeader(errorCode) - w.Write([]byte(response)) + _, _ = w.Write([]byte(response)) } func handleNASTest(w http.ResponseWriter) { @@ -214,7 +214,7 @@ func handleNASTest(w http.ResponseWriter) { w.Header().Set("Server", "Nintendo") w.WriteHeader(200) - w.Write([]byte(response)) + _, _ = w.Write([]byte(response)) } func forwardPayloadRequest(moduleName string, w http.ResponseWriter, r *http.Request) { @@ -233,7 +233,9 @@ func forwardPayloadRequest(moduleName string, w http.ResponseWriter, r *http.Req replyHTTPError(w, http.StatusBadGateway, "502 Bad Gateway") return } - defer resp.Body.Close() + defer func() { + _ = resp.Body.Close() + }() // Copy the response headers and status code for key, values := range resp.Header { @@ -246,9 +248,12 @@ func forwardPayloadRequest(moduleName string, w http.ResponseWriter, r *http.Req // Copy the response body body, err := io.ReadAll(resp.Body) if err != nil { - logging.Error(moduleName, "Error reading response body:", err) + logging.Error(moduleName, "Error reading payload response body:", err) replyHTTPError(w, http.StatusInternalServerError, "500 Internal Server Error") return } - w.Write(body) + _, err = w.Write(body) + if err != nil { + logging.Error(moduleName, "Error writing payload response body:", err) + } } diff --git a/nas/payload.go b/nas/payload.go index ff79997..9c21b3b 100644 --- a/nas/payload.go +++ b/nas/payload.go @@ -32,7 +32,10 @@ func downloadStage1(w http.ResponseWriter, stage1Ver int) { w.Header().Set("Content-Type", "text/plain") w.Header().Set("Content-Length", strconv.Itoa(len(payload))) - w.Write(payload) + _, err = w.Write(payload) + if err != nil { + logging.Error("NAS", "Error writing stage 1 payload:", err) + } } func handlePayloadRequest(moduleName string, w http.ResponseWriter, r *http.Request) { @@ -171,5 +174,8 @@ func handlePayloadRequest(moduleName string, w http.ResponseWriter, r *http.Requ dat = append(append(dat[:0x10], signature...), dat[0x110:]...) w.Header().Set("Content-Length", strconv.Itoa(len(dat))) - w.Write(dat) + _, err = w.Write(dat) + if err != nil { + logging.Error("NAS", "Error writing payload response body:", err) + } } diff --git a/nas/profanity.go b/nas/profanity.go index 2b8cd14..2d9e3cd 100644 --- a/nas/profanity.go +++ b/nas/profanity.go @@ -6,6 +6,7 @@ import ( "os" "strings" "time" + "wwfc/common" ) var profanityFilePath = "./profanity.txt" @@ -13,15 +14,15 @@ var profanityFileLines []string = nil var lastModTime time.Time var symbolEquivalences = map[rune]rune{ - '1': 'i', - '0': 'o', - '5': 's', - '4': 'a', - '3': 'e', - '7': 't', - '9': 'g', - '2': 'z', - '(': 'c', + '1': 'i', + '0': 'o', + '5': 's', + '4': 'a', + '3': 'e', + '7': 't', + '9': 'g', + '2': 'z', + '(': 'c', } func CacheProfanityFile() error { @@ -38,7 +39,9 @@ func CacheProfanityFile() error { if err != nil { return err } - defer file.Close() + defer func() { + common.ShouldNotError(file.Close()) + }() profanityFileLines = nil scanner := bufio.NewScanner(file)