└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # nds-constrain't 2 | **Because Nintendo can't do SSL properly** 3 | 4 | ## Testing Server 5 | **tl;dr: If you only want to join the test server**, then you can use the following DNS settings: 6 | - Primary DNS: 178.62.43.212 7 | - Secondary DNS: 1.1.1.1 or 8.8.8.8 8 | 9 | ## What is this? 10 | A way to sign SSL certificates such that the Nitro/TWL SDK's SSL library will treat as valid, without Nintendo's CA keys 11 | 12 | ## Background information 13 | On Nintendo's consoles, online communications are carried out over various protocols but the predominant of these is HTTPS - HTTP carried within encrypted SSL packets. 14 | After some initial unencrypted handshake steps in which the two parties exchange version information and capabilities, SSL servers will present an SSL certificate to the client containing the server's public key. 15 | The client uses the server's public key to encrypt a shared secret that the server will decrypt with its private key. This secret is used to protect a further key exchange step (e.g. Diffie-Hellman, although this can vary depending on the capabilities of each party) which will establish a new shared secret to be used to encrypt all further communications. 16 | Since SSL is a recognised web standard it is fairly simple for anyone competent to setup a compatible server - however, SSL certificates (and indeed X509 certificates in general) are almost always signed by a certifying authority so that the client knows it can trust the server it's connecting to. 17 | Unfortunately for us, the Nintendo SDK will refuse to connect to any server without a certificate signed by a trusted Nintendo CA, and Nintendo are of course not going to simply sign certificates for custom server authors to emulate theirs, leaving us unable to do anything without code patches... in theory. 18 | 19 | ## The flaw 20 | SSL certificate authorities can choose to add a flag to certificates they sign to state that this certificate is allowed to act as an intermediate CA too - that is, it can sign certificates. If the SSL server includes the intermediate CA's certificate with its own signed by that same intermediate, the client can follow the chain of trust back up to the root and will therefore accept the certificate. 21 | This, however, is where Nintendo's fatal flaw lies: in their implementation, they do not check if the intermediate certificate is supposed to sign other certs or not (indicated by a flag in the certificate's _basicConstraints_ section - `CA:TRUE` or `CA:FALSE`, as appropriate - leading to the name we gave this flaw), and as such if one has _any_ certificate signed by Nintendo with its accompanying private key, they can use it as an intermediate CA to sign their own certificates. 22 | 23 | **And as it happens, we do.** 24 | 25 | Nintendo consoles from the Wii onwards include a Nintendo-signed _client certificate_ which it uses to authenticate with Nintendo servers, as well as the accompanying private key for it. This client certificate is signed by the same CA as Nintendo's server certificates and as such is trusted by the DS. 26 | 27 | **TL;DR: client certs can sign certs and the DS doesn't care!** 28 | 29 | ## Instructions 30 | ### Requirements 31 | - The Wii's client certificate and its corresponding private key (these are not console-unique and can be pulled from any Wii, a guide will come soon.) 32 | - A server which supports SSLv3 (may be somewhat difficult to set up as support for SSLv3 has been disabled/removed in most modern servers for security reasons... but it's all the DS supports) 33 | - OpenSSL, to sign the certificates (or other suitable tool) 34 | 35 | ### Generating trusted certificates 36 | ```bash 37 | # Generate a 1024-bit private key for your server cert (weak, but it's a DS) 38 | openssl genrsa -out server.key 1024 39 | # Generate a certificate request 40 | openssl req -new -key server.key -out server.csr 41 | # Produce a signed server certificate from the certificate request, signed with the Wii's client certificate. 42 | # The SHA-1 digest algorithm must be used because we're working with old tech here, but you can customise the validity period as you see fit. Here, we specify 10 years. 43 | openssl x509 -req -in server.csr -CA nwc.crt -CAkey nwc.key -CAcreateserial -out server.crt -days 3650 -sha1 44 | ``` 45 | 46 | Copy the server.key and server.crt files to the correct places, and then configure your server to use them. 47 | You must also send `nwc.crt` to the client as part of the certificate chain, otherwise the DS will not be able to follow the chain of trust back up to the root and reject your lovely certificate - just concatenate your server certificate with `nwc.crt` like so: `cat server.crt nwc.crt > server.chain.crt`. 48 | 49 | Alternatively, with Apache, you can add `SSLCertificateChainFile /path/to/nwc.crt` to your server config. 50 | 51 | Example configuration: 52 | ```apache 53 | 54 | 55 | DocumentRoot /var/www/html 56 | ServerName nas.nintendowifi.net 57 | 58 | SSLEngine on 59 | SSLCertificateFile /path/to/server.crt 60 | SSLCertificateKeyFile /path/to/server.key 61 | SSLCertificateChainFile /path/to/nwc.crt 62 | 63 | 64 | ``` 65 | --------------------------------------------------------------------------------