Skip to content

Commit e1ceb9f

Browse files
committed
add TLS support
1 parent 6036dbf commit e1ceb9f

File tree

14 files changed

+534
-265
lines changed

14 files changed

+534
-265
lines changed

README.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Socket.IO Lib uses _asio_, _rapidjson_, and _websocketpp_. SIOJson is originally
1111
[Unreal Forum Thread](https://forums.unrealengine.com/showthread.php?110680-Plugin-Socket-io-Client)
1212

1313

14-
Recommended socket.io server version: 1.4+.
14+
Recommended socket.io server version: 3.0+
1515

1616
*Tip: This is a sizeable readme, quickly find your topic with ```Ctrl+F``` and a search term e.g. namespaces*
1717

@@ -22,8 +22,34 @@ Current platform issues:
2222
* Xbox/PS4 platform untested - see [issue 117](https://github.com/getnamo/SocketIOClient-Unreal/issues/117)
2323
* Lumin platform untested - see [issue 114](https://github.com/getnamo/SocketIOClient-Unreal/issues/114)
2424

25-
HTTPS currently not yet supported
26-
* OpenSSL Support - Available under separate branch https://github.com/getnamo/SocketIOClient-Unreal/tree/ssl. Issue tracked here: [issue39](https://github.com/getnamo/SocketIOClient-Unreal/issues/39)
25+
Current TLS/SSL issues:
26+
27+
* Certification verification is not implemented; setting `bShouldSkipCertificateVerification` will always fail - see [issue 303](https://github.com/getnamo/SocketIOClient-Unreal/issues/303)
28+
29+
## Socket.IO Server Compatibility
30+
31+
Some features in later versions of this plugin are not supported by earlier versions of the Socket.IO server API. See the compatibility table below for more details
32+
33+
<table>
34+
<tr>
35+
<th rowspan="2">UE4 Socket.IO plugin version</th>
36+
<th colspan="2">Socket.IO server version</th>
37+
</tr>
38+
<tr>
39+
<td align="center">1.x / 2.x</td>
40+
<td align="center">3.x / 4.x</td>
41+
</tr>
42+
<tr>
43+
<td><a href="https://github.com/getnamo/socketio-client-ue4/releases/tag/v2.0.1">v2.0.1 and earlier</a></td>
44+
<td align="center">YES</td>
45+
<td align="center">NO</td>
46+
</tr>
47+
<tr>
48+
<td><a href="https://github.com/dobby5/socketio-client-ue4">v2.1.0 and later</a></td>
49+
<td align="center">NO</td>
50+
<td align="center">YES</td>
51+
</tr>
52+
</table>
2753

2854
## Quick Install & Setup ##
2955

@@ -773,6 +799,12 @@ You can post simple JSON requests using the SIOJRequest (this is the same archit
773799
774800
These request functions are available globally.
775801
802+
## TLS / SSL
803+
804+
TLS is supported for both C++ and BP without recompiling the plugin to switch between no TLS and TLS. To use it, you must enable the `bShouldUseTlsLibraries` flag on the `SocketIOClientComponent` **and** specify a `https` or `wss` URL as the host.
805+
806+
Currently, certification verification is not implemented, so you must have `bShouldSkipCertificateVerification` enabled (currently the default). See [issue 303](https://github.com/getnamo/SocketIOClient-Unreal/issues/303).
807+
776808
## Packaging
777809
778810
### C++

Source/SocketIOClient/Private/SocketIOClient.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class FSocketIOClientModule : public ISocketIOClientModule
1515
{
1616
public:
1717
//virtual TSharedPtr<FSocketIONative> NewValidNativePointer() override;
18-
virtual TSharedPtr<FSocketIONative> NewValidNativePointer() override;
19-
virtual TSharedPtr<FSocketIONative> ValidSharedNativePointer(FString SharedId) override;
18+
virtual TSharedPtr<FSocketIONative> NewValidNativePointer(const bool bShouldUseTlsLibraries, const bool bShouldSkipCertificateVerification) override;
19+
virtual TSharedPtr<FSocketIONative> ValidSharedNativePointer(FString SharedId, const bool bShouldUseTlsLibraries, const bool bShouldSkipCertificateVerification) override;
2020
void ReleaseNativePointer(TSharedPtr<FSocketIONative> PointerToRelease) override;
2121

2222
/** IModuleInterface implementation */
@@ -79,9 +79,9 @@ void FSocketIOClientModule::ShutdownModule()
7979
PluginNativePointers.Empty();
8080
}
8181

82-
TSharedPtr<FSocketIONative> FSocketIOClientModule::NewValidNativePointer()
82+
TSharedPtr<FSocketIONative> FSocketIOClientModule::NewValidNativePointer(const bool bShouldUseTlsLibraries, const bool bShouldSkipCertificateVerification)
8383
{
84-
TSharedPtr<FSocketIONative> NewPointer = MakeShareable(new FSocketIONative);
84+
TSharedPtr<FSocketIONative> NewPointer = MakeShareable(new FSocketIONative(bShouldUseTlsLibraries, bShouldSkipCertificateVerification));
8585

8686
PluginNativePointers.Add(NewPointer);
8787

@@ -90,7 +90,7 @@ TSharedPtr<FSocketIONative> FSocketIOClientModule::NewValidNativePointer()
9090
return NewPointer;
9191
}
9292

93-
TSharedPtr<FSocketIONative> FSocketIOClientModule::ValidSharedNativePointer(FString SharedId)
93+
TSharedPtr<FSocketIONative> FSocketIOClientModule::ValidSharedNativePointer(FString SharedId, const bool bShouldUseTlsLibraries, const bool bShouldSkipCertificateVerification)
9494
{
9595
//Found key? return it
9696
if (SharedNativePointers.Contains(SharedId))
@@ -100,7 +100,7 @@ TSharedPtr<FSocketIONative> FSocketIOClientModule::ValidSharedNativePointer(FStr
100100
//Otherwise request a new id and return it
101101
else
102102
{
103-
TSharedPtr<FSocketIONative> NewNativePtr = NewValidNativePointer();
103+
TSharedPtr<FSocketIONative> NewNativePtr = NewValidNativePointer(bShouldUseTlsLibraries, bShouldSkipCertificateVerification);
104104
SharedNativePointers.Add(SharedId, NewNativePtr);
105105
AllSharedPtrs.Add(NewNativePtr);
106106
return NewNativePtr;

Source/SocketIOClient/Private/SocketIOClientComponent.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
USocketIOClientComponent::USocketIOClientComponent(const FObjectInitializer &init) : UActorComponent(init)
1313
{
14+
bShouldUseTlsLibraries = false;
15+
bShouldSkipCertificateVerification = false;
1416
bShouldAutoConnect = true;
1517
bWantsInitializeComponent = true;
1618
bAutoActivate = true;
@@ -63,14 +65,14 @@ void USocketIOClientComponent::InitializeNative()
6365
{
6466
if (bPluginScopedConnection)
6567
{
66-
NativeClient = ISocketIOClientModule::Get().ValidSharedNativePointer(PluginScopedId);
68+
NativeClient = ISocketIOClientModule::Get().ValidSharedNativePointer(PluginScopedId, bShouldUseTlsLibraries, bShouldSkipCertificateVerification);
6769

6870
//Enforcement: This is the default FSocketIONative option value, but this component depends on it being true.
6971
NativeClient->bCallbackOnGameThread = true;
7072
}
7173
else
7274
{
73-
NativeClient = ISocketIOClientModule::Get().NewValidNativePointer();
75+
NativeClient = ISocketIOClientModule::Get().NewValidNativePointer(bShouldUseTlsLibraries, bShouldSkipCertificateVerification);
7476
}
7577

7678
SetupCallbacks();

Source/SocketIOClient/Private/SocketIONative.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "sio_message.h"
1010
#include "sio_socket.h"
1111

12-
FSocketIONative::FSocketIONative()
12+
FSocketIONative::FSocketIONative(const bool bShouldUseTlsLibraries, const bool bShouldSkipCertificateVerification)
1313
{
1414
PrivateClient = nullptr;
1515
AddressAndPort = TEXT("http://localhost:3000"); //default to 127.0.0.1
@@ -20,7 +20,7 @@ FSocketIONative::FSocketIONative()
2020
ReconnectionDelay = 5000;
2121
bCallbackOnGameThread = true;
2222

23-
PrivateClient = MakeShareable(new sio::client);
23+
PrivateClient = MakeShareable(new sio::client(bShouldUseTlsLibraries, bShouldSkipCertificateVerification));
2424

2525
ClearCallbacks();
2626
}

Source/SocketIOClient/Public/SocketIOClient.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ class SOCKETIOCLIENT_API ISocketIOClientModule : public IModuleInterface
3535
/**
3636
* Request a new plugin scoped pointer as a shared ptr.
3737
*/
38-
virtual TSharedPtr<FSocketIONative> NewValidNativePointer() { return nullptr; };
38+
virtual TSharedPtr<FSocketIONative> NewValidNativePointer(const bool bShouldUseTlsLibraries, const bool bShouldSkipCertificateVerification) { return nullptr; };
3939

4040
/**
4141
* Request a shared FSocketIONative instance for a given id. May allocate a new pointer.
4242
*/
43-
virtual TSharedPtr<FSocketIONative> ValidSharedNativePointer(FString SharedId) { return nullptr; };
43+
virtual TSharedPtr<FSocketIONative> ValidSharedNativePointer(FString SharedId, const bool bShouldUseTlsLibraries, const bool bShouldSkipCertificateVerification) { return nullptr; };
4444

4545
/**
4646
* Releases the given plugin scoped pointer using a background thread

Source/SocketIOClient/Public/SocketIOClientComponent.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,30 @@ class SOCKETIOCLIENT_API USocketIOClientComponent : public UActorComponent
6060
FSIOCEventSignature OnFail;
6161

6262

63-
/** Default connection address string in form e.g. http://localhost:80. */
63+
/**
64+
* Default connection address string in form e.g. http://localhost:80.
65+
* If HTTPS/WSS is provided and TLS/SSL libraries aren't compiled, HTTP/WS
66+
* will be used.
67+
*/
6468
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SocketIO Connection Properties")
6569
FString AddressAndPort;
6670

71+
/**
72+
* Whether or not to use the TLS/SSL libraries for the connection.
73+
* Ignored if TLS/SSL libraries are not compiled in (SIO_TLS isn't defined)
74+
*/
75+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SocketIO Connection Properties")
76+
bool bShouldUseTlsLibraries;
77+
78+
/**
79+
* If `Should Use TLS Libraries` is set to true, setting this to true
80+
* will not verify the authenticity of the SSL certificate (i.e. asio::ssl::verify_none).
81+
* NOTE: Certification verification is currently not implemented; setting to false will
82+
* always fail verification.
83+
*/
84+
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SocketIO Connection Properties")
85+
bool bShouldSkipCertificateVerification = true;
86+
6787
/** If true will auto-connect on begin play to address specified in AddressAndPort. */
6888
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SocketIO Connection Properties")
6989
bool bShouldAutoConnect;

Source/SocketIOClient/Public/SocketIONative.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class SOCKETIOCLIENT_API FSocketIONative
9595
/** If true, all callbacks and events will occur on game thread. Default true. */
9696
bool bCallbackOnGameThread;
9797

98-
FSocketIONative();
98+
FSocketIONative(const bool bShouldUseTlsLibraries, const bool bShouldSkipCertificateVerification);
9999

100100
/**
101101
* Connect to a socket.io server, optional method if auto-connect is set to true.

0 commit comments

Comments
 (0)