From 0f4b18b8eb8bf3b8aa80d93dc222d4be66db1211 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Thu, 16 Jul 2020 17:48:35 -0700 Subject: [PATCH] 1. Fixed compiler warnings 2. Fixed #ifdef for NOTLS --- meshcore/agentcore.c | 19 ++++++++++++------- meshcore/agentcore.h | 3 ++- microstack/ILibWebRTC.c | 11 ++++++++++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index f592cdb..fbf1bdc 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -600,6 +600,7 @@ void UDPSocket_OnData(ILibAsyncUDPSocket_SocketModule socketModule, char* buffer if (remoteInterface->sin6_family != AF_INET && remoteInterface->sin6_family != AF_INET6) return; //isLoopback = ILibIsLoopback((struct sockaddr*)remoteInterface); +#ifndef MICROSTACK_NOTLS // If the discovery key is set, use it to decrypt the packet if (agentHost->multicastDiscoveryKey != NULL) { @@ -615,16 +616,17 @@ void UDPSocket_OnData(ILibAsyncUDPSocket_SocketModule socketModule, char* buffer // Decrypt the packet using AES256-CBC dec_ctx = EVP_CIPHER_CTX_new(); - EVP_DecryptInit(dec_ctx, EVP_aes_256_cbc(), agentHost->multicastDiscoveryKey, buffer); - if (!EVP_DecryptUpdate(dec_ctx, ILibScratchPad, &declength, buffer + 16, bufferLength - 16)) { EVP_CIPHER_CTX_free(dec_ctx); return; } + EVP_DecryptInit(dec_ctx, EVP_aes_256_cbc(), agentHost->multicastDiscoveryKey, (unsigned char*)buffer); + if (!EVP_DecryptUpdate(dec_ctx, (unsigned char*)ILibScratchPad, &declength, (unsigned char*)(buffer + 16), bufferLength - 16)) { EVP_CIPHER_CTX_free(dec_ctx); return; } packetLen = declength; - if (!EVP_DecryptFinal_ex(dec_ctx, ILibScratchPad + packetLen, &declength)) { EVP_CIPHER_CTX_free(dec_ctx); return; } + if (!EVP_DecryptFinal_ex(dec_ctx, (unsigned char*)(ILibScratchPad + packetLen), &declength)) { EVP_CIPHER_CTX_free(dec_ctx); return; } packetLen += declength; packet = ILibScratchPad; EVP_CIPHER_CTX_free(dec_ctx); packet[packetLen] = 0; } else +#endif { // Assume UDP Packet is not encrypted packet = buffer; @@ -3366,7 +3368,9 @@ void MeshServer_ConnectEx(MeshAgentHostContainer *agent) else { // Multicast discovery packet to try to find our server - if ((agent->multicastDiscovery2 != NULL) && (ILibSimpleDataStore_Get(agent->masterDb, "ServerID", ILibScratchPad2, sizeof(ILibScratchPad2)) == 97)) { + if ((agent->multicastDiscovery2 != NULL) && (ILibSimpleDataStore_Get(agent->masterDb, "ServerID", ILibScratchPad2, sizeof(ILibScratchPad2)) == 97)) + { +#ifndef MICROSTACK_NOTLS // If the discovery key is set, use it to encrypt the UDP packet if (agent->multicastDiscoveryKey != NULL) { @@ -3374,12 +3378,12 @@ void MeshServer_ConnectEx(MeshAgentHostContainer *agent) int enclength = sizeof(ILibScratchPad) - 16, packetLen; util_random(16, ILibScratchPad); // Select a random IV enc_ctx = EVP_CIPHER_CTX_new(); - EVP_EncryptInit(enc_ctx, EVP_aes_256_cbc(), agent->multicastDiscoveryKey, ILibScratchPad); - if (EVP_EncryptUpdate(enc_ctx, ILibScratchPad + 16, &enclength, ILibScratchPad2, 96)) + EVP_EncryptInit(enc_ctx, EVP_aes_256_cbc(), agent->multicastDiscoveryKey, (unsigned char*)ILibScratchPad); + if (EVP_EncryptUpdate(enc_ctx, (unsigned char*)(ILibScratchPad + 16), &enclength, (unsigned char*)ILibScratchPad2, 96)) { packetLen = enclength; enclength = sizeof(ILibScratchPad) - 16 - packetLen; - if (EVP_EncryptFinal_ex(enc_ctx, ILibScratchPad + 16 + packetLen, &enclength)) + if (EVP_EncryptFinal_ex(enc_ctx, (unsigned char*)(ILibScratchPad + 16 + packetLen), &enclength)) { // Send the encrypted packet ILibMulticastSocket_Broadcast(agent->multicastDiscovery2, ILibScratchPad, 16 + packetLen + enclength, 1); @@ -3388,6 +3392,7 @@ void MeshServer_ConnectEx(MeshAgentHostContainer *agent) EVP_CIPHER_CTX_free(enc_ctx); } else +#endif { // No discovery key set, broadcast without encryption ILibMulticastSocket_Broadcast(agent->multicastDiscovery2, ILibScratchPad2, 96, 1); diff --git a/meshcore/agentcore.h b/meshcore/agentcore.h index 2315dd5..cfa93b3 100644 --- a/meshcore/agentcore.h +++ b/meshcore/agentcore.h @@ -66,7 +66,8 @@ typedef enum MeshCommand_AuthInfo_CapabilitiesMask MeshCommand_AuthInfo_CapabilitiesMask_CONSOLE = 0x08, MeshCommand_AuthInfo_CapabilitiesMask_JAVASCRIPT = 0x10, MeshCommand_AuthInfo_CapabilitiesMask_TEMPORARY = 0x20, - MeshCommand_AuthInfo_CapabilitiesMask_RECOVERY = 0x40 + MeshCommand_AuthInfo_CapabilitiesMask_RECOVERY = 0x40, + MeshCommand_AuthInfo_CapabilitiesMask_COMPRESSION = 0x80 }MeshCommand_AuthInfo_CapabilitiesMask; typedef enum AgentIdentifiers diff --git a/microstack/ILibWebRTC.c b/microstack/ILibWebRTC.c index 5f393a0..13cfa3d 100644 --- a/microstack/ILibWebRTC.c +++ b/microstack/ILibWebRTC.c @@ -7480,6 +7480,15 @@ int ILibSCTP_Debug_SetDebugCallback(void* dtlsSession, char* debugFieldName, ILi return 0; } #endif +#endif + +#ifdef MICROSTACK_NOTLS +#if defined(WINSOCK2) + #include + #include +#endif + #include "ILibParsers.h" +#endif /* zlib.h -- interface of the 'zlib' general purpose compression library version 1.2.11, January 15th, 2017 @@ -7689,4 +7698,4 @@ uint32_t crc32(uint32_t crc, const unsigned char* buf, uint32_t len) return crc32_z(crc, buf, len); } -#endif +