How to include OpenSSL?

Hello,

I am trying to include OpenSSL to be able to encrypt and decrypt everything going through my socket.
I just want to preface this by saying : WON’T WORRY I am NOT doing that during a game but only in the main menu.

So I am trying to include OpenSSL but when I do it I get macro redefinition and other kind of problem.
My code :

#if PLATFORM_WINDOWS
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/pem.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/ssl.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/rsa.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/evp.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/bio.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/err.h"
#elif PLATFORM_MAC
#elif PLATFORM_LINUX
#endif

Error :

2>C:\Program Files\Epic Games\UE_4.18\Engine\Source\ThirdParty\OpenSSL\1.0.2g\include\Win64\VS2015\openssl/ossl_typ.h(172): error C2365: 'UI': redefinition; previous definition was 'namespace'
2>C:\Program Files\Epic Games\UE_4.18\Engine\Source\Runtime\CoreUObject\Public\UObject/ObjectMacros.h(721): note: see declaration of 'UI'

I found several topic but none of the answers helped me, this is where I am at :

#define UI UI_ST
THIRD_PARTY_INCLUDES_START
#if PLATFORM_WINDOWS
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/pem.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/ssl.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/rsa.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/evp.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/bio.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/err.h"
#elif PLATFORM_MAC
#elif PLATFORM_LINUX
#endif
THIRD_PARTY_INCLUDES_END
#undef UI

That’s nice because the UI conflict desapears but this appears :

2>C:\Program Files (x86)\Windows Kits\8.1\include\um\winnt.h(536): warning C4005: 'TEXT': macro redefinition
2>c:\program files\epic games\ue_4.18\engine\source\runtime\core\public\HAL/Platform.h(848): note: see previous definition of 'TEXT'
2>C:\Users\...\Documents\MagesBattle\MagesBattle\Source\MagesBattle\Private\NetworkManager.cpp(95): error C2039: 'SetPortW': is not a member of 'FInternetAddr'
2>C:\Program Files\Epic Games\UE_4.18\Engine\Source\Runtime\Sockets\Public\IPAddress.h(13): note: see declaration of 'FInternetAddr'
2>C:\Users\...\Documents\MagesBattle\MagesBattle\Source\MagesBattle\Private\NetworkManager.cpp(147): error C2039: 'GetMessageW': is not a member of 'IMessageContext'
2>C:\Program Files\Epic Games\UE_4.18\Engine\Source\Runtime\Messaging\Public\IMessageReceiver.h(9): note: see declaration of 'IMessageContext'
2>C:\Users\...\Documents\MagesBattle\MagesBattle\Source\MagesBattle\Private\NetworkManager.cpp(147): error C2672: 'StaticCast': no matching overloaded function found

Which is very weird, I feel like some very important type were redefined because of the include.

Someone has an idea ?

Well I found the solution while look into the UE4 source code. In the HTTPS implementation of UE4 there I found the correct code.

This following code is not complete you will need to include the correct header for osx and linux.

#include "NetworkManager.h"

#if PLATFORM_WINDOWS
#include "WindowsHWrapper.h"
#include "AllowWindowsPlatformTypes.h"
#endif

#define UI UI_ST
THIRD_PARTY_INCLUDES_START
#if PLATFORM_WINDOWS
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/pem.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/ssl.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/rsa.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/evp.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/bio.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/err.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/bn.h"
#include "ThirdParty/OpenSSL/1.0.2g/include/Win64/VS2015/openssl/x509.h"
#elif PLATFORM_MAC
#elif PLATFORM_LINUX
#endif
THIRD_PARTY_INCLUDES_END
#undef UI

#if PLATFORM_WINDOWS
#include "HideWindowsPlatformTypes.h"
#endif