Skip to content

Commit

Permalink
xs2c-0.2.1
Browse files Browse the repository at this point in the history
- updated StreamMessage
- improved presence list handling
  • Loading branch information
IxiAngel committed Aug 23, 2019
1 parent 9e99615 commit 45e6df7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 43 deletions.
2 changes: 1 addition & 1 deletion IxianS2/Meta/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Config
public static string externalIp = "";

// Read-only values
public static readonly string version = "xs2c-0.2.0a"; // S2 Node version
public static readonly string version = "xs2c-0.2.1"; // S2 Node version

public static readonly int maximumStreamClients = 100; // Maximum number of stream clients this server can accept

Expand Down
14 changes: 2 additions & 12 deletions IxianS2/Network/NetworkProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ public static void parseProtocolMessage(ProtocolMessageCode code, byte[] data, R
}
break;

case ProtocolMessageCode.presenceList:
/*case ProtocolMessageCode.presenceList:
{
Logging.info("Receiving complete presence list");
PresenceList.syncFromBytes(data);
}
break;
break;*/

case ProtocolMessageCode.updatePresence:
{
Expand All @@ -166,16 +166,6 @@ public static void parseProtocolMessage(ProtocolMessageCode code, byte[] data, R
{
byte[] address = null;
bool updated = PresenceList.receiveKeepAlive(data, out address, endpoint);

// If a presence entry was updated, broadcast this message again
if (updated)
{
CoreProtocolMessage.broadcastProtocolMessage(new char[] { 'M', 'R', 'H', 'W' }, ProtocolMessageCode.keepAlivePresence, data, address, endpoint);

// Send this keepalive message to all connected clients
CoreProtocolMessage.broadcastEventDataMessage(NetworkEvents.Type.keepAlive, address, ProtocolMessageCode.keepAlivePresence, data, address, endpoint);
}

}
break;

Expand Down
76 changes: 46 additions & 30 deletions IxianS2/Network/StreamMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public StreamMessage(byte[] bytes)
int sig_length = reader.ReadInt32();
if (sig_length > 0)
sigdata = reader.ReadBytes(sig_length);

encrypted = reader.ReadBoolean();
sigEncrypted = reader.ReadBoolean();
}
}
}
Expand All @@ -111,52 +114,65 @@ public byte[] getBytes()
writer.Write((int)encryptionType);

// Write the sender
int sender_length = sender.Length;
writer.Write(sender_length);

if (sender_length > 0)
if (sender != null)
{
writer.Write(sender.Length);
writer.Write(sender);
}
else
{
writer.Write(0);
}


// Write the recipient
int recipient_length = recipient.Length;
writer.Write(recipient_length);

if (recipient_length > 0)
if (recipient != null)
{
writer.Write(recipient.Length);
writer.Write(recipient);
}
else
{
writer.Write(0);
}


// Write the data
int data_length = data.Length;
writer.Write(data_length);

if (data_length > 0)
if (data != null)
{
writer.Write(data.Length);
writer.Write(data);
}
else
{
writer.Write(0);
}

// Write the tx
int tx_length = transaction.Length;
writer.Write(tx_length);

if (tx_length > 0)
if (transaction != null)
{
writer.Write(transaction.Length);
writer.Write(transaction);
}
else
{
writer.Write(0);
}


// Write the sig
int sig_length = sigdata.Length;
writer.Write(sig_length);

if (sig_length > 0)
if (sigdata != null)
{
writer.Write(sigdata.Length);
writer.Write(sigdata);
}
else
{
writer.Write(0);
}

writer.Write(encrypted);
writer.Write(sigEncrypted);

}
return m.ToArray();
Expand Down Expand Up @@ -188,15 +204,10 @@ public bool encrypt(byte[] public_key, byte[] aes_password, byte[] chacha_key)

public bool decrypt(byte[] private_key, byte[] aes_key, byte[] chacha_key)
{
if (sigEncrypted)
{
return true;
}
byte[] decrypted_data = _decrypt(data, private_key, aes_key, chacha_key);
if (decrypted_data != null)
{
data = decrypted_data;
sigEncrypted = true;
return true;
}
return false;
Expand All @@ -205,10 +216,15 @@ public bool decrypt(byte[] private_key, byte[] aes_key, byte[] chacha_key)
// Encrypts a provided signature with aes, then chacha based on the keys provided
public bool encryptSignature(byte[] public_key, byte[] aes_password, byte[] chacha_key)
{
if (sigEncrypted)
{
return true;
}
byte[] encrypted_data = _encrypt(sigdata, public_key, aes_password, chacha_key);
if (encrypted_data != null)
{
sigdata = encrypted_data;
sigEncrypted = true;
return true;
}
return false;
Expand All @@ -231,8 +247,8 @@ private byte[] _encrypt(byte[] data_to_encrypt, byte[] public_key, byte[] aes_ke
{
if (aes_key != null && chacha_key != null)
{
byte[] aes_encrypted = CryptoManager.lib.decryptDataAES(data_to_encrypt, aes_key);
byte[] chacha_encrypted = CryptoManager.lib.decryptWithChacha(aes_encrypted, chacha_key);
byte[] aes_encrypted = CryptoManager.lib.encryptWithAES(data_to_encrypt, aes_key, true);
byte[] chacha_encrypted = CryptoManager.lib.encryptWithChacha(aes_encrypted, chacha_key);
return chacha_encrypted;
}
else
Expand All @@ -244,7 +260,7 @@ private byte[] _encrypt(byte[] data_to_encrypt, byte[] public_key, byte[] aes_ke
{
if (public_key != null)
{
return CryptoManager.lib.decryptWithRSA(data_to_encrypt, public_key);
return CryptoManager.lib.encryptWithRSA(data_to_encrypt, public_key);
}
else
{
Expand All @@ -265,7 +281,7 @@ private byte[] _decrypt(byte[] data_to_decrypt, byte[] private_key, byte[] aes_k
if (aes_key != null && chacha_key != null)
{
byte[] chacha_decrypted = CryptoManager.lib.decryptWithChacha(data_to_decrypt, chacha_key);
byte[] aes_decrypted = CryptoManager.lib.decryptDataAES(chacha_decrypted, aes_key);
byte[] aes_decrypted = CryptoManager.lib.decryptWithAES(chacha_decrypted, aes_key, true);
return aes_decrypted;
}
else
Expand All @@ -286,7 +302,7 @@ private byte[] _decrypt(byte[] data_to_decrypt, byte[] private_key, byte[] aes_k
}
else
{
Logging.error("Cannot decrypt message, invalid encryption type {0} was specified.", encryptionType);
Logging.error("Cannot decrypt message, invalid decryption type {0} was specified.", encryptionType);
}
return null;
}
Expand Down

0 comments on commit 45e6df7

Please sign in to comment.