com.unity.netcode.gameobjects icon indicating copy to clipboard operation
com.unity.netcode.gameobjects copied to clipboard

How to have a secured connection with Netcode for Gameobjects and Unity Transport?

Open Marc477 opened this issue 3 years ago • 2 comments

I'm trying to figure out how to create a secured connection. I don't find any doc about it.

I saw somewhere you can do it with the Unity Transport. But it only says how to do it if you're coding directly the transport, not with Netcode.

settings.WithSecureServerParameters(
            certificate: ref SecureParameters.MyGameServerCertificate,                  
            privateKey: ref SecureParameters.MyGameServerPrivate  
        );

 m_Driver = NetworkDriver.Create(settings); 

But then what do you do with this? Is there any way to plug the driver or the settings directly into the NetworkManager of Netcode? Or in the UnityTransport component? I haven't found any function to do this.

Marc477 avatar Apr 18 '22 19:04 Marc477

Ok so I found where the driver is created in the code UnityTransport.cs line 1123

m_NetworkSettings.WithNetworkConfigParameters(
               maxConnectAttempts: transport.m_MaxConnectAttempts,
               connectTimeoutMS: transport.m_ConnectTimeoutMS,
               disconnectTimeoutMS: transport.m_DisconnectTimeoutMS,
               heartbeatTimeoutMS: transport.m_HeartbeatTimeoutMS,
               maxFrameTimeMS: maxFrameTimeMS);

But it doesn't allow for changing the secured settings. I feel like there should be new settings in Connection data, for example i would be able to do this

transport.ConnectionData.Address = localhost;   //Already exists
transport.ConnectionData.Port = port;              //Already exists
transport.ConnectionData.IsSecured = true;              //Does not exists
transport.ConnectionData.Certificate= "";              //Does not exists
transport.ConnectionData.PrivateKey = "";             //Does not exists
transport.ConnectionData.CACertificate = "";              //Does not exists

And then based on if you called StartHost or StartClient, it will create the right settings in UnityTransport.cs

Is this something you would consider adding in the future? Seems like something necessary. Otherwise I really don't know how I'm supposed to create a secured connection. I miss the old Unity days when the packages were imported directly in the project so you can edit the code. Now the code comes from package manager and can't be edited. Do you have any suggestions on how to achieve this? and if this is something you'd consider to add ?

Note: if my assumptions are correct, you can change the flag from support to feature.

Marc477 avatar Apr 18 '22 19:04 Marc477

It may be too late, but it looks like what you were looking for is now available with: Снимок экрана 2024-02-20 194405

sergei201613 avatar Feb 20 '24 11:02 sergei201613