-
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
66 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,60 @@ | ||
using System; | ||
using System.IO; | ||
using System.Net.Security; | ||
using System.Net.Sockets; | ||
using System.Security.Cryptography.X509Certificates; | ||
using Mirror.SimpleWeb; | ||
using UnityEngine; | ||
|
||
namespace Mirror | ||
{ | ||
public class TransportSecurity : MonoBehaviour | ||
public class TransportSecurity : MonoBehaviour, ICreateStream | ||
{ | ||
public SSLSettings sslSettings; | ||
public CertificateSettings certificateSettings; | ||
public SSLSettings GetSslSettings() | ||
{ | ||
return sslSettings; | ||
} | ||
public bool TryCreateStream(IConnection conn) | ||
{ | ||
NetworkStream stream = conn.Client.GetStream(); | ||
if (sslSettings.SSLEnabled) | ||
{ | ||
try | ||
{ | ||
conn.Stream = CreateStream(stream); | ||
return true; | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogError($"[SWT-ServerSslHelper]: Create SSLStream Failed: {e.Message}"); | ||
return false; | ||
} | ||
} | ||
|
||
conn.Stream = stream; | ||
return true; | ||
} | ||
public Stream CreateStream(NetworkStream stream) | ||
{ | ||
if (!sslSettings.SSLEnabled) | ||
{ | ||
Debug.LogError("SSL is not enabled. Unable to create stream."); | ||
return null; | ||
} | ||
|
||
SslStream sslStream = new SslStream(stream, true, AcceptClient); | ||
sslStream.AuthenticateAsServer(certificateSettings.Certificate, false, sslSettings.SSLProtocol, false); | ||
|
||
return sslStream; | ||
} | ||
|
||
// Always accept client | ||
private bool AcceptClient(object sender, X509Certificate certificate, X509Chain chain, | ||
SslPolicyErrors sslPolicyErrors) | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Server/ICreateStream.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters