How to authenticate native application against a Web Service?

146 views Asked by At

I need to find a solution to make sure my app, which will be distributed as a native App on mobile devices, and ONLY my app can acces my Web Service hosted some place else. In other words, my Web Service should only accept request through legitimate usage of my application, on not by any other means.

The solution i thought about is the following, please tell me if you think there is a better one, or if this one is not adequate:

Counter-Synchronyzed One Time Passwords (CS-OTPs): The basic idea is that each side (the WS and the App) holds a hard-coded secret key, and a synchronized counter. Each time the client app sends a request to the WS, it produces a hash with the secret key and the counter value. The back-end WS does the same and compares the hashes, if they are identical, the authentication succeeds, and both sides increment theirs counters to keep them synchronized. Since the counter is incremented after every successful attempt, the hash will each time be different (thus the name 'One time password').

Why do I think I need a one-time password? Because if the password, or the hash, stays identical, it could be intercepted very easily by the client App user, which could then forge request by himself without the need of the App.

Tell me what you think about that solution.

2

There are 2 answers

0
Anthony On

Many ways to achieve this, my method is to create an encrypted token from the client to server using a secret key as you suggest. I would also include in this encrypted key some information that will aid validation. Include things like IP address, expirey date/time, current time etc. So someone trying to replay traffic would have to come from the same ip address, within a certain time period etc. YOu can vary to suit your own needs. Hope this helps.

0
Grzegorz Kazior On

I believe as long as a native application is under control of hacker, he may debug your application and steel your secret. No matter what the secret is. If you give the secret, you give it to the person not to the application.

You may give a unique secret to each instance of the application, then at you may block sb. who behaves strange. This gives you kind of authentication.

You may try to mangle the code to make hacking harder, but it is only the additional cost for the hacker. However "only" may be enough.