From 388b9daac475c5612096fbfd331b971a1e76d6d5 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 26 Sep 2023 22:08:05 +1000 Subject: [PATCH] Configure BearSSL to always rely on ClassiCube's platform function to retrieve the current time --- readme.md | 2 ++ src/SSL.c | 17 +++++++++++++++-- src/Window_Dreamcast.c | 2 +- third_party/bearssl/src/inner.h | 18 ------------------ 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/readme.md b/readme.md index 97cf71246..6989f2db9 100644 --- a/readme.md +++ b/readme.md @@ -85,6 +85,8 @@ ClassiCube runs on:
  • PS Vita - unfinished, rendering issues
  • Xbox - unfinished, major rendering issues
  • PS3 - doesn't render properly yet
  • + + # Compiling diff --git a/src/SSL.c b/src/SSL.c index d8e89d402..13b714496 100644 --- a/src/SSL.c +++ b/src/SSL.c @@ -456,8 +456,8 @@ cc_bool SSLBackend_DescribeError(cc_result res, cc_string* dst) { #include <3ds.h> static void InjectEntropy(SSLContext* ctx) { char buf[32]; - int res = PS_GenerateRandomBytes(buf, 32); - if (res == 0) return; // NOTE: Not implemented in Citra + PS_GenerateRandomBytes(buf, 32); + // NOTE: PS_GenerateRandomBytes isn't implemented in Citra br_ssl_engine_inject_entropy(&ctx->sc.eng, buf, 32); } @@ -485,6 +485,18 @@ static void InjectEntropy(SSLContext* ctx) { #else static void InjectEntropy(SSLContext* ctx) { } #endif +static void SetCurrentTime(SSLContext* ctx) { + cc_uint64 cur = DateTime_CurrentUTC_MS() / 1000; + uint32_t days = (uint32_t)(cur / 86400) + 366; + uint32_t secs = (uint32_t)(cur % 86400); + + br_x509_minimal_set_time(&ctx->xc, days, secs); + /* This matches bearssl's default time calculation + time_t x = time(NULL); + vd = (uint32_t)(x / 86400) + 719528; + vs = (uint32_t)(x % 86400); + */ +} static int sock_read(void* ctx_, unsigned char* buf, size_t len) { SSLContext* ctx = (SSLContext*)ctx_; @@ -519,6 +531,7 @@ cc_result SSL_Init(cc_socket socket, const cc_string* host_, void** out_ctx) { br_x509_minimal_set_ecdsa(&ctx->xc, &br_ec_prime_i31, &br_ecdsa_i31_vrfy_asn1); }*/ InjectEntropy(ctx); + SetCurrentTime(ctx); ctx->socket = socket; br_ssl_engine_set_buffer(&ctx->sc.eng, ctx->iobuf, sizeof(ctx->iobuf), 1); diff --git a/src/Window_Dreamcast.c b/src/Window_Dreamcast.c index 35ad02573..3c7b904ed 100644 --- a/src/Window_Dreamcast.c +++ b/src/Window_Dreamcast.c @@ -36,7 +36,7 @@ void Window_Init(void) { void Window_Create2D(int width, int height) { launcherMode = true; - vid_set_mode(DEFAULT_VID_MODE, PM_RGB0888); + vid_set_mode(DEFAULT_VID_MODE, PM_RGB888); vid_flip(0); } diff --git a/third_party/bearssl/src/inner.h b/third_party/bearssl/src/inner.h index 07e1d0a47..0d408257e 100644 --- a/third_party/bearssl/src/inner.h +++ b/third_party/bearssl/src/inner.h @@ -432,24 +432,6 @@ #endif -/* - * Detect support for an OS-provided time source. - */ - -#ifndef BR_USE_UNIX_TIME -#if defined __unix__ || defined __linux__ \ - || defined _POSIX_SOURCE || defined _POSIX_C_SOURCE \ - || (defined __APPLE__ && defined __MACH__) -#define BR_USE_UNIX_TIME 1 -#endif -#endif - -#ifndef BR_USE_WIN32_TIME -#if defined _WIN32 || defined _WIN64 -#define BR_USE_WIN32_TIME 1 -#endif -#endif - /* ==================================================================== */ /* * Encoding/decoding functions.