UDP Security and Incoming Identity

I am creating an application that uses UDP to send and receive information. The problem I am facing is security. Right now I am using IP / socketid to determine which data belongs to whom.

However, I read about how people can simply spoof their IP address and then just send the data as a specific IP address. So this seems to be the wrong way to do this (unsafe). So, how else can I determine which data belongs to those users? For example, you have 10 users, all have specific data. The server will need to match the user data with the data we received.

The only way I can do this is to use some kind of client / server key system and encrypt the data. I am curious how other applications (or games, ever since this application) make sure their data is authentic. There is also the fact that encryption takes much longer than unencrypted. Although I'm not sure how much this will affect performance.

Any information would be appreciated. Thanks.

+7
python security cryptography udp encryption
source share
6 answers

One solution is to use TCP because it is immune to faking the source address over the open Internet due to a three - way handshake ( More information on why merging the TCP source URL is not possible .). If you still want to use UDP, you can have a simulated three-way handshake to start the connection. Session ID can be added to each UDP packet. This will increase the connection overhead by 2 packets and a few bits per packet, however, you will still get the UDP speed for the rest of the session compared to tcp.

However, using TCP or UDP as the transport layer still leaves you open to other attacks, such as Sniffing and Man in the Center , using arp spoofing or dns cache poising . Another problem is that both the attacker and the gamers are on the same local computer, such as a wireless network or another broadcast network, then you can receive traffic, regardless of the source / address, and ONLY a three-way handshake is replaced maybe (and hmac can't help!). The best solution is to use SSL / TLS as your transport layer, which solves all these problems.

You should not reinvent wheal, but if you need to encrypt UDP, for some reason you should use Stream Cipher, such as RC4-drop1024, or even better, such as Block Cipher, such as AES 256, in OFB mode . This will save bandwidth compared to other encryption modes, since they are rounded to the maximum block size.

EDIT: Based on Marts comments for (Datagram Transport Layer Security) DTLS, I did some digging and I found that there is an official pyOpenSSL . I recommend using the RC4-SHA cipher suite to reduce overhead; this package is supported by SSL 3.0 (latest). However, DTLS will likely have more overhead (LAG!), And then TCP.

+4
source share

You can watch hmac

Wikipedia:

In HMAC cryptography (Hash-based Message Authentication Code), there is a specific design for calculating a message authentication code (MAC) using a cryptographic hash function in combination with a secret key. As with any MAC, it can be used to simultaneously verify the integrity and authenticity of a message.

Each client will need to receive a unique token that only they know. Each message they send, they will create a hash based on the token and message and send it along with the message itself. You can then verify that the message came from a specific client.

+1
source share

If you absolutely need to verify that a specific user is a specific user, you need to use some form of encryption when the user signs their messages. This can be done quite quickly, because the user needs to generate a hash of his message, and then sign (encrypt) the hash.

For your gaming application, you probably don't need to worry about that. Most Internet service providers will not allow their users to spoof IP addresses, so you only need to worry about users for NAT, in which you can have multiple users working from the same IP address. In this case and in the general case, you can safely identify unique users based on a tuple containing the IP address and UDP port.

0
source share

DTLS is probably the best solution, however it looks very poorly documented. I searched for a similar solution for a while, and all the links that I saw on the OpenSSL DTLS implementation show that you will need to dig through OpenSSL examples and source code to figure out how to use it ... which, for me, means that i am going to make 10 serious security errors when i try to configure it. Also, I don't think pyOpenSSL libary exports this functionality.

An alternative that I considered is Secure Remote Password Protocol . The advantage of this solution is that it gives you strong mutual authentication (along with Kerberos security as documented) and, which is also important in your case, provides both ends with a shared session key that can be used for encryption,

Given a shared key, each packet may contain AES256_CBC( <random starter block for CBC><user-id><sequence_number><application data> ) . If decryption succeeds in providing the expected user ID, the packet is authenticated as outgoing from your user, and the sequence number can be used to prevent repeated attacks.

One drawback of SRP is that in Python, the number of crunches is rather slow. I changed the Python demo code to something more convenient and found that it took about 300 ms to complete a single SRP client server (2 GHz processor). However, a straightforward C ++ implementation of the SRP algorithm using BigNumber support in OpenSSL took only 2 ms. Therefore, if you intend to take this route, I highly recommend using an implementation of the algorithm to create code in C / C ++. Otherwise, you will probably be able to process multiple logins per second.

0
source share

I break it down into four levels of security.

  • Extremely unsafe - any network user can spoof a valid request / response with publicly available prior knowledge. (i.e. syslog)

  • Very Insecure - any network user can fake a valid request / response only if they have at least read access to the wire. (Passive MITM) (i.e.Http-accessible forum with browser cookies)

  • Some unsafe - any network user can fake a valid request / response if he can read and make changes to the wire (active MITM) (i.e. https site with a self-signed certificate)

  • Security - requests / responses cannot be faked even with full access to the wire. (i.e. https accessible e-commerce site)

For online games, a very unsafe solution can be really acceptable (this will be my choice). It does not require cryptography. Just a field in your packet of UDP packets of your application with some random almost indescribable session identifier redirected to the game.

To some extent, unsafe requires a bit of cryptography, but none of the trusted / PKI / PSKs are needed to protect the Active-MITM secure solution. If several invalid data is not sensitive to data, you can only use integrity encryption with DTLS (TDP) TLS / (UDP) to reduce overhead and delays on the client and server.

For games, UDP is a huge advantage, because if there is packet loss, you don’t want the IP stack to waste time relaying outdated state - you want to send a new state. There are many smart schemes with UDP, such as invalid frames (world data that are not so important if they are lost) and statistical methods for duplicating important state data to counter the predicted levels of observed packet loss.

At the end of the day, I would recommend being very insecure or somewhat insecure / w DTLS integrity.

0
source share

I would look into the Garage Games network library. It is written in C ++ and uses UDP. It is designed for low latency and is considered one of the best for games.

If I remember correctly, they would really calculate the likely position of the player both on the client side and on the server side. This would do this for many aspects to ensure data integrity. He would also do a crc check on the client software and compare it with the server software to make sure they match.

I'm not sure that you can license it separately, so you may have to license the game engine (100 bucks). This will at least give you some insight into the proven UDP approach for games. Another option is to search for PyGame network code. Perhaps he has already addressed the problems you are facing.

0
source share

All Articles