Nerdy Bunz
Nerdy Bunz

Reputation: 7437

Primitive Diffie-Hellman cryptography for app-server exchange

Working on an app that lets a user call someone by clicking on them. After the call, a new activity is started, FeedbackActivity, where the user enters feedback regarding the person they called which is uploaded and the server crunches the numbers over time and produces a "rating."

However, the app does not have a traditional "log in and password" behavior... (and it is important that it does not have this) so there is nothing preventing a user from maliciously entering negative feedback over and over again... or worse, loading

http://www.example.com/feedback.php?personICalled=334875634&feedback=blahblahblah

into a browser and just reloading it over and over again.

So, we need to make sure that people can only give feedback on someone that have actually called.

I had the idea of having some sort of "token" be sent to the server when the user clicks "call." Then the server saves this token.

then, when they subsequently upload feedback, it would look like:

http://www.example.com/feedback.php?personICalled=334875634&feedback=blahblahblah,&token=[same token sent prior]

This way, the server checks that such a token was ever saved, and if so, then it saves the feedback, otherwise not.

Or, better yet, there could be a secret formula known only to the server (and the app), whereby [token checked upon feedback given] is a (complex mathematical) function of [token uploaded at phone call time].

But, obviously this wouldn't be that hard for someone to figure out by looking at app source code, or observing the y=f(x) relationship over time and figuring out the formula... and there has to be a better way to do this.

I read about the Diffie-Hellman key exchange... and it seems to me there must be a way of implementing this for this purpose... but I'm not a Harvard graduate and it been a while since discrete math... and I'm not particularly knowledgable about cryptography... and the wiki page makes me head hurt!!!!

Take this diagram, for example Can you explain ZAT??

If anyone could tell me how the terms "Common paint," "Secret Colors," "Public Transport" and "Common Secret" translate to my scenario, I think I might just be able to figure this out.

I'm guessing that Public Transport = internet... I've got that far.

Upvotes: 0

Views: 308

Answers (1)

TheGreatContini
TheGreatContini

Reputation: 6629

First thing, Diffie Hellman is not going to solve your problem. There are a ton of things that can go wrong in crypto, so dont play with it unless you really know that you need it and know what you want it for.

What is your real requirement? A user should be able to enter feedback only one time per call. You do not need crypto to solve this.

When the user makes a call, generate a token. Send that token to the user and also store it in the database. When the call is finished, allow the user to "consume" the token by providing feedback associated with that token. The sever verifies that the token exists in the database (and has not already been consumed). Assuming it is there, accept the feedback and then remove the token from the database (it has been consumed). If it is not there, do not accept the feedback.

You can improve things by also storing a time with the token (the time it was generated). Don't let them provide feedback if they try to consume it too soon. Expire the tokens if they are not consumed after some max life period. This prevents people from repeatedly calling a user or tokens living indefinitely in your database (DoS).

You might also restrict people by IP address. Allow a user to receive only one rating from an IP address in any reasonable time period (one day). The IP addresses can be stored along with the feedback in the database.

Upvotes: 3

Related Questions