kinnay / NintendoClients

Python package to communicate with Switch, Wii U and 3DS servers
MIT License
558 stars 68 forks source link

How to get smm2 stage data. #18

Closed mariotroopa closed 4 years ago

mariotroopa commented 4 years ago

I want to get smm2 stage information, but there are no examples to get information from the server with switch platform.

I test example_mariokartdeluxe.py with login.

backend = backend.BackEndClient("switch.cfg")
backend.configure(SMM2.ACCESS_KEY, SMM2.NEX_VERSION, SMM2.CLIENT_VERSION)
backend.connect(HOST, PORT)
backend.login(USERNAME,auth_info=?)

and say nintendo.nex.common.RMCError: Authentication::ValidationFailed (0x80680007)

What do i need to do?

Thank you for your reply.

kinnay commented 4 years ago

Hi,

You have to provide a valid token in the AuthenticationInfo structure. If you don't send a token to the server or if the token is invalid the server returns Authentication::ValidationFailed. At the moment, a man-in-the-middle is the easiest way to obtain a token. Do you know how to do that?

You should look for the following request with your man-in-the-middle: https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com/1.0.0/application/token.

Once you have a token, you can set up the AuthenticationInfo as follows:

auth_info = authentication.AuthenticationInfo()
auth_info.token = TOKEN
auth_info.ngs_version = 4
auth_info.token_type = 2
auth_info.server_version = 0

The token is valid for three hours. When it's expired, you have to get a new token.

At some point, NintendoClients might be able to request a token itself. However, at the moment I'm still researching how exactly this is done by the Switch.

Anway, I hope this helps.

mariotroopa commented 4 years ago

Actually I'm not familiar with Nintendo APIs.

According to this Doc, I found session token , service token and webApiServerCredential["accesstoken"] (Authentication Steps 2,3,4) with Telerik Fiddler on iOS Swich Online App.

And I haven't found https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com/1.0.0/application/token on Switch Online App yet.

I'm sorry for your inconvenience.Thank you for your cooperation.

kinnay commented 4 years ago

The Switch Online App is unrelated to this. You have to set up a man-in-the-middle on your real Nintendo Switch console.

USERNAME is supposed to be your user id in decimal form. I think you can find it in https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com/1.0.0/login.

exefs_patches is probably the easiest way to set up a MITM on your Switch, but I can't really help you with it because I haven't used it myself yet.

kinnay commented 4 years ago

Actually, I think I was wrong about /1.0.0/application/token. I think you have to look at /1.0.0/login for the NEX token as well.

mariotroopa commented 4 years ago

I confirmed exefs_patches and it will not work alone. Need to generate Client Certificate from dumped data. CertNXtractionPack Set generated certificate to proxy's Client Certificate .

It was explained at simon'n discord. I try it,and report when results are available

mariotroopa commented 4 years ago

It seems that it will take more time to acquire tokens due to switch version upgrade, but it seems that I can create certificate and mitm with it. Actually, Original CertNXtranctionPackworked well with Charles Proxy(ver3.x.x).

One question is, how do you get a token if you are not using exefs_patches?

kinnay commented 4 years ago

I actually never got a token myself. Instead, I tested my client with the guest account when it still existed. The only way to get a token without mitm would be to request one with a custom client. However, I'm still trying to figure out how everything works (aauth is quite complicated).

kinnay commented 4 years ago

Hi again, I uploaded an example script that downloads a SMM2 level from the server. You'll have to dump a few things from your Switch to run it (keys, prodinfo and ticket files), but once you have the required files you won't have to touch your Switch anymore to use the script.