From 45f97d971e5f69d421acf5e53ae32e3660855948 Mon Sep 17 00:00:00 2001 From: Matthew Lopez <73856503+MatthewL246@users.noreply.github.com> Date: Wed, 20 Dec 2023 22:19:40 -0500 Subject: [PATCH] Set up the Wii U Chat server There seems to be a problem with the compatability of the authentication and secure servers. --- compose.yml | 28 +++++++++++ environment/wiiu-chat.env | 6 +++ .../wiiu-chat-authentication/dockerize.patch | 20 ++++++++ ...ake-environment-variables-consistent.patch | 49 +++++++++++++++++++ patches/wiiu-chat-secure/dockerize.patch | 20 ++++++++ ...ment-variables-for-port-and-database.patch | 24 +++++++++ scripts/setup-environment.sh | 6 +++ scripts/update-account-servers-database.sh | 13 ++++- 8 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 environment/wiiu-chat.env create mode 100644 patches/wiiu-chat-authentication/dockerize.patch create mode 100644 patches/wiiu-chat-authentication/make-environment-variables-consistent.patch create mode 100644 patches/wiiu-chat-secure/dockerize.patch create mode 100644 patches/wiiu-chat-secure/use-environment-variables-for-port-and-database.patch diff --git a/compose.yml b/compose.yml index 6bcb0c5..a78ee17 100644 --- a/compose.yml +++ b/compose.yml @@ -225,6 +225,34 @@ services: networks: internal: + wiiu-chat-authentication: + build: ./repos/wiiu-chat-authentication + depends_on: + - account + - mongodb + ports: + - 6002:6002/udp + env_file: + - ./environment/wiiu-chat.env + - ./environment/wiiu-chat.local.env + dns: 172.20.0.2 + networks: + internal: + + wiiu-chat-secure: + build: ./repos/wiiu-chat-secure + depends_on: + - account + - mongodb + ports: + - 6003:6003/udp + env_file: + - ./environment/wiiu-chat.env + - ./environment/wiiu-chat.local.env + dns: 172.20.0.2 + networks: + internal: + volumes: mitmproxy-pretendo-data: mongodb-database: diff --git a/environment/wiiu-chat.env b/environment/wiiu-chat.env new file mode 100644 index 0000000..4f01257 --- /dev/null +++ b/environment/wiiu-chat.env @@ -0,0 +1,6 @@ +PN_WIIU_CHAT_MONGO_URI=mongodb://mongodb:27017/pretendo_account?replicaSet=rs +PN_WIIU_CHAT_MONGO_DATABASE=pretendo_account +PN_WIIU_CHAT_AUTHENTICATION_SERVER_PORT=6002 +PN_WIIU_CHAT_SECURE_SERVER_PORT=6003 +PN_WIIU_CHAT_FRIENDS_GRPC_HOST=friends +PN_WIIU_CHAT_FRIENDS_GRPC_PORT=5001 diff --git a/patches/wiiu-chat-authentication/dockerize.patch b/patches/wiiu-chat-authentication/dockerize.patch new file mode 100644 index 0000000..4d5102c --- /dev/null +++ b/patches/wiiu-chat-authentication/dockerize.patch @@ -0,0 +1,20 @@ +diff --git c/Dockerfile i/Dockerfile +new file mode 100644 +index 0000000..0f18fe9 +--- /dev/null ++++ i/Dockerfile +@@ -0,0 +1,14 @@ ++FROM golang:alpine AS builder ++WORKDIR /build ++ ++COPY go.* ./ ++RUN go mod download ++ ++COPY . ./ ++RUN go build -v -o server ++ ++FROM alpine:latest AS runner ++WORKDIR /app ++ ++COPY --from=builder /build/server /app/server ++CMD ["/app/server"] diff --git a/patches/wiiu-chat-authentication/make-environment-variables-consistent.patch b/patches/wiiu-chat-authentication/make-environment-variables-consistent.patch new file mode 100644 index 0000000..234a60f --- /dev/null +++ b/patches/wiiu-chat-authentication/make-environment-variables-consistent.patch @@ -0,0 +1,49 @@ +diff --git i/main.go w/main.go +index 97dcb04..7dcb42d 100644 +--- i/main.go ++++ w/main.go +@@ -18,7 +18,7 @@ func main() { + Minor: 4, + Patch: 2, + }) +- nexServer.SetKerberosPassword(os.Getenv("KERBEROS_PASSWORD")) ++ nexServer.SetKerberosPassword(os.Getenv("PN_WIIU_CHAT_KERBEROS_PASSWORD")) + nexServer.SetAccessKey("e7a47214") + + nexServer.On("Data", func(packet *nex.PacketV1) { +@@ -34,8 +34,8 @@ func main() { + + secureStationURL := nex.NewStationURL("") + secureStationURL.SetScheme("prudps") +- secureStationURL.SetAddress(os.Getenv("SECURE_SERVER_LOCATION")) +- secureStationURL.SetPort(os.Getenv("SECURE_SERVER_PORT")) ++ secureStationURL.SetAddress(os.Getenv("PN_WIIU_CHAT_SECURE_SERVER_LOCATION")) ++ secureStationURL.SetPort(os.Getenv("PN_WIIU_CHAT_SECURE_SERVER_PORT")) + secureStationURL.SetCID("1") + secureStationURL.SetPID("2") + secureStationURL.SetSID("1") +@@ -46,5 +46,5 @@ func main() { + authenticationProtocol.SetBuildName("Pretendo WiiU Chat Auth") + authenticationProtocol.SetPasswordFromPIDFunction(passwordFromPID) + +- nexServer.Listen(":60004") ++ nexServer.Listen(":" + os.Getenv("PN_WIIU_CHAT_AUTHENTICATION_SERVER_PORT")) + } +diff --git i/database.go w/database.go +index abae4c2..05f1527 100644 +--- i/database.go ++++ w/database.go +@@ -16,11 +16,11 @@ var mongoDatabase *mongo.Database + var mongoCollection *mongo.Collection + + func connectMongo() { +- mongoClient, _ = mongo.NewClient(options.Client().ApplyURI(os.Getenv("MONGO_URI"))) ++ mongoClient, _ = mongo.NewClient(options.Client().ApplyURI(os.Getenv("PN_WIIU_CHAT_MONGO_URI"))) + mongoContext, _ = context.WithTimeout(context.Background(), 10*time.Second) + _ = mongoClient.Connect(mongoContext) + +- mongoDatabase = mongoClient.Database("pretendo") ++ mongoDatabase = mongoClient.Database(os.Getenv("PN_WIIU_CHAT_MONGO_DATABASE")) + mongoCollection = mongoDatabase.Collection("nexaccounts") + } + diff --git a/patches/wiiu-chat-secure/dockerize.patch b/patches/wiiu-chat-secure/dockerize.patch new file mode 100644 index 0000000..4d5102c --- /dev/null +++ b/patches/wiiu-chat-secure/dockerize.patch @@ -0,0 +1,20 @@ +diff --git c/Dockerfile i/Dockerfile +new file mode 100644 +index 0000000..0f18fe9 +--- /dev/null ++++ i/Dockerfile +@@ -0,0 +1,14 @@ ++FROM golang:alpine AS builder ++WORKDIR /build ++ ++COPY go.* ./ ++RUN go mod download ++ ++COPY . ./ ++RUN go build -v -o server ++ ++FROM alpine:latest AS runner ++WORKDIR /app ++ ++COPY --from=builder /build/server /app/server ++CMD ["/app/server"] diff --git a/patches/wiiu-chat-secure/use-environment-variables-for-port-and-database.patch b/patches/wiiu-chat-secure/use-environment-variables-for-port-and-database.patch new file mode 100644 index 0000000..e495738 --- /dev/null +++ b/patches/wiiu-chat-secure/use-environment-variables-for-port-and-database.patch @@ -0,0 +1,24 @@ +diff --git i/nex/server.go w/nex/server.go +index 3d15725..03531d1 100644 +--- i/nex/server.go ++++ w/nex/server.go +@@ -35,5 +35,5 @@ func StartNEXServer() { + registerCommonProtocols() + registerNEXProtocols() + +- globals.NEXServer.Listen(":60005") ++ globals.NEXServer.Listen(":" + os.Getenv("PN_WIIU_CHAT_SECURE_SERVER_PORT")) + } +diff --git i/database/connect_mongo.go w/database/connect_mongo.go +index 580fa98..1090679 100644 +--- i/database/connect_mongo.go ++++ w/database/connect_mongo.go +@@ -27,7 +27,7 @@ func connectMongo() { + mongoContext, _ = context.WithTimeout(context.Background(), 10*time.Second) + _ = mongoClient.Connect(mongoContext) + +- accountDatabase = mongoClient.Database("pretendo") ++ accountDatabase = mongoClient.Database(os.Getenv("PN_WIIU_CHAT_MONGO_DATABASE")) + pnidCollection = accountDatabase.Collection("pnids") + nexAccountsCollection = accountDatabase.Collection("nexaccounts") + diff --git a/scripts/setup-environment.sh b/scripts/setup-environment.sh index 6316674..8a539c3 100755 --- a/scripts/setup-environment.sh +++ b/scripts/setup-environment.sh @@ -52,14 +52,20 @@ friends_kerberos_password=$(generate_password 32) echo "PN_FRIENDS_CONFIG_KERBEROS_PASSWORD=$friends_kerberos_password" >>./friends.local.env friends_api_key=$(generate_password 32) echo "PN_FRIENDS_CONFIG_GRPC_API_KEY=$friends_api_key" >>./friends.local.env +echo "PN_WIIU_CHAT_FRIENDS_GRPC_API_KEY=$friends_api_key" >>./wiiu-chat.local.env friends_aes_key=$(generate_hex 64) echo "PN_FRIENDS_CONFIG_AES_KEY=$friends_aes_key" >>./friends.local.env +# Generate a Kerberos password for the Wii U Chat server +chat_kerberos_password=$(generate_password 32) +echo "PN_WIIU_CHAT_KERBEROS_PASSWORD=$chat_kerberos_password" >>./wiiu-chat.local.env + # Get the computer IP address printf "What is your computer's IP address? It must be accessible to your consoles: " read -r computer_ip echo "COMPUTER_IP=$computer_ip" >>./system.local.env echo "PN_FRIENDS_SECURE_SERVER_HOST=$computer_ip" >>./friends.local.env +echo "PN_WIIU_CHAT_SECURE_SERVER_LOCATION=$computer_ip" >>./wiiu-chat.local.env # Get the Wii U IP address printf "Enter your Wii U's IP address: " diff --git a/scripts/update-account-servers-database.sh b/scripts/update-account-servers-database.sh index 269fa62..8a6b670 100755 --- a/scripts/update-account-servers-database.sh +++ b/scripts/update-account-servers-database.sh @@ -1,10 +1,18 @@ #! /bin/sh set -eu + +null_aes_key="" +for _ in $(seq 1 64); do + null_aes_key="${null_aes_key}0" +done + git_base=$(git rev-parse --show-toplevel) . "$git_base/environment/system.local.env" . "$git_base/environment/friends.env" . "$git_base/environment/friends.local.env" +. "$git_base/environment/wiiu-chat.env" +. "$git_base/environment/wiiu-chat.local.env" docker compose up -d account @@ -13,4 +21,7 @@ docker compose exec account node /app/dist/create-server-in-database.js reset docker compose exec account node /app/dist/create-server-in-database.js nex \ "Friend List" "00003200" "0005001010001C00" "$COMPUTER_IP" \ "$PN_FRIENDS_AUTHENTICATION_SERVER_PORT" "prod" "$PN_FRIENDS_CONFIG_AES_KEY" - +# Wii U Chat server doesn't seem to care about the AES key +docker compose exec account node /app/dist/create-server-in-database.js nex \ + "Wii U Chat" "1005A000" "000500101005A100" "$COMPUTER_IP" \ + "$PN_WIIU_CHAT_AUTHENTICATION_SERVER_PORT" "prod" "$null_aes_key"