Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions com.unity.multiplayer.mlapi/Editor/NetworkingManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public class NetworkingManagerEditor : Editor
private SerializedProperty loadSceneTimeOutProperty;
private SerializedProperty enableMessageBufferingProperty;
private SerializedProperty messageBufferTimeoutProperty;
private SerializedProperty enableEncryptionProperty;
private SerializedProperty signKeyExchangeProperty;
private SerializedProperty serverBase64PfxCertificateProperty;

private ReorderableList networkPrefabsList;
private ReorderableList registeredScenesList;
Expand All @@ -55,7 +52,7 @@ public class NetworkingManagerEditor : Editor
private bool initialized;

private readonly List<Type> transportTypes = new List<Type>();
private string[] transportNames = new string[] { "Select transport..." };
private string[] transportNames = { "Select transport..." };

private void ReloadTransports()
{
Expand Down Expand Up @@ -124,9 +121,6 @@ private void Init()
loadSceneTimeOutProperty = networkConfigProperty.FindPropertyRelative("LoadSceneTimeOut");
enableMessageBufferingProperty = networkConfigProperty.FindPropertyRelative("EnableMessageBuffering");
messageBufferTimeoutProperty = networkConfigProperty.FindPropertyRelative("MessageBufferTimeout");
enableEncryptionProperty = networkConfigProperty.FindPropertyRelative("EnableEncryption");
signKeyExchangeProperty = networkConfigProperty.FindPropertyRelative("SignKeyExchange");
serverBase64PfxCertificateProperty = networkConfigProperty.FindPropertyRelative("ServerBase64PfxCertificate");


ReloadTransports();
Expand Down Expand Up @@ -164,9 +158,6 @@ private void CheckNullProperties()
loadSceneTimeOutProperty = networkConfigProperty.FindPropertyRelative("LoadSceneTimeOut");
enableMessageBufferingProperty = networkConfigProperty.FindPropertyRelative("EnableMessageBuffering");
messageBufferTimeoutProperty = networkConfigProperty.FindPropertyRelative("MessageBufferTimeout");
enableEncryptionProperty = networkConfigProperty.FindPropertyRelative("EnableEncryption");
signKeyExchangeProperty = networkConfigProperty.FindPropertyRelative("SignKeyExchange");
serverBase64PfxCertificateProperty = networkConfigProperty.FindPropertyRelative("ServerBase64PfxCertificate");
}

private void OnEnable()
Expand Down Expand Up @@ -371,15 +362,6 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(allowRuntimeSceneChangesProperty);
}

EditorGUILayout.LabelField("Cryptography", EditorStyles.boldLabel);
EditorGUILayout.PropertyField(enableEncryptionProperty);

using (new EditorGUI.DisabledScope(!networkingManager.NetworkConfig.EnableEncryption))
{
EditorGUILayout.PropertyField(signKeyExchangeProperty);
EditorGUILayout.PropertyField(serverBase64PfxCertificateProperty);
}

serializedObject.ApplyModifiedProperties();


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ internal static class MLAPIConstants
{
internal const string MLAPI_PROTOCOL_VERSION = "13.0.0";

internal const byte MLAPI_CERTIFICATE_HAIL = 0;
internal const byte MLAPI_CERTIFICATE_HAIL_RESPONSE = 1;
internal const byte MLAPI_GREETINGS = 2;
internal const byte MLAPI_CONNECTION_REQUEST = 3;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to adjust enum values so that we don't start at 3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, we might but I simply left that decision/discussion for later here.
(personally, I don't like starting from 0 because I think 0 should be used for empty/null/invalid/default value and not for something meaningful but anyways...)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I like the convention of mapping "None" to 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at one time I tried making these enum's but I found that even if I declared the enum as a byte type I had to then cast it in all the function calls which made a big mess. Probably should rewrite the functions that take these to receive an actual (enum) type not a byte

internal const byte MLAPI_CONNECTION_APPROVED = 4;
internal const byte MLAPI_ADD_OBJECT = 5;
Expand All @@ -29,10 +26,11 @@ internal static class MLAPIConstants
internal const byte MLAPI_CLIENT_RPC = 31;
internal const byte INVALID = 32;

internal static readonly string[] MESSAGE_NAMES = {
"MLAPI_CERTIFICATE_HAIL", // 0
"MLAPI_CERTIFICATE_HAIL_RESPONSE",
"MLAPI_GREETINGS",
internal static readonly string[] MESSAGE_NAMES =
{
"", // 0
"",
"",
"MLAPI_CONNECTION_REQUEST",
"MLAPI_CONNECTION_APPROVED",
"MLAPI_ADD_OBJECT",
Expand Down Expand Up @@ -65,4 +63,4 @@ internal static class MLAPIConstants
"INVALID" // 32
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
using System.Linq;
using MLAPI.Transports;
using BitStream = MLAPI.Serialization.BitStream;
using System.Security.Cryptography.X509Certificates;
using MLAPI.Hashing;
using MLAPI.Serialization.Pooled;
using UnityEngine.Serialization;

namespace MLAPI.Configuration
{
Expand Down Expand Up @@ -171,51 +169,6 @@ public class NetworkConfig
/// Whether or not to enable network logs.
/// </summary>
public bool EnableNetworkLogs = true;
/// <summary>
/// Whether or not to enable the ECDHE key exchange to allow for encryption and authentication of messages
/// </summary>
[Tooltip("Whether or not to enable the ECDHE key exchange to allow for encryption and authentication of messages")]
public bool EnableEncryption = false;
/// <summary>
/// Whether or not to enable signed diffie hellman key exchange.
/// </summary>
[Tooltip("Whether or not to sign the diffie hellman key exchange to prevent MITM attacks on")]
public bool SignKeyExchange = false;
/// <summary>
/// Pfx file in base64 encoding containing private and public key
/// </summary>
[Tooltip("The certificate in base64 encoded PFX format")]
[TextArea]
public string ServerBase64PfxCertificate;
/// <summary>
/// Gets the currently in use certificate
/// </summary>
public X509Certificate2 ServerX509Certificate
{
get
{
return serverX509Certificate;
}
internal set
{
serverX509CertificateBytes = null;
serverX509Certificate = value;
}
}
private X509Certificate2 serverX509Certificate;
/// <summary>
/// Gets the cached binary representation of the server certificate that's used for handshaking
/// </summary>
public byte[] ServerX509CertificateBytes
{
get
{
if (serverX509CertificateBytes == null)
serverX509CertificateBytes = ServerX509Certificate.Export(X509ContentType.Cert);
return serverX509CertificateBytes;
}
}
private byte[] serverX509CertificateBytes = null;

private void Sort()
{
Expand Down Expand Up @@ -248,8 +201,6 @@ public string ToBase64()
writer.WriteInt32Packed(config.ClientConnectionBufferTimeout);
writer.WriteBool(config.ConnectionApproval);
writer.WriteInt32Packed(config.SecondsHistory);
writer.WriteBool(config.EnableEncryption);
writer.WriteBool(config.SignKeyExchange);
writer.WriteInt32Packed(config.LoadSceneTimeOut);
writer.WriteBool(config.EnableTimeResync);
writer.WriteBool(config.EnsureNetworkedVarLengthSafety);
Expand Down Expand Up @@ -297,8 +248,6 @@ public void FromBase64(string base64)
config.ClientConnectionBufferTimeout = reader.ReadInt32Packed();
config.ConnectionApproval = reader.ReadBool();
config.SecondsHistory = reader.ReadInt32Packed();
config.EnableEncryption = reader.ReadBool();
config.SignKeyExchange = reader.ReadBool();
config.LoadSceneTimeOut = reader.ReadInt32Packed();
config.EnableTimeResync = reader.ReadBool();
config.EnsureNetworkedVarLengthSafety = reader.ReadBool();
Expand Down Expand Up @@ -358,8 +307,6 @@ public ulong GetConfig(bool cache = true)
writer.WriteBool(UsePrefabSync);
writer.WriteBool(EnableSceneManagement);
writer.WriteBool(EnsureNetworkedVarLengthSafety);
writer.WriteBool(EnableEncryption);
writer.WriteBool(SignKeyExchange);
writer.WriteBits((byte)RpcHashSize, 2);
stream.PadStream();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ public class NetworkedClient
/// The Id of the NetworkedClient
/// </summary>
public ulong ClientId;

/// <summary>
/// The PlayerObject of the Client
/// </summary>
public NetworkedObject PlayerObject;

/// <summary>
/// The NetworkedObject's owned by this Client
/// </summary>
public readonly List<NetworkedObject> OwnedObjects = new List<NetworkedObject>();
/// <summary>
/// The encryption key used for this client
/// </summary>
public byte[] AesKey;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#if !DISABLE_CRYPTOGRAPHY
using MLAPI.Security;
#endif

namespace MLAPI.Connection
namespace MLAPI.Connection
{
/// <summary>
/// A class representing a client that is currently in the process of connecting
Expand All @@ -13,14 +9,6 @@ public class PendingClient
/// The ClientId of the client
/// </summary>
public ulong ClientId;

#if !DISABLE_CRYPTOGRAPHY
internal EllipticDiffieHellman KeyExchange;
#endif
/// <summary>
/// The current AesKey
/// </summary>
public byte[] AesKey;

/// <summary>
/// The state of the connection process for the client
Expand All @@ -32,10 +20,6 @@ public class PendingClient
/// </summary>
public enum State
{
/// <summary>
/// Client is in the process of doing the hail handshake
/// </summary>
PendingHail,
/// <summary>
/// Client is in the process of doing the connection handshake
/// </summary>
Expand Down
35 changes: 11 additions & 24 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkedBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using MLAPI.NetworkedVar;
using MLAPI.Profiling;
using MLAPI.Reflection;
using MLAPI.Security;
using MLAPI.Serialization;
using MLAPI.Serialization.Pooled;
using MLAPI.Spawning;
Expand Down Expand Up @@ -74,25 +73,21 @@ public BitSerializer __beginSendServerRpc(ServerRpcParams serverRpcParams, RpcDe

if (IsHost)
{
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ServerRpc, Time.realtimeSinceStartup, transportChannel, 0,
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ServerRpc, Time.realtimeSinceStartup, transportChannel,
NetworkingManager.Singleton.ServerClientId, null, QueueHistoryFrame.QueueFrameType.Inbound, serverRpcParams.Send.UpdateStage);

if (!isUsingBatching)
{
writer.WriteBit(false); // Encrypted
writer.WriteBit(false); // Authenticated
writer.WriteBits(MLAPIConstants.MLAPI_SERVER_RPC, 6); // MessageType
writer.WriteByte(MLAPIConstants.MLAPI_SERVER_RPC); // MessageType
}
}
else
{
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ServerRpc, Time.realtimeSinceStartup, transportChannel, 0,
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ServerRpc, Time.realtimeSinceStartup, transportChannel,
NetworkingManager.Singleton.ServerClientId, null, QueueHistoryFrame.QueueFrameType.Outbound, NetworkUpdateStage.PostLateUpdate);
if (!isUsingBatching)
{
writer.WriteBit(false); // Encrypted
writer.WriteBit(false); // Authenticated
writer.WriteBits(MLAPIConstants.MLAPI_SERVER_RPC, 6); // MessageType
writer.WriteByte(MLAPIConstants.MLAPI_SERVER_RPC); // MessageType
}
}

Expand Down Expand Up @@ -157,7 +152,7 @@ public BitSerializer __beginSendClientRpc(ClientRpcParams clientRpcParams, RpcDe
if (IsHost && ContainsServerClientId)
{
//Always write to the next frame's inbound queue
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ClientRpc, Time.realtimeSinceStartup, transportChannel, 0,
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ClientRpc, Time.realtimeSinceStartup, transportChannel,
NetworkingManager.Singleton.ServerClientId, null, QueueHistoryFrame.QueueFrameType.Inbound, clientRpcParams.Send.UpdateStage);

//Handle sending to the other clients, if so the above notes explain why this code is here (a temporary patch-fix)
Expand All @@ -167,36 +162,30 @@ public BitSerializer __beginSendClientRpc(ClientRpcParams clientRpcParams, RpcDe
rpcQueueContainer.SetLoopBackFrameItem(clientRpcParams.Send.UpdateStage);

//Switch to the outbound queue
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ClientRpc, Time.realtimeSinceStartup, Channel.ReliableRPC, 0, NetworkId,
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ClientRpc, Time.realtimeSinceStartup, Channel.ReliableRPC, NetworkId,
ClientIds, QueueHistoryFrame.QueueFrameType.Outbound, NetworkUpdateStage.PostLateUpdate);

if (!isUsingBatching)
{
writer.WriteBit(false); // Encrypted
writer.WriteBit(false); // Authenticated
writer.WriteBits(MLAPIConstants.MLAPI_CLIENT_RPC, 6); // MessageType
writer.WriteByte(MLAPIConstants.MLAPI_CLIENT_RPC); // MessageType
}
}
else
{
if (!isUsingBatching)
{
writer.WriteBit(false); // Encrypted
writer.WriteBit(false); // Authenticated
writer.WriteBits(MLAPIConstants.MLAPI_CLIENT_RPC, 6); // MessageType
writer.WriteByte(MLAPIConstants.MLAPI_CLIENT_RPC); // MessageType
}
}
}
else
{
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ClientRpc, Time.realtimeSinceStartup, transportChannel, 0, NetworkId,
writer = rpcQueueContainer.BeginAddQueueItemToFrame(RpcQueueContainer.QueueItemType.ClientRpc, Time.realtimeSinceStartup, transportChannel, NetworkId,
ClientIds, QueueHistoryFrame.QueueFrameType.Outbound, NetworkUpdateStage.PostLateUpdate);

if (!isUsingBatching)
{
writer.WriteBit(false); // Encrypted
writer.WriteBit(false); // Authenticated
writer.WriteBits(MLAPIConstants.MLAPI_CLIENT_RPC, 6); // MessageType
writer.WriteByte(MLAPIConstants.MLAPI_CLIENT_RPC); // MessageType
}
}

Expand Down Expand Up @@ -708,9 +697,7 @@ private void NetworkedVarUpdate(ulong clientId)

if (writtenAny)
{
InternalMessageSender.Send(clientId,
MLAPIConstants.MLAPI_NETWORKED_VAR_DELTA,
channelsForNetworkedVarGroups[j], stream, SecuritySendFlags.None);
InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_NETWORKED_VAR_DELTA, channelsForNetworkedVarGroups[j], stream);
}
}
}
Expand Down
8 changes: 3 additions & 5 deletions com.unity.multiplayer.mlapi/Runtime/Core/NetworkedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
using MLAPI.Hashing;
using MLAPI.Logging;
using MLAPI.Messaging;
using MLAPI.Security;
using MLAPI.Serialization.Pooled;
using MLAPI.Spawning;
using MLAPI.Transports;
using Unity.Profiling;
using UnityEngine;

namespace MLAPI
Expand Down Expand Up @@ -283,7 +281,7 @@ public static void NetworkShow(List<NetworkedObject> networkedObjects, ulong cli
SpawnManager.WriteSpawnCallForObject(stream, clientId, networkedObjects[i], payload);
}

InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_ADD_OBJECTS, Channel.Internal, stream, SecuritySendFlags.None);
InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_ADD_OBJECTS, Channel.Internal, stream);
}
}

Expand Down Expand Up @@ -323,7 +321,7 @@ public void NetworkHide(ulong clientId)
{
writer.WriteUInt64Packed(NetworkId);

InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_DESTROY_OBJECT, Channel.Internal, stream, SecuritySendFlags.None);
InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_DESTROY_OBJECT, Channel.Internal, stream);
}
}
}
Expand Down Expand Up @@ -375,7 +373,7 @@ public static void NetworkHide(List<NetworkedObject> networkedObjects, ulong cli
}
}

InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_DESTROY_OBJECTS, Channel.Internal, stream, SecuritySendFlags.None);
InternalMessageSender.Send(clientId, MLAPIConstants.MLAPI_DESTROY_OBJECTS, Channel.Internal, stream);
}
}

Expand Down
Loading