Skip to content

Conversation

@futrime
Copy link
Owner

@futrime futrime commented Apr 16, 2025

What does this PR do?

Which issues does this PR resolve?

Checklist before merging

Thank you for your contribution to the repository.
Before submitting this PR, please make sure:

  • Your code builds clean without any errors or warnings
  • Your code follows our code style
  • You have tested all functions
  • You have not used code without license
  • You have added statement for third-party code

Pd233 and others added 27 commits January 11, 2025 22:24
// Send password
using var rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(rsaPublicKey.Key);
await _sender!.SendPacketAsync(ConnectionVerifyPackets.Password, new PasswordPacket { PasswordData = rsa.Encrypt(_hashedPassword, false) }, false, token);

Check failure

Code scanning / CodeQL

Weak encryption: inadequate RSA padding High

Enable RSA padding.

Copilot Autofix

AI 9 months ago

To fix the problem, we need to replace the insecure PKCS#1 v1.5 padding with the more secure PKCS#1 v2 (OAEP) padding. This involves changing the rsa.Encrypt method call to use OAEP padding.

  • Update the rsa.Encrypt method call to use OAEP padding by passing true instead of false.
  • Ensure that the decryption process also uses OAEP padding by updating the rsa.Decrypt method call accordingly.
Suggested changeset 1
Lip.Connection/Connection.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Lip.Connection/Connection.cs b/Lip.Connection/Connection.cs
--- a/Lip.Connection/Connection.cs
+++ b/Lip.Connection/Connection.cs
@@ -195,3 +195,3 @@
         rsa.FromXmlString(rsaPublicKey.Key);
-        await _sender!.SendPacketAsync(ConnectionVerifyPackets.Password, new PasswordPacket { PasswordData = rsa.Encrypt(_hashedPassword, false) }, false, token);
+        await _sender!.SendPacketAsync(ConnectionVerifyPackets.Password, new PasswordPacket { PasswordData = rsa.Encrypt(_hashedPassword, RSAEncryptionPadding.OaepSHA1) }, false, token);
 
@@ -212,3 +212,3 @@
         //if (type is not ConnectionVerifyPackets.AesKey) throw new InvalidOperationException("Failed to recive aes key.");
-        byte[] key = _cryptoServiceProvider.Decrypt(aesKeyPacket.Key, false);
+        byte[] key = _cryptoServiceProvider.Decrypt(aesKeyPacket.Key, RSAEncryptionPadding.OaepSHA1);
 
EOF
@@ -195,3 +195,3 @@
rsa.FromXmlString(rsaPublicKey.Key);
await _sender!.SendPacketAsync(ConnectionVerifyPackets.Password, new PasswordPacket { PasswordData = rsa.Encrypt(_hashedPassword, false) }, false, token);
await _sender!.SendPacketAsync(ConnectionVerifyPackets.Password, new PasswordPacket { PasswordData = rsa.Encrypt(_hashedPassword, RSAEncryptionPadding.OaepSHA1) }, false, token);

@@ -212,3 +212,3 @@
//if (type is not ConnectionVerifyPackets.AesKey) throw new InvalidOperationException("Failed to recive aes key.");
byte[] key = _cryptoServiceProvider.Decrypt(aesKeyPacket.Key, false);
byte[] key = _cryptoServiceProvider.Decrypt(aesKeyPacket.Key, RSAEncryptionPadding.OaepSHA1);

Copilot is powered by AI and may make mistakes. Always verify output.
using var rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(rsaPublicKey.Key);
byte[] key = Guid.NewGuid().ToByteArray();
await _sender.SendPacketAsync(ConnectionVerifyPackets.AesKey, new AESKeyPacket { Key = rsa.Encrypt(key, false) }, false, token);

Check failure

Code scanning / CodeQL

Weak encryption: inadequate RSA padding High

Enable RSA padding.

Copilot Autofix

AI 9 months ago

To fix the problem, we need to change the padding scheme used in the RSA encryption from PKCS#1 v1.5 to PKCS#1 v2 (OAEP). This involves modifying the rsa.Encrypt method call to use OAEP padding.

  • Update the rsa.Encrypt method call to use OAEP padding by passing true instead of false.
  • Ensure that the rest of the code remains unchanged to maintain existing functionality.
Suggested changeset 1
Lip.Connection/Connection.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/Lip.Connection/Connection.cs b/Lip.Connection/Connection.cs
--- a/Lip.Connection/Connection.cs
+++ b/Lip.Connection/Connection.cs
@@ -252,3 +252,3 @@
         byte[] key = Guid.NewGuid().ToByteArray();
-        await _sender.SendPacketAsync(ConnectionVerifyPackets.AesKey, new AESKeyPacket { Key = rsa.Encrypt(key, false) }, false, token);
+        await _sender.SendPacketAsync(ConnectionVerifyPackets.AesKey, new AESKeyPacket { Key = rsa.Encrypt(key, RSAEncryptionPadding.OaepSHA1) }, false, token);
 
EOF
@@ -252,3 +252,3 @@
byte[] key = Guid.NewGuid().ToByteArray();
await _sender.SendPacketAsync(ConnectionVerifyPackets.AesKey, new AESKeyPacket { Key = rsa.Encrypt(key, false) }, false, token);
await _sender.SendPacketAsync(ConnectionVerifyPackets.AesKey, new AESKeyPacket { Key = rsa.Encrypt(key, RSAEncryptionPadding.OaepSHA1) }, false, token);

Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants