@@ -156,9 +156,11 @@ public bool IsClientConnected
156
156
/// </summary>
157
157
public NetworkConfig NetworkConfig ;
158
158
159
+ #if ! DISABLE_CRYPTOGRAPHY
159
160
internal EllipticDiffieHellman clientDiffieHellman ;
160
161
internal readonly Dictionary < uint , byte [ ] > diffieHellmanPublicKeys = new Dictionary < uint , byte [ ] > ( ) ;
161
162
internal byte [ ] clientAesKey ;
163
+ #endif
162
164
163
165
/// <summary>
164
166
/// An inspector bool that acts as a Trigger for regenerating RSA keys. Should not be used outside Unity editor.
@@ -235,7 +237,9 @@ private object Init(bool server)
235
237
connectedClients . Clear ( ) ;
236
238
connectedClientsList . Clear ( ) ;
237
239
messageBuffer = new byte [ NetworkConfig . MessageBufferSize ] ;
240
+ #if ! DISABLE_CRYPTOGRAPHY
238
241
diffieHellmanPublicKeys . Clear ( ) ;
242
+ #endif
239
243
Data . Cache . messageAttributeHashes . Clear ( ) ;
240
244
Data . Cache . messageAttributeNames . Clear ( ) ;
241
245
MessageManager . channels . Clear ( ) ;
@@ -707,19 +711,22 @@ private void Update()
707
711
else
708
712
{
709
713
if ( LogHelper . CurrentLogLevel <= LogLevel . Developer ) LogHelper . LogInfo ( "Connected" ) ;
714
+ #if ! DISABLE_CRYPTOGRAPHY
710
715
byte [ ] diffiePublic = new byte [ 0 ] ;
711
716
if ( NetworkConfig . EnableEncryption )
712
717
{
713
718
clientDiffieHellman = new EllipticDiffieHellman ( EllipticDiffieHellman . DEFAULT_CURVE , EllipticDiffieHellman . DEFAULT_GENERATOR , EllipticDiffieHellman . DEFAULT_ORDER ) ;
714
719
diffiePublic = clientDiffieHellman . GetPublicKey ( ) ;
715
720
}
721
+ #endif
716
722
717
723
using ( BitWriter writer = BitWriter . Get ( ) )
718
724
{
719
725
writer . WriteByteArray ( NetworkConfig . GetConfig ( ) , true ) ;
720
-
726
+ #if ! DISABLE_CRYPTOGRAPHY
721
727
if ( NetworkConfig . EnableEncryption )
722
728
writer . WriteByteArray ( diffiePublic ) ;
729
+ #endif
723
730
724
731
if ( NetworkConfig . ConnectionApproval )
725
732
writer . WriteByteArray ( NetworkConfig . ConnectionData ) ;
@@ -831,6 +838,7 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId)
831
838
}
832
839
833
840
reader . SkipPadded ( ) ;
841
+ #if ! DISABLE_CRYPTOGRAPHY
834
842
byte [ ] readBuffer = null ;
835
843
if ( NetworkConfig . EncryptedChannelsHashSet . Contains ( MessageManager . reverseChannels [ channelId ] ) )
836
844
{
@@ -843,6 +851,9 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId)
843
851
}
844
852
845
853
using ( BitReader messageReader = readBuffer == null ? reader : BitReader . Get ( readBuffer ) )
854
+ #else
855
+ using ( BitReader messageReader = reader )
856
+ #endif
846
857
{
847
858
if ( isServer && isPassthrough && ! NetworkConfig . PassthroughMessageHashSet . Contains ( messageType ) )
848
859
{
@@ -1012,8 +1023,10 @@ internal void DisconnectClient(uint clientId)
1012
1023
1013
1024
connectedClientsList . RemoveAll ( x => x . ClientId == clientId ) ; // :(
1014
1025
1026
+ #if ! DISABLE_CRYPTOGRAPHY
1015
1027
if ( diffieHellmanPublicKeys . ContainsKey ( clientId ) )
1016
1028
diffieHellmanPublicKeys . Remove ( clientId ) ;
1029
+ #endif
1017
1030
1018
1031
foreach ( KeyValuePair < uint , NetworkedObject > pair in SpawnManager . spawnedObjects )
1019
1032
pair . Value . observers . Remove ( clientId ) ;
@@ -1074,6 +1087,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1074
1087
if ( pendingClients . Contains ( clientId ) )
1075
1088
pendingClients . Remove ( clientId ) ;
1076
1089
1090
+ #if ! DISABLE_CRYPTOGRAPHY
1077
1091
byte [ ] aesKey = new byte [ 0 ] ;
1078
1092
byte [ ] publicKey = new byte [ 0 ] ;
1079
1093
byte [ ] publicKeySignature = new byte [ 0 ] ;
@@ -1096,11 +1110,14 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1096
1110
}
1097
1111
}
1098
1112
}
1113
+ #endif
1099
1114
1100
1115
NetworkedClient client = new NetworkedClient ( )
1101
1116
{
1102
1117
ClientId = clientId ,
1118
+ #if ! DISABLE_CRYPTOGRAPHY
1103
1119
AesKey = aesKey
1120
+ #endif
1104
1121
} ;
1105
1122
connectedClients . Add ( clientId , client ) ;
1106
1123
connectedClientsList . Add ( client ) ;
@@ -1120,12 +1137,14 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1120
1137
if ( NetworkConfig . EnableSceneSwitching )
1121
1138
writer . WriteUInt ( NetworkSceneManager . CurrentSceneIndex ) ;
1122
1139
1140
+ #if ! DISABLE_CRYPTOGRAPHY
1123
1141
if ( NetworkConfig . EnableEncryption )
1124
1142
{
1125
1143
writer . WriteByteArray ( publicKey ) ;
1126
1144
if ( NetworkConfig . SignKeyExchange )
1127
1145
writer . WriteByteArray ( publicKeySignature ) ;
1128
1146
}
1147
+ #endif
1129
1148
1130
1149
writer . WriteFloat ( NetworkTime ) ;
1131
1150
writer . WriteInt ( NetworkConfig . NetworkTransport . GetNetworkTimestamp ( ) ) ;
@@ -1216,13 +1235,15 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1216
1235
if ( pendingClients . Contains ( clientId ) )
1217
1236
pendingClients . Remove ( clientId ) ;
1218
1237
1238
+ #if ! DISABLE_CRYPTOGRAPHY
1219
1239
if ( diffieHellmanPublicKeys . ContainsKey ( clientId ) )
1220
1240
diffieHellmanPublicKeys . Remove ( clientId ) ;
1241
+ #endif
1221
1242
1222
1243
NetworkConfig . NetworkTransport . DisconnectClient ( clientId ) ;
1223
1244
}
1224
1245
}
1225
- #region SEND METHODS
1246
+ #region SEND METHODS
1226
1247
/// <summary>
1227
1248
/// Registers a message handler
1228
1249
/// </summary>
@@ -1608,6 +1629,6 @@ public NetworkedObject GetNetworkedObject(uint networkId)
1608
1629
{
1609
1630
return SpawnManager . spawnedObjects [ networkId ] ;
1610
1631
}
1611
- #endregion
1632
+ #endregion
1612
1633
}
1613
1634
}
0 commit comments