Make it easier to switch SSL backends

This commit is contained in:
UnknownShadow200 2024-07-31 18:06:32 +10:00
parent b95abff3f0
commit 6da3ab1354
3 changed files with 36 additions and 16 deletions

View file

@ -141,6 +141,10 @@ typedef cc_uint8 cc_bool;
#define CC_GFX_BACKEND_D3D11 5 #define CC_GFX_BACKEND_D3D11 5
#define CC_GFX_BACKEND_VULKAN 6 #define CC_GFX_BACKEND_VULKAN 6
#define CC_SSL_BACKEND_NONE 1
#define CC_SSL_BACKEND_BEARSSL 2
#define CC_SSL_BACKEND_SCHANNEL 3
#define CC_GFX_BACKEND_IS_GL() (CC_GFX_BACKEND == CC_GFX_BACKEND_GL1 || CC_GFX_BACKEND == CC_GFX_BACKEND_GL2) #define CC_GFX_BACKEND_IS_GL() (CC_GFX_BACKEND == CC_GFX_BACKEND_GL1 || CC_GFX_BACKEND == CC_GFX_BACKEND_GL2)
#define CC_BUILD_NETWORKING #define CC_BUILD_NETWORKING
@ -162,8 +166,8 @@ typedef cc_uint8 cc_bool;
#define CC_BUILD_NOMUSIC #define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS #define CC_BUILD_NOSOUNDS
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN #define CC_BUILD_SPLITSCREEN
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined XENON #elif defined XENON
/* libxenon also defines __linux__ (yes, really) */ /* libxenon also defines __linux__ (yes, really) */
#define CC_BUILD_XBOX360 #define CC_BUILD_XBOX360
@ -172,11 +176,12 @@ typedef cc_uint8 cc_bool;
#define CC_BUILD_NOMUSIC #define CC_BUILD_NOMUSIC
#define CC_BUILD_NOSOUNDS #define CC_BUILD_NOSOUNDS
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined _WIN32 #elif defined _WIN32
#define CC_BUILD_WIN #define CC_BUILD_WIN
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_SCHANNEL
#define CC_BUILD_WINMM #define CC_BUILD_WINMM
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_SCHANNEL
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_D3D9 #define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_D3D9
#define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_WIN32 #define DEFAULT_WIN_BACKEND CC_WIN_BACKEND_WIN32
#elif defined __ANDROID__ #elif defined __ANDROID__
@ -315,15 +320,15 @@ typedef cc_uint8 cc_bool;
#define CC_BUILD_COOPTHREADED #define CC_BUILD_COOPTHREADED
#define CC_BUILD_OPENAL #define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL #define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined __3DS__ #elif defined __3DS__
#define CC_BUILD_3DS #define CC_BUILD_3DS
#define CC_BUILD_CONSOLE #define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM #define CC_BUILD_LOWMEM
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_TOUCH #define CC_BUILD_TOUCH
#define CC_BUILD_DUALSCREEN #define CC_BUILD_DUALSCREEN
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined GEKKO #elif defined GEKKO
#define CC_BUILD_GCWII #define CC_BUILD_GCWII
#define CC_BUILD_CONSOLE #define CC_BUILD_CONSOLE
@ -332,31 +337,31 @@ typedef cc_uint8 cc_bool;
#endif #endif
#define CC_BUILD_COOPTHREADED #define CC_BUILD_COOPTHREADED
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN #define CC_BUILD_SPLITSCREEN
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined __vita__ #elif defined __vita__
#define CC_BUILD_PSVITA #define CC_BUILD_PSVITA
#define CC_BUILD_CONSOLE #define CC_BUILD_CONSOLE
#define CC_BUILD_OPENAL #define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_TOUCH #define CC_BUILD_TOUCH
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined _arch_dreamcast #elif defined _arch_dreamcast
#define CC_BUILD_DREAMCAST #define CC_BUILD_DREAMCAST
#define CC_BUILD_CONSOLE #define CC_BUILD_CONSOLE
#define CC_BUILD_LOWMEM #define CC_BUILD_LOWMEM
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN #define CC_BUILD_SPLITSCREEN
#define CC_BUILD_SMALLSTACK #define CC_BUILD_SMALLSTACK
#undef CC_BUILD_RESOURCES #undef CC_BUILD_RESOURCES
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined PLAT_PS3 #elif defined PLAT_PS3
#define CC_BUILD_PS3 #define CC_BUILD_PS3
#define CC_BUILD_CONSOLE #define CC_BUILD_CONSOLE
#define CC_BUILD_OPENAL #define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN #define CC_BUILD_SPLITSCREEN
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined N64 #elif defined N64
#define CC_BIG_ENDIAN #define CC_BIG_ENDIAN
#define CC_BUILD_N64 #define CC_BUILD_N64
@ -376,8 +381,8 @@ typedef cc_uint8 cc_bool;
#define CC_BUILD_COOPTHREADED #define CC_BUILD_COOPTHREADED
#define CC_BUILD_OPENAL #define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN #define CC_BUILD_SPLITSCREEN
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined PLAT_NDS #elif defined PLAT_NDS
#define CC_BUILD_NDS #define CC_BUILD_NDS
#define CC_BUILD_CONSOLE #define CC_BUILD_CONSOLE
@ -396,18 +401,18 @@ typedef cc_uint8 cc_bool;
#define CC_BUILD_COOPTHREADED #define CC_BUILD_COOPTHREADED
#define CC_BUILD_OPENAL #define CC_BUILD_OPENAL
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_SPLITSCREEN #define CC_BUILD_SPLITSCREEN
#define CC_BUILD_TOUCH #define CC_BUILD_TOUCH
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined __SWITCH__ #elif defined __SWITCH__
#define CC_BUILD_SWITCH #define CC_BUILD_SWITCH
#define CC_BUILD_CONSOLE #define CC_BUILD_CONSOLE
#define CC_BUILD_HTTPCLIENT #define CC_BUILD_HTTPCLIENT
#define CC_BUILD_BEARSSL
#define CC_BUILD_TOUCH #define CC_BUILD_TOUCH
#define CC_BUILD_GLES #define CC_BUILD_GLES
#define CC_BUILD_EGL #define CC_BUILD_EGL
#define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL2 #define DEFAULT_GFX_BACKEND CC_GFX_BACKEND_GL2
#define DEFAULT_SSL_BACKEND CC_SSL_BACKEND_BEARSSL
#elif defined PLAT_PS1 #elif defined PLAT_PS1
#define CC_BUILD_PS1 #define CC_BUILD_PS1
#define CC_BUILD_CONSOLE #define CC_BUILD_CONSOLE
@ -455,6 +460,9 @@ typedef cc_uint8 cc_bool;
#if defined DEFAULT_GFX_BACKEND && !defined CC_GFX_BACKEND #if defined DEFAULT_GFX_BACKEND && !defined CC_GFX_BACKEND
#define CC_GFX_BACKEND DEFAULT_GFX_BACKEND #define CC_GFX_BACKEND DEFAULT_GFX_BACKEND
#endif #endif
#if defined DEFAULT_SSL_BACKEND && !defined CC_SSL_BACKEND
#define CC_SSL_BACKEND DEFAULT_SSL_BACKEND
#endif
#ifdef CC_BUILD_CONSOLE #ifdef CC_BUILD_CONSOLE
#undef CC_BUILD_FREETYPE #undef CC_BUILD_FREETYPE

View file

@ -136,6 +136,14 @@ void Platform_Log(const char* msg, int len) {
OutputDebugStringA("\n"); OutputDebugStringA("\n");
} }
static VOID (WINAPI *_GetSystemTimeAsFileTime)(LPFILETIME sysTime);
/* Fallback support for NT 3.5 */
static VOID WINAPI Fallback_GetSystemTimeAsFileTime(LPFILETIME sysTime) {
SYSTEMTIME curTime;
GetSystemTime(&curTime);
SystemTimeToFileTime(&curTime, sysTime);
}
#define FILETIME_EPOCH 50491123200ULL #define FILETIME_EPOCH 50491123200ULL
#define FILETIME_UNIX_EPOCH 11644473600ULL #define FILETIME_UNIX_EPOCH 11644473600ULL
#define FileTime_TotalSecs(time) ((time / 10000000) + FILETIME_EPOCH) #define FileTime_TotalSecs(time) ((time / 10000000) + FILETIME_EPOCH)
@ -144,7 +152,7 @@ TimeMS DateTime_CurrentUTC(void) {
FILETIME ft; FILETIME ft;
cc_uint64 raw; cc_uint64 raw;
GetSystemTimeAsFileTime(&ft); _GetSystemTimeAsFileTime(&ft);
/* in 100 nanosecond units, since Jan 1 1601 */ /* in 100 nanosecond units, since Jan 1 1601 */
raw = ft.dwLowDateTime | ((cc_uint64)ft.dwHighDateTime << 32); raw = ft.dwLowDateTime | ((cc_uint64)ft.dwHighDateTime << 32);
return FileTime_TotalSecs(raw); return FileTime_TotalSecs(raw);
@ -171,7 +179,7 @@ cc_uint64 Stopwatch_Measure(void) {
QueryPerformanceCounter(&t); QueryPerformanceCounter(&t);
return (cc_uint64)t.QuadPart; return (cc_uint64)t.QuadPart;
} else { } else {
GetSystemTimeAsFileTime(&ft); _GetSystemTimeAsFileTime(&ft);
return (cc_uint64)ft.dwLowDateTime | ((cc_uint64)ft.dwHighDateTime << 32); return (cc_uint64)ft.dwLowDateTime | ((cc_uint64)ft.dwHighDateTime << 32);
} }
} }
@ -964,12 +972,15 @@ static BOOL (WINAPI *_IsDebuggerPresent)(void);
static void LoadKernelFuncs(void) { static void LoadKernelFuncs(void) {
static const struct DynamicLibSym funcs[] = { static const struct DynamicLibSym funcs[] = {
DynamicLib_Sym(AttachConsole), DynamicLib_Sym(IsDebuggerPresent) DynamicLib_Sym(AttachConsole), DynamicLib_Sym(IsDebuggerPresent),
DynamicLib_Sym(GetSystemTimeAsFileTime),
}; };
static const cc_string kernel32 = String_FromConst("KERNEL32.DLL"); static const cc_string kernel32 = String_FromConst("KERNEL32.DLL");
void* lib; void* lib;
DynamicLib_LoadAll(&kernel32, funcs, Array_Elems(funcs), &lib); DynamicLib_LoadAll(&kernel32, funcs, Array_Elems(funcs), &lib);
/* Not present on Windows NT 3.5 */
if (!_GetSystemTimeAsFileTime) _GetSystemTimeAsFileTime = Fallback_GetSystemTimeAsFileTime;
} }
void Platform_Init(void) { void Platform_Init(void) {
@ -1046,6 +1057,7 @@ cc_result Platform_Encrypt(const void* data, int len, cc_string* dst) {
LocalFree(output.pbData); LocalFree(output.pbData);
return 0; return 0;
} }
cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) { cc_result Platform_Decrypt(const void* data, int len, cc_string* dst) {
DATA_BLOB input, output; DATA_BLOB input, output;
int i; int i;

View file

@ -1,7 +1,7 @@
#include "SSL.h" #include "SSL.h"
#include "Errors.h" #include "Errors.h"
#if defined CC_BUILD_SCHANNEL #if CC_SSL_BACKEND == CC_SSL_BACKEND_SCHANNEL
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOSERVICE #define NOSERVICE
#define NOMCX #define NOMCX
@ -404,7 +404,7 @@ cc_result SSL_Free(void* ctx_) {
Mem_Free(ctx); Mem_Free(ctx);
return 0; return 0;
} }
#elif defined CC_BUILD_BEARSSL #elif CC_SSL_BACKEND == CC_SSL_BACKEND_BEARSSL
#include "String.h" #include "String.h"
#include "bearssl.h" #include "bearssl.h"
#include "../misc/certs/certs.h" #include "../misc/certs/certs.h"