Update moonlight-common-c and enable MbedTLS backend

This commit is contained in:
Cameron Gutman 2021-05-24 19:54:17 -05:00
parent 4bc5beb704
commit 84a033425a
7 changed files with 13 additions and 191 deletions

View file

@ -75,7 +75,7 @@ M_INCLUDES := \
-I$(TOPDIR)/third_party/nanogui/ext/nanovg/src
DEFINES := -DNANOGUI_USE_OPENGL -DNVG_STB_IMAGE_IMPLEMENTATION -DNANOGUI_NO_GLFW \
-DHAS_SOCKLEN_T -DHAS_POLL -DHAS_FCNTL -DUSE_MBEDTLS_CRYPTO -DMOONLIGHT_VERSION=\"$(MOONLIGHT_VERSION)\"
-DHAS_SOCKLEN_T -DHAS_POLL -DHAS_FCNTL -DUSE_MBEDTLS -DMOONLIGHT_VERSION=\"$(MOONLIGHT_VERSION)\"
CFLAGS := -g -Wall -fcompare-debug-second -O2 -ffunction-sections $(ARCH) $(DEFINES) $(INCLUDE) $(M_INCLUDES) -D__SWITCH__
CXXFLAGS := $(CFLAGS) -std=gnu++17
@ -117,7 +117,6 @@ MOONLIGHT_LIBRETRO_CXX_SOURCES = \
GLVideoRenderer.cpp \
Data.cpp \
MbedTLSCryptoManager.cpp \
mbedtls_to_openssl_wrapper.cpp \
AudrenAudioRenderer.cpp \
BoxArtManager.cpp \
Logger.cpp \
@ -151,6 +150,7 @@ MOONLIGHT_COMMON_C_SOURCES = \
LinkedBlockingQueue.c \
Misc.c \
Platform.c \
PlatformCrypto.c \
PlatformSockets.c \
RtpFecQueue.c \
RtpReorderQueue.c \

View file

@ -124,7 +124,7 @@
36E63790247010C70032F5FB /* Data.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 36E6378E247010C70032F5FB /* Data.cpp */; };
36EB490F249927C60059EDB7 /* Alert.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 36EB490D249927C60059EDB7 /* Alert.cpp */; };
36EB491324993A4C0059EDB7 /* WakeOnLanManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 36EB491124993A4C0059EDB7 /* WakeOnLanManager.cpp */; };
36F16475247473A300D70AD9 /* mbedtls_to_openssl_wrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 36F16474247473A300D70AD9 /* mbedtls_to_openssl_wrapper.cpp */; };
9801E576265C7F7000990C41 /* PlatformCrypto.c in Sources */ = {isa = PBXBuildFile; fileRef = 9801E575265C7F7000990C41 /* PlatformCrypto.c */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@ -363,11 +363,10 @@
36EB491124993A4C0059EDB7 /* WakeOnLanManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WakeOnLanManager.cpp; sourceTree = "<group>"; };
36EB491224993A4C0059EDB7 /* WakeOnLanManager.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = WakeOnLanManager.hpp; sourceTree = "<group>"; };
36F1646F2474736E00D70AD9 /* switch_wrapper.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = switch_wrapper.c; sourceTree = "<group>"; };
36F164712474736E00D70AD9 /* evp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = evp.h; sourceTree = "<group>"; };
36F164722474736E00D70AD9 /* rand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rand.h; sourceTree = "<group>"; };
36F16474247473A300D70AD9 /* mbedtls_to_openssl_wrapper.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = mbedtls_to_openssl_wrapper.cpp; sourceTree = "<group>"; };
36F16476247481F200D70AD9 /* AudrenAudioRenderer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = AudrenAudioRenderer.cpp; sourceTree = "<group>"; };
36F16477247481F200D70AD9 /* AudrenAudioRenderer.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = AudrenAudioRenderer.hpp; sourceTree = "<group>"; };
9801E575265C7F7000990C41 /* PlatformCrypto.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = PlatformCrypto.c; sourceTree = "<group>"; };
9801E577265C7F7E00990C41 /* PlatformCrypto.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCrypto.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -663,6 +662,8 @@
3652F046245C292B001FABF3 /* src */ = {
isa = PBXGroup;
children = (
9801E577265C7F7E00990C41 /* PlatformCrypto.h */,
9801E575265C7F7000990C41 /* PlatformCrypto.c */,
3652F04E245C292B001FABF3 /* Limelight.h */,
3652F047245C292B001FABF3 /* PlatformThreads.h */,
3652F048245C292B001FABF3 /* Input.h */,
@ -876,22 +877,11 @@
36F1646E2474736E00D70AD9 /* switch */ = {
isa = PBXGroup;
children = (
36F164702474736E00D70AD9 /* openssl */,
36F1646F2474736E00D70AD9 /* switch_wrapper.c */,
36F16474247473A300D70AD9 /* mbedtls_to_openssl_wrapper.cpp */,
);
path = switch;
sourceTree = "<group>";
};
36F164702474736E00D70AD9 /* openssl */ = {
isa = PBXGroup;
children = (
36F164712474736E00D70AD9 /* evp.h */,
36F164722474736E00D70AD9 /* rand.h */,
);
path = openssl;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -993,6 +983,7 @@
buildActionMask = 2147483647;
files = (
3652F075245C292B001FABF3 /* VideoStream.c in Sources */,
9801E576265C7F7000990C41 /* PlatformCrypto.c in Sources */,
3652EFE0245B3B00001FABF3 /* imageview.cpp in Sources */,
3652EFDB245B3B00001FABF3 /* texture.cpp in Sources */,
36A0C03D2461F03C0083289C /* Settings.cpp in Sources */,
@ -1062,7 +1053,6 @@
3652F077245C292B001FABF3 /* VideoDepacketizer.c in Sources */,
362041A225D94D7700D21EE3 /* StreamControlsController.cpp in Sources */,
3652EFF1245B3B00001FABF3 /* messagedialog.cpp in Sources */,
36F16475247473A300D70AD9 /* mbedtls_to_openssl_wrapper.cpp in Sources */,
3652F06F245C292B001FABF3 /* ControlStream.c in Sources */,
3652EFD6245B3B00001FABF3 /* window.cpp in Sources */,
3652F071245C292B001FABF3 /* InputStream.c in Sources */,
@ -1189,7 +1179,7 @@
"-DHAS_POLL",
"-DHAS_FCNTL",
"-DHAVE_PULSE",
"-DUSE_MBEDTLS_CRYPTO",
"-DUSE_MBEDTLS",
"-DMOONLIGHT_VERSION=\\\"1.1.0\\\"",
);
OTHER_LDFLAGS = (
@ -1280,7 +1270,7 @@
"-DHAS_POLL",
"-DHAS_FCNTL",
"-DHAVE_PULSE",
"-DUSE_MBEDTLS_CRYPTO",
"-DUSE_MBEDTLS",
"-DMOONLIGHT_VERSION=\\\"1.1.0\\\"",
);
OTHER_LDFLAGS = (

View file

@ -1,12 +1,12 @@
#include <stdio.h>
#pragma once
#if defined(USE_OPENSSL_CRYPTO)
#if defined(USE_OPENSSL)
#include "OpenSSLCryptoManager.hpp"
#define CryptoManager OpenSSLCryptoManager
#elif defined(USE_MBEDTLS_CRYPTO)
#elif defined(USE_MBEDTLS)
#include "MbedTLSCryptoManager.hpp"
#define CryptoManager MbedTLSCryptoManager

View file

@ -1,121 +0,0 @@
#include <openssl/rand.h>
#include <openssl/evp.h>
#include <mbedtls/gcm.h>
#include <cstdlib>
#include "Data.hpp"
struct MBED_CIPHER_CTX {
mbedtls_gcm_context ctx;
int iv_len;
const unsigned char *iv;
unsigned char* tag;
};
const EVP_CIPHER *EVP_aes_128_gcm(void) {
return NULL;
}
const EVP_CIPHER *EVP_aes_128_cbc(void) {
return NULL;
}
void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) {
if (ctx) {
mbedtls_gcm_init(&ctx->ctx);
ctx->iv_len = 0;
ctx->iv = NULL;
ctx->tag = NULL;
}
}
int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx) {
if (ctx) {
mbedtls_gcm_free(&ctx->ctx);
if (ctx->tag) {
free(ctx->tag);
ctx->tag = NULL;
}
}
return 1;
}
EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) {
EVP_CIPHER_CTX* ctx = (EVP_CIPHER_CTX *)malloc(sizeof(EVP_CIPHER_CTX));
EVP_CIPHER_CTX_init(ctx);
return ctx;
}
void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) {
if (ctx && ctx->tag) {
free(ctx->tag);
}
}
int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr) {
if (ctx && type == EVP_CTRL_GCM_SET_IVLEN) {
ctx->iv_len = arg;
} else if (ctx && type == EVP_CTRL_GCM_GET_TAG) {
unsigned char *tag = (unsigned char*)ptr;
for (int i = 0; i < arg; i++) {
tag[i] = ctx->tag[i];
}
}
return 1;
}
int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv) {
if (ctx && key != NULL && iv != NULL) {
mbedtls_gcm_setkey(&ctx->ctx, MBEDTLS_CIPHER_ID_AES, key, ctx->iv_len * 8);
mbedtls_gcm_starts(&ctx->ctx, MBEDTLS_GCM_ENCRYPT, iv, ctx->iv_len, NULL, 0);
ctx->iv = iv;
}
return 1;
}
int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl) {
if (ctx) {
ctx->tag = (unsigned char*)malloc(ctx->iv_len);
mbedtls_gcm_crypt_and_tag(&ctx->ctx, MBEDTLS_GCM_ENCRYPT, inl, ctx->iv, ctx->iv_len, NULL, 0, in, out, ctx->iv_len, ctx->tag);
*outl = inl;
}
return 1;
}
int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) {
return 1;
}
// TODO: This is correct?
int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv) {
if (ctx && key != NULL && iv != NULL) {
mbedtls_gcm_setkey(&ctx->ctx, MBEDTLS_CIPHER_ID_AES, key, ctx->iv_len * 8);
mbedtls_gcm_starts(&ctx->ctx, MBEDTLS_GCM_DECRYPT, iv, ctx->iv_len, NULL, 0);
ctx->iv = iv;
}
return 1;
}
int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl) {
if (ctx) {
ctx->tag = (unsigned char*)malloc(ctx->iv_len);
mbedtls_gcm_crypt_and_tag(&ctx->ctx, MBEDTLS_GCM_DECRYPT, inl, ctx->iv, ctx->iv_len, NULL, 0, in, out, ctx->iv_len, ctx->tag);
*outl = inl;
}
return 1;
}
int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl) {
return 1;
}
int RAND_bytes(unsigned char *buf, int num) {
Data rand = Data::random_bytes(num);
for (int i = 0; i < num; i++) {
buf[i] = rand.bytes()[i];
}
return 1;
}

View file

@ -1,36 +0,0 @@
#include <stdint.h>
#define EVP_CTRL_GCM_SET_IVLEN 0x9
#define EVP_CTRL_GCM_GET_TAG 0x10
#define EVP_CTRL_GCM_SET_TAG 0x11
typedef int EVP_CIPHER;
typedef int ENGINE;
struct MBED_CIPHER_CTX;
typedef struct MBED_CIPHER_CTX EVP_CIPHER_CTX;
#ifdef __cplusplus
extern "C" {
#endif
const EVP_CIPHER *EVP_aes_128_gcm(void);
const EVP_CIPHER *EVP_aes_128_cbc(void);
void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx);
int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *ctx);
EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void);
void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx);
int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv);
int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl);
int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, const unsigned char *key, const unsigned char *iv);
int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl);
int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
#ifdef __cplusplus
}
#endif

View file

@ -1,11 +0,0 @@
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
int RAND_bytes(unsigned char *buf, int num);
#ifdef __cplusplus
}
#endif

@ -1 +1 @@
Subproject commit 5782246b30bfc11e659cf53b498886a924aa97d1
Subproject commit 4723f8ba7cce9b2dead1d2d441472836153fa8ed