Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INTERNAL][CORE] Adds Socks5 proxy connection encryption #1069

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

srossbach
Copy link
Contributor

This patch will now encrypt non mediated Socks 5 connection because the
SMACK API do not offer it.

The encryption is currently done with RSA and RC4 although RC4 should be
replaced. This patch includes some randomization that makes sniffing RC4
sessions harder.

This patch will now encrypt non mediated Socks 5 connection because the
SMACK API do not offer it.

The encryption is currently done with RSA and RC4 although RC4 should be
replaced. This patch includes some randomization that makes sniffing RC4
sessions harder.
@srossbach srossbach requested review from m273d15 and tobous July 27, 2020 21:11
@saros-infrastructure
Copy link

Codacy Here is an overview of what got changed by this pull request:

Complexity increasing per file
==============================
- core/test/junit/saros/net/stream/SecureByteStreamTest.java  4
- core/src/saros/net/stream/SecureByteStream.java  4
         

See the complete overview on Codacy

final DataOutputStream encryptedOutputStream = new DataOutputStream(rc4CipherOutputStream);
random.nextBytes(garbageData);

encryptedOutputStream.writeInt(garbageDataSize);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing the local inputstream and the remote outputstream.

@@ -401,7 +401,7 @@ private IByteStreamConnection acceptNewRequest(BytestreamRequest request)
localAddress,
new JID(peer),
connectionIdentifier,
new XMPPByteStreamAdapter(inSession),
SecureByteStream.wrap(new XMPPByteStreamAdapter(inSession), false),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Catch IO exception, close the Stream and then rethrow the exception.

@tobous
Copy link
Member

tobous commented Jul 30, 2020

As I am not well versed with the network stuff and he already had a look a it earlier on, I would like @stefaus to have a look at it. But, as he is currently a little preoccupy, this might take a while.

@tobous tobous requested a review from stefaus July 30, 2020 14:32
@srossbach
Copy link
Contributor Author

There is no XEP for encryption regarding Socks5 or Jingle yet. So there is no support for this even in the newest Smack version.

@srossbach srossbach added Area: Core Issue affecting the Saros Core Aspect: Network Issue with Saros' network layer Breaks Compatibility Change breaking compatibility with previous releases labels Jul 31, 2020
Copy link
Contributor

@stefaus stefaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is missing authentication of the clients, allowing man in the middle attacks. This could be mitigated via xmpp messages for pubkey exchange.


// send garbage to avoid RC4 attacks/sniffing

final Random random = new Random();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random is just a pseudo random generator and not suitable here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the fix would be ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you marked this as resolved?

A fix would be to use a cryptographically strong random number generator like SecureRandom

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You suggested to not use RC4 and so the whole logic can be discarded.


final SecretKey rc4SecretKey = new SecretKeySpec(rc4KeyData, "RC4");

final Cipher rc4CipherOut = Cipher.getInstance("RC4");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RC4 is a broken Cipher and shouldn't be used, see https://tools.ietf.org/html/rfc7465

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can switch to AES

Copy link
Contributor Author

@srossbach srossbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The man in the middle attack could also be done through a compromised XMPP server. I do not see any reason to transmit the keys through another (unsafe) channel.


// send garbage to avoid RC4 attacks/sniffing

final Random random = new Random();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the fix would be ?

Copy link
Contributor

@stefaus stefaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The man in the middle attack could also be done through a compromised XMPP server. I do not see any reason to transmit the keys through another (unsafe) channel.

It makes a difference.

  1. Compromising a XMPP-Server is way more difficult.
  2. Transmission to the XMPP-Server is encrypted and authenticated against a publickey signed by a "trusted" authority / manually validated.
  3. Even if the XMPP-Server is compromised, this byte stream is not passing the XMPP-Server. The Attacker has to control the Server and a network on the direct transmission path. This is not the basic public wifi scenario.

Depending on how everything works out, I still plan to do a more comprehensive security approach as part of my master thesis.


// send garbage to avoid RC4 attacks/sniffing

final Random random = new Random();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you marked this as resolved?

A fix would be to use a cryptographically strong random number generator like SecureRandom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Core Issue affecting the Saros Core Aspect: Network Issue with Saros' network layer Breaks Compatibility Change breaking compatibility with previous releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants