mirror of
https://github.com/barronwaffles/dwc_network_server_emulator.git
synced 2026-03-21 17:34:21 -05:00
Contains enough code to allow Tetris DS to get to the post-login wifi menu. This is very rough, basic code. I expect it to change quite a bit from its current format once I start adding more features. It's nowhere near ready for public use yet.
65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
from ctypes import c_uint
|
|
import sys
|
|
import base64
|
|
import hashlib
|
|
|
|
# GameSpy uses a slightly modified version of base64 which replaces +/= with []_
|
|
def base64_encode(input):
|
|
output = base64.b64encode(input).replace('+', '[').replace('/',']').replace('=','_')
|
|
return output
|
|
|
|
def base64_decode(input):
|
|
output = base64.b64decode(input.replace('[', '+').replace('/',']').replace('_','='))
|
|
return output
|
|
|
|
# Parse my custom authtoken generated by the emulated nas.nintendowifi.net/ac
|
|
def parse_authtoken(authtoken):
|
|
messages = {}
|
|
|
|
if authtoken[:3] == "NDS":
|
|
authtoken = authtoken[3:]
|
|
|
|
dec = base64.standard_b64decode(authtoken)
|
|
|
|
for item in dec.split('|'):
|
|
s = item.split('\\')
|
|
messages[s[0]] = s[1]
|
|
|
|
return messages
|
|
|
|
|
|
def generate_response(challenge, ac_challenge, secretkey, authtoken):
|
|
md5 = hashlib.md5()
|
|
md5.update(ac_challenge)
|
|
|
|
output = md5.hexdigest()
|
|
output += ' ' * 0x30
|
|
output += authtoken
|
|
output += secretkey
|
|
output += challenge
|
|
output += md5.hexdigest()
|
|
|
|
md5_2 = hashlib.md5()
|
|
md5_2.update(output)
|
|
|
|
return md5_2.hexdigest()
|
|
|
|
|
|
# The proof is practically the same thing as the response, except it has the challenge and the secret key swapped.
|
|
# Maybe combine the two functions later?
|
|
def generate_proof(challenge, ac_challenge, secretkey, authtoken):
|
|
md5 = hashlib.md5()
|
|
md5.update(ac_challenge)
|
|
|
|
output = md5.hexdigest()
|
|
output += ' ' * 0x30
|
|
output += authtoken
|
|
output += challenge
|
|
output += secretkey
|
|
output += md5.hexdigest()
|
|
|
|
md5_2 = hashlib.md5()
|
|
md5_2.update(output)
|
|
|
|
return md5_2.hexdigest()
|
|
|