3DS: Try to fix connecting to multiplayer, and also try to fix can't validate classicube.net's SSL certificate

This commit is contained in:
UnknownShadow200 2023-08-17 22:42:18 +10:00
parent f32fcb1c00
commit 4314f1924e
2 changed files with 16 additions and 6 deletions

View File

@ -34,8 +34,8 @@
const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */ const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */
const cc_result ReturnCode_FileNotFound = ENOENT; const cc_result ReturnCode_FileNotFound = ENOENT;
const cc_result ReturnCode_SocketInProgess = -26; const cc_result ReturnCode_SocketInProgess = EINPROGRESS;
const cc_result ReturnCode_SocketWouldBlock = -6; const cc_result ReturnCode_SocketWouldBlock = EWOULDBLOCK;
const cc_result ReturnCode_DirectoryExists = EEXIST; const cc_result ReturnCode_DirectoryExists = EEXIST;
const char* Platform_AppNameSuffix = " 3DS"; const char* Platform_AppNameSuffix = " 3DS";
@ -392,12 +392,12 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) {
cc_result res = Socket_Poll(s, SOCKET_POLL_WRITE, writable); cc_result res = Socket_Poll(s, SOCKET_POLL_WRITE, writable);
if (res || *writable) return res; if (res || *writable) return res;
// Actual 3DS hardware returns EINPROGRESS if connect is still in progress // Actual 3DS hardware returns INPROGRESS error code if connect is still in progress
// Which is different from POSIX: // Which is different from POSIX:
// https://stackoverflow.com/questions/29479953/so-error-value-after-successful-socket-operation // https://stackoverflow.com/questions/29479953/so-error-value-after-successful-socket-operation
getsockopt(s, SOL_SOCKET, SO_ERROR, &res, &resultSize); getsockopt(s, SOL_SOCKET, SO_ERROR, &res, &resultSize);
Platform_Log1("--write poll failed-- = %i", &res); Platform_Log1("--write poll failed-- = %i", &res);
if (res == ReturnCode_SocketInProgess) res = 0; if (res == -26) res = 0;
return res; return res;
} }

View File

@ -420,13 +420,22 @@ cc_result SSL_Free(void* ctx_) {
#elif defined CC_BUILD_3DS #elif defined CC_BUILD_3DS
#include <3ds.h> #include <3ds.h>
#include "String.h" #include "String.h"
#define CERT_ATTRIBUTES
#include "../misc/RootCerts.h"
// https://github.com/devkitPro/3ds-examples/blob/master/network/sslc/source/ssl.c // https://github.com/devkitPro/3ds-examples/blob/master/network/sslc/source/ssl.c
// https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/services/sslc.h // https://github.com/devkitPro/libctru/blob/master/libctru/include/3ds/services/sslc.h
static u32 certChainHandle; static u32 certChainHandle, certContextHandle;
static cc_bool _verifyCerts; static cc_bool _verifyCerts;
static void SSL_CreateRootChain(void) { static void SSL_CreateRootChain(void) {
int ret = sslcCreateRootCertChain(&certChainHandle); int ret;
ret = sslcCreateRootCertChain(&certChainHandle);
if (ret) { Platform_Log1("sslcCreateRootCertChain failed: %i", &ret); return; } if (ret) { Platform_Log1("sslcCreateRootCertChain failed: %i", &ret); return; }
ret = sslcAddTrustedRootCA(certChainHandle, Baltimore_RootCert, Baltimore_RootCert_Size, &certContextHandle);
if (ret) { Platform_Log1("sslcAddTrustedRootCA failed: %i", &ret); return; }
} }
void SSLBackend_Init(cc_bool verifyCerts) { void SSLBackend_Init(cc_bool verifyCerts) {
@ -495,6 +504,7 @@ cc_result SSL_Free(void* ctx_) {
#define IOCTLV_SSL_WRITE 5 #define IOCTLV_SSL_WRITE 5
#define IOCTLV_SSL_SHUTDOWN 6 #define IOCTLV_SSL_SHUTDOWN 6
#define SSL_HEAP_SIZE 0xB000 #define SSL_HEAP_SIZE 0xB000
#define CERT_ATTRIBUTES ATTRIBUTE_ALIGN(32) #define CERT_ATTRIBUTES ATTRIBUTE_ALIGN(32)
//#include "../misc/RootCerts.h" //#include "../misc/RootCerts.h"