Skip to content

Commit 72c3652

Browse files
committed
Added new hail message pair to handle X509 certificates
1 parent 05cf6bd commit 72c3652

File tree

5 files changed

+331
-132
lines changed

5 files changed

+331
-132
lines changed

MLAPI/Data/MLAPIConstants.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@ public static class MLAPIConstants
88
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
99
public const string MLAPI_PROTOCOL_VERSION = "2.1.0";
1010

11+
12+
public const byte MLAPI_CERTIFICATE_HAIL = 23;
13+
public const byte MLAPI_CERTIFICATE_HAIL_RESPONSE = 25;
14+
1115
public const byte MLAPI_CONNECTION_REQUEST = 0;
1216
public const byte MLAPI_CONNECTION_APPROVED = 1;
17+
18+
1319
public const byte MLAPI_ADD_OBJECT = 2;
1420
public const byte MLAPI_CLIENT_DISCONNECT = 3;
1521
public const byte MLAPI_DESTROY_OBJECT = 4;

MLAPI/Data/NetworkConfig.cs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using MLAPI.Serialization;
77
using MLAPI.Transports;
88
using BitStream = MLAPI.Serialization.BitStream;
9+
using System.Security.Cryptography.X509Certificates;
910

1011
namespace MLAPI.Configuration
1112
{
@@ -116,24 +117,6 @@ public class NetworkConfig
116117
/// </summary>
117118
public bool HandleObjectSpawning = true;
118119
/// <summary>
119-
/// Wheter or not to enable encryption
120-
/// </summary>
121-
public bool EnableEncryption = false;
122-
/// <summary>
123-
/// Wheter or not to enable signed diffie hellman key exchange.
124-
/// </summary>
125-
public bool SignKeyExchange = false;
126-
/// <summary>
127-
/// Private RSA XML key to use for signing key exchange
128-
/// </summary>
129-
[TextArea]
130-
public string RSAPrivateKey = "<RSAKeyValue><Modulus>vBEvOQki/EftWOgwh4G8/nFRvcDJLylc8P7Dhz5m/hpkkNtAMzizNKYUrGbs7sYWlEuMYBOWrzkIDGOMoOsYc9uCi+8EcmNoHDlIhK5yNfZUexYBF551VbvZ625LSBR7kmBxkyo4IPuA09fYCHeUFm3prt4h6aTD0Hjc7ZsJHUU=</Modulus><Exponent>EQ==</Exponent><P>ydgcrq5qLJOdDQibD3m9+o3/dkKoFeCC110dnMgdpEteCruyBdL0zjGKKvjjgy3XTSSp43EN591NiXaBp0JtDw==</P><Q>7obHrUnUCsSHUsIJ7+JOrupcGrQ0XaYcQ+Uwb2v7d2YUzwZ46U4gI9snfD2J0tc3DGEh3v3G0Q8q7bxEe3H4aw==</Q><DP>L34k3c6vkgSdbHp+1nb/hj+HZx6+I0PijQbZyolwYuSOmR0a1DGjA1bzVWe9D86NAxevgM9OkOjG8yrxVIgZqQ==</DP><DQ>OB+2gyBuIKa2bdNNodrlVlVC2RtXnZB/HwjAGjeGdnJfP8VJoE6eJo3rLEq3BG7fxq1xYaUfuLhGVg4uOyngGQ==</DQ><InverseQ>o97PimYu58qH5eFmySRCIsyhBr/tK2GM17Zd9QQPJZRSorrhIJn1m6gwQ/G5aJLIM/3Yl04CoyqmQGsPXMzW2w==</InverseQ><D>CxAR1i22w4vCquB7U0Pd8Nl9R2Wxez6rHTwpnoszPB+rkAzlqKj7e5FMgpykhoQfciKPyWqQZKkAeTMIRbN56JinvpAt5POId/28HDd5xjGymHE81k3RzoHqzQXFIOF1TSYKUWzjPPF/TU4nn7auD4i6lOODATsMqtLr5DRBN/0=</D></RSAKeyValue>"; //CHANGE THESE FOR PRODUCTION!
131-
/// <summary>
132-
/// Public RSA XML key to use for signing key exchange
133-
/// </summary>
134-
[TextArea]
135-
public string RSAPublicKey = "<RSAKeyValue><Modulus>vBEvOQki/EftWOgwh4G8/nFRvcDJLylc8P7Dhz5m/hpkkNtAMzizNKYUrGbs7sYWlEuMYBOWrzkIDGOMoOsYc9uCi+8EcmNoHDlIhK5yNfZUexYBF551VbvZ625LSBR7kmBxkyo4IPuA09fYCHeUFm3prt4h6aTD0Hjc7ZsJHUU=</Modulus><Exponent>EQ==</Exponent></RSAKeyValue>"; //CHANGE THESE FOR PRODUCTION!
136-
/// <summary>
137120
/// Wheter or not to enable scene switching
138121
/// </summary>
139122
public bool EnableSceneSwitching = true;
@@ -145,6 +128,40 @@ public class NetworkConfig
145128
/// Decides how many bytes to use for Attribute messaging. Leave this to 2 bytes unless you are facing hash collisions
146129
/// </summary>
147130
public AttributeMessageMode AttributeMessageMode = AttributeMessageMode.WovenTwoByte;
131+
/// <summary>
132+
/// Wheter or not to enable encryption
133+
/// </summary>
134+
[Header("Cryptography")]
135+
public bool EnableEncryption = false;
136+
/// <summary>
137+
/// Wheter or not to enable signed diffie hellman key exchange.
138+
/// </summary>
139+
public bool SignKeyExchange = false;
140+
[TextArea]
141+
public string ServerCertificatePfx;
142+
public X509Certificate2 ServerX509Certificate
143+
{
144+
get
145+
{
146+
return serverX509Certificate;
147+
}
148+
internal set
149+
{
150+
serverX509CertificateBytes = null;
151+
serverX509Certificate = value;
152+
}
153+
}
154+
private X509Certificate2 serverX509Certificate;
155+
public byte[] ServerX509CertificateBytes
156+
{
157+
get
158+
{
159+
if (serverX509CertificateBytes == null)
160+
serverX509CertificateBytes = ServerX509Certificate.Export(X509ContentType.Cert);
161+
return serverX509CertificateBytes;
162+
}
163+
}
164+
private byte[] serverX509CertificateBytes = null;
148165

149166
private void Sort()
150167
{

0 commit comments

Comments
 (0)