diff --git a/misc/RootCerts.h b/misc/RootCerts.h new file mode 100644 index 000000000..b7253c6b1 --- /dev/null +++ b/misc/RootCerts.h @@ -0,0 +1,61 @@ +// DER encoded Baltimore CyberTrust root certificate +static const unsigned char Baltimore_RootCert[] CERT_ATTRIBUTES = { + 0x30, 0x82, 0x03, 0x77, 0x30, 0x82, 0x02, 0x5F, 0xA0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x04, 0x02, + 0x00, 0x00, 0xB9, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x05, + 0x05, 0x00, 0x30, 0x5A, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, + 0x45, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x09, 0x42, 0x61, 0x6C, 0x74, + 0x69, 0x6D, 0x6F, 0x72, 0x65, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x0A, + 0x43, 0x79, 0x62, 0x65, 0x72, 0x54, 0x72, 0x75, 0x73, 0x74, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, + 0x55, 0x04, 0x03, 0x13, 0x19, 0x42, 0x61, 0x6C, 0x74, 0x69, 0x6D, 0x6F, 0x72, 0x65, 0x20, 0x43, + 0x79, 0x62, 0x65, 0x72, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x30, 0x1E, + 0x17, 0x0D, 0x30, 0x30, 0x30, 0x35, 0x31, 0x32, 0x31, 0x38, 0x34, 0x36, 0x30, 0x30, 0x5A, 0x17, + 0x0D, 0x32, 0x35, 0x30, 0x35, 0x31, 0x32, 0x32, 0x33, 0x35, 0x39, 0x30, 0x30, 0x5A, 0x30, 0x5A, + 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, 0x45, 0x31, 0x12, 0x30, + 0x10, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x13, 0x09, 0x42, 0x61, 0x6C, 0x74, 0x69, 0x6D, 0x6F, 0x72, + 0x65, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x0A, 0x43, 0x79, 0x62, 0x65, + 0x72, 0x54, 0x72, 0x75, 0x73, 0x74, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x19, 0x42, 0x61, 0x6C, 0x74, 0x69, 0x6D, 0x6F, 0x72, 0x65, 0x20, 0x43, 0x79, 0x62, 0x65, 0x72, + 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0D, + 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, + 0x0F, 0x00, 0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xA3, 0x04, 0xBB, 0x22, 0xAB, + 0x98, 0x3D, 0x57, 0xE8, 0x26, 0x72, 0x9A, 0xB5, 0x79, 0xD4, 0x29, 0xE2, 0xE1, 0xE8, 0x95, 0x80, + 0xB1, 0xB0, 0xE3, 0x5B, 0x8E, 0x2B, 0x29, 0x9A, 0x64, 0xDF, 0xA1, 0x5D, 0xED, 0xB0, 0x09, 0x05, + 0x6D, 0xDB, 0x28, 0x2E, 0xCE, 0x62, 0xA2, 0x62, 0xFE, 0xB4, 0x88, 0xDA, 0x12, 0xEB, 0x38, 0xEB, + 0x21, 0x9D, 0xC0, 0x41, 0x2B, 0x01, 0x52, 0x7B, 0x88, 0x77, 0xD3, 0x1C, 0x8F, 0xC7, 0xBA, 0xB9, + 0x88, 0xB5, 0x6A, 0x09, 0xE7, 0x73, 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39, 0x02, 0x03, 0x01, 0x00, 0x01, + 0xA3, 0x45, 0x30, 0x43, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04, 0x14, 0xE5, + 0x9D, 0x59, 0x30, 0x82, 0x47, 0x58, 0xCC, 0xAC, 0xFA, 0x08, 0x54, 0x36, 0x86, 0x7B, 0x3A, 0xB5, + 0x04, 0x4D, 0xF0, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x01, 0x01, 0xFF, 0x04, 0x08, 0x30, + 0x06, 0x01, 0x01, 0xFF, 0x02, 0x01, 0x03, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x01, 0x01, + 0xFF, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, + 0x0D, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x85, 0x0C, 0x5D, 0x8E, 0xE4, + 0x6F, 0x51, 0x68, 0x42, 0x05, 0xA0, 0xDD, 0xBB, 0x4F, 0x27, 0x25, 0x84, 0x03, 0xBD, 0xF7, 0x64, + 0xFD, 0x2D, 0xD7, 0x30, 0xE3, 0xA4, 0x10, 0x17, 0xEB, 0xDA, 0x29, 0x29, 0xB6, 0x79, 0x3F, 0x76, + 0xF6, 0x19, 0x13, 0x23, 0xB8, 0x10, 0x0A, 0xF9, 0x58, 0xA4, 0xD4, 0x61, 0x70, 0xBD, 0x04, 0x61, + 0x6A, 0x12, 0x8A, 0x17, 0xD5, 0x0A, 0xBD, 0xC5, 0xBC, 0x30, 0x7C, 0xD6, 0xE9, 0x0C, 0x25, 0x8D, + 0x86, 0x40, 0x4F, 0xEC, 0xCC, 0xA3, 0x7E, 0x38, 0xC6, 0x37, 0x11, 0x4F, 0xED, 0xDD, 0x68, 0x31, + 0x8E, 0x4C, 0xD2, 0xB3, 0x01, 0x74, 0xEE, 0xBE, 0x75, 0x5E, 0x07, 0x48, 0x1A, 0x7F, 0x70, 0xFF, + 0x16, 0x5C, 0x84, 0xC0, 0x79, 0x85, 0xB8, 0x05, 0xFD, 0x7F, 0xBE, 0x65, 0x11, 0xA3, 0x0F, 0xC0, + 0x02, 0xB4, 0xF8, 0x52, 0x37, 0x39, 0x04, 0xD5, 0xA9, 0x31, 0x7A, 0x18, 0xBF, 0xA0, 0x2A, 0xF4, + 0x12, 0x99, 0xF7, 0xA3, 0x45, 0x82, 0xE3, 0x3C, 0x5E, 0xF5, 0x9D, 0x9E, 0xB5, 0xC8, 0x9E, 0x7C, + 0x2E, 0xC8, 0xA4, 0x9E, 0x4E, 0x08, 0x14, 0x4B, 0x6D, 0xFD, 0x70, 0x6D, 0x6B, 0x1A, 0x63, 0xBD, + 0x64, 0xE6, 0x1F, 0xB7, 0xCE, 0xF0, 0xF2, 0x9F, 0x2E, 0xBB, 0x1B, 0xB7, 0xF2, 0x50, 0x88, 0x73, + 0x92, 0xC2, 0xE2, 0xE3, 0x16, 0x8D, 0x9A, 0x32, 0x02, 0xAB, 0x8E, 0x18, 0xDD, 0xE9, 0x10, 0x11, + 0xEE, 0x7E, 0x35, 0xAB, 0x90, 0xAF, 0x3E, 0x30, 0x94, 0x7A, 0xD0, 0x33, 0x3D, 0xA7, 0x65, 0x0F, + 0xF5, 0xFC, 0x8E, 0x9E, 0x62, 0xCF, 0x47, 0x44, 0x2C, 0x01, 0x5D, 0xBB, 0x1D, 0xB5, 0x32, 0xD2, + 0x47, 0xD2, 0x38, 0x2E, 0xD0, 0xFE, 0x81, 0xDC, 0x32, 0x6A, 0x1E, 0xB5, 0xEE, 0x3C, 0xD5, 0xFC, + 0xE7, 0x81, 0x1D, 0x19, 0xC3, 0x24, 0x42, 0xEA, 0x63, 0x39, 0xA9, +}; +static const int Baltimore_RootCert_Size = sizeof(Baltimore_RootCert); + diff --git a/src/Formats.c b/src/Formats.c index 099bf534a..bc0504492 100644 --- a/src/Formats.c +++ b/src/Formats.c @@ -335,7 +335,7 @@ struct NbtTag { float f32; cc_uint8 small[NBT_SMALL_SIZE]; cc_uint8* big; /* malloc for big byte arrays */ - struct { cc_string text; char buffer[NBT_STRING_SIZE]; } str; + struct { cc_string text; char buffer[STRING_SIZE * 2]; } str; } value; char _nameBuffer[NBT_STRING_SIZE]; cc_result result; diff --git a/src/SSL.c b/src/SSL.c index 61a2fbb42..f6cb9c26d 100644 --- a/src/SSL.c +++ b/src/SSL.c @@ -487,6 +487,7 @@ cc_result SSL_Free(void* ctx_) { #include "Platform.h" #include "Logger.h" #include "String.h" + #define IOCTLV_SSL_NEW 1 #define IOCTLV_SSL_CONNECT 2 #define IOCTLV_SSL_HANDSHAKE 3 @@ -494,6 +495,9 @@ cc_result SSL_Free(void* ctx_) { #define IOCTLV_SSL_WRITE 5 #define IOCTLV_SSL_SHUTDOWN 6 #define SSL_HEAP_SIZE 0xB000 +#define CERT_ATTRIBUTES ATTRIBUTE_ALIGN(32) +//#include "../misc/RootCerts.h" + static char SSL_fs[] ATTRIBUTE_ALIGN(32) = "/dev/net/ssl"; static s32 SSL_fd = -1; static s32 SSL_hid = -1; @@ -504,58 +508,81 @@ void SSLBackend_Init(cc_bool verifyCerts) { if (SSL_hid < 0) Logger_Abort("Failed to create SSL heap"); } cc_bool SSLBackend_DescribeError(cc_result res, cc_string* dst) { return false; } + static u32 ssl_open(void) { s32 ret; if (SSL_fd >= 0) return 0; if (SSL_hid < 0) return ERR_OUT_OF_MEMORY; + ret = IOS_Open(SSL_fs, 0); if (ret < 0) return ret; SSL_fd = ret; return 0; } + static u32 ssl_close(void) { s32 ret; if (SSL_fd < 0) return 0; + ret = IOS_Close(SSL_fd); SSL_fd = -1; return ret; } static s32 ssl_new(const cc_string* host, u32 ssl_verify_options) { + static cc_string ccnet_cert_CN = String_FromConst("sni.cloudflaressl.com"); s32 ret; u8 aCN[1024] ATTRIBUTE_ALIGN(32); s32 aContext[8] ATTRIBUTE_ALIGN(32); u32 aVerify_options[8] ATTRIBUTE_ALIGN(32); - String_EncodeUtf8(aCN, host); + + // classicube.net's SSL certificate CN is actually "sni.cloudflaressl.com" + if (String_CaselessEqualsConst(host, "www.classicube.net")) { + String_EncodeUtf8(aCN, &ccnet_cert_CN); + } else { + String_EncodeUtf8(aCN, host); + } + if ((ret = ssl_open())) return ret; + aVerify_options[0] = ssl_verify_options; ret = IOS_IoctlvFormat(SSL_hid, SSL_fd, IOCTLV_SSL_NEW, "d:dd", aContext, 0x20, aVerify_options, 0x20, aCN, 0x100); ssl_close(); + return ret ? ret : aContext[0]; } + static s32 ssl_connect(s32 ssl_context, s32 socket) { s32 ret; s32 aSsl_context[8] ATTRIBUTE_ALIGN(32); s32 aSocket[8] ATTRIBUTE_ALIGN(32); s32 aResponse[8] ATTRIBUTE_ALIGN(32); + if ((ret = ssl_open())) return ret; + aSsl_context[0] = ssl_context; aSocket[0] = socket; - ret = IOS_IoctlvFormat(SSL_hid, SSL_fd, IOCTLV_SSL_CONNECT, "d:dd", aResponse, 0x20, aSsl_context, 0x20, aSocket, 0x20); + ret = IOS_IoctlvFormat(SSL_hid, SSL_fd, IOCTLV_SSL_CONNECT, "d:dd", aResponse, 0x20, aSsl_context, 0x20, aSocket, 0x20); ssl_close(); + return ret ? ret : aResponse[0]; } + static s32 ssl_handshake(s32 ssl_context) { s32 ret; s32 aSsl_context[8] ATTRIBUTE_ALIGN(32); s32 aResponse[8] ATTRIBUTE_ALIGN(32); + if ((ret = ssl_open())) return ret; + aSsl_context[0] = ssl_context; - ret = IOS_IoctlvFormat(SSL_hid, SSL_fd, IOCTLV_SSL_HANDSHAKE, "d:d", aResponse, 0x20, aSsl_context, 0x20); + ret = IOS_IoctlvFormat(SSL_hid, SSL_fd, IOCTLV_SSL_HANDSHAKE, "d:d", aResponse, 0x20, aSsl_context, 0x20); ssl_close(); + return ret ? ret : aResponse[0]; } + cc_result SSL_Init(cc_socket socket, const cc_string* host, void** ctx) { int sslCtx, ret; @@ -579,12 +606,14 @@ cc_result SSL_Read(void* ctx, cc_uint8* data, cc_uint32 count, cc_uint32* read) s32 aSsl_context[8] ATTRIBUTE_ALIGN(32); s32 aResponse[8] ATTRIBUTE_ALIGN(32); if ((ret = ssl_open())) return ret; + u8* aBuffer = NULL; aBuffer = iosAlloc(SSL_hid, count); if (!aBuffer) return IPC_ENOMEM; aSsl_context[0] = sslCtx; ret = IOS_IoctlvFormat(SSL_hid, SSL_fd, IOCTLV_SSL_READ, "dd:d", aResponse, 0x20, aBuffer, count, aSsl_context, 0x20); ssl_close(); + if (ret == IPC_OK) { Mem_Copy(data, aBuffer, aResponse[0]); } @@ -592,6 +621,7 @@ cc_result SSL_Read(void* ctx, cc_uint8* data, cc_uint32 count, cc_uint32* read) iosFree(SSL_hid, aBuffer); return ret; } + cc_result SSL_Write(void* ctx, const cc_uint8* data, cc_uint32 count, cc_uint32* wrote) { int sslCtx = *(int*)ctx; *wrote = 0; @@ -600,6 +630,7 @@ cc_result SSL_Write(void* ctx, const cc_uint8* data, cc_uint32 count, cc_uint32* s32 aSsl_context[8] ATTRIBUTE_ALIGN(32); s32 aResponse[8] ATTRIBUTE_ALIGN(32); if ((ret = ssl_open())) return ret; + u8* aBuffer = NULL; aBuffer = iosAlloc(SSL_hid, count); if (!aBuffer) return IPC_ENOMEM; @@ -612,15 +643,19 @@ cc_result SSL_Write(void* ctx, const cc_uint8* data, cc_uint32 count, cc_uint32* iosFree(SSL_hid, aBuffer); return ret; } + cc_result SSL_Free(void* ctx) { int sslCtx = *(int*)ctx; - s32 ret; + s32 ret; + s32 aSsl_context[8] ATTRIBUTE_ALIGN(32); s32 aResponse[8] ATTRIBUTE_ALIGN(32); if ((ret = ssl_open())) return ret; + aSsl_context[0] = sslCtx; ret = IOS_IoctlvFormat(SSL_hid, SSL_fd, IOCTLV_SSL_SHUTDOWN, "d:d", aResponse, 0x20, aSsl_context, 0x20); ssl_close(); + return ret; } #else diff --git a/src/Window_GCWii.c b/src/Window_GCWii.c index bdc33f6d1..20141d7dc 100644 --- a/src/Window_GCWii.c +++ b/src/Window_GCWii.c @@ -222,8 +222,6 @@ static void ProcessKeyboardInput(void) { { key = MapNativeKey(ke.keycode); if (key) Input_SetReleased(key); - //Platform_Log2("KEYCODE: %i (%i)", &ke.keycode, &ke.type); - if (ke.symbol) Event_RaiseInt(&InputEvents.Press, ke.symbol); } } #endif