I know that this question has been asked in various forms before. However, I'm not looking for the "use https" answer. I'm already using HTTPS and I'm not worried about the sensitivity of the payload being transmitted back and forth.
However, an iPhone application that I am working on is talking to a REST API that I have built (I have control of the application and server - so any suggestions are welcome).
I use the OAuth2 protocol for authentication, which means that my "API key" is a combination of a Client ID and Client Secret that only need to be transmitted to acquire an access_token
. After that, all requests are sent to the server using the access_token
and a header containing an HMAC of the request body (using the client secret as a key). The only reason for this addition was so that someone couldn't make API requests with JUST an access_token
.
The API that I'm talking to is going to be made public when I release the application. So I'm not necessarily worried about others being able to make API calls to it.
What I care about is:
My guess is that there's not really a solution to this problem (other than using UIWebView and making a glorified webapp) but I thought I would ask around here anyway.
Can you all think of a way to protect the client ID/client secret if it needs to be consumed by the app?
I know this isn't the answer you were hoping for, but unfortunately I don't think you can accomplish your objectives with absolute assurance. At the end of the day, you can't trust a client which you don't control, and you don't control it once it leaves your hands.
In order to achieve your two objectives, you need to verify that the client accessing the API was written by you. The way to do this is using public/private keys pairs. You would need to embed a private key into the client that it can use to sign something. This way the server knows the request came from your client and not someone else's. This would also allow you to restrict certain calls to only your client.
However, this is not bullet-proof because a savvy user could reverse engineer and extract the private key from your app and use it to spoof the source. Although not bullet-proof, it is bullet resistant because doing that would require A LOT of work and would be highly technical, especially if you use anti-RE techniques like buffer smearing, mass red-herrings, etc.
If I were you, I would ask myself what type of damage would result if someone for sure hacked it. If you are Facebook it is catastrophic. If you are serving an internal organization it may not be a big deal at all. If you can't afford a single abuse, then you need to reconsider your design because this one isn't going to work. You simply cannot trust code that you don't control, and you don't control the client anymore once it's on someone else's device.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With