1
0
mirror of https://github.com/Ylianst/MeshCentralRouter synced 2025-12-06 00:13:33 +00:00

Added WebSocket masking.

This commit is contained in:
Ylian Saint-Hilaire
2021-06-09 22:33:58 -07:00
parent 91432389b8
commit 3b720c081b

View File

@@ -62,6 +62,7 @@ namespace MeshCentralRouter
public long PendingSendLength { get { return (pendingSendBuffer == null)? 0 : pendingSendBuffer.Length; } }
private bool readPaused = false;
private bool shouldRead = false;
private RNGCryptoServiceProvider CryptoRandom = new RNGCryptoServiceProvider();
// Outside variables
public object tag = null;
@@ -644,6 +645,12 @@ namespace MeshCentralRouter
// Check that everything is ok
if (len < 0) { Dispose(); return 0; }
// Set the mask to a cryptographic random value and XOR the data
byte[] rand = new byte[4];
CryptoRandom.GetBytes(rand);
Array.Copy(rand, 0, buf, 10, 4);
for (int x = 0; x < len; x++) { buf[x + 14] ^= rand[x % 4]; }
if (len < 126)
{
// Small fragment