开发者

Website API only for my android client

开发者 https://www.devze.com 2023-04-11 07:11 出处:网络
I want to develop an android ap开发者_如何学编程p for my website. One way of doing it is to have an API for the site, and let the app use that API. However i want this API to be used ONLY by my androi

I want to develop an android ap开发者_如何学编程p for my website. One way of doing it is to have an API for the site, and let the app use that API. However i want this API to be used ONLY by my android app, I don't want any other client to be using this API.

Is there a way to ensure this?

I can think of one way of doing it: put a secret in the app and let the app pass this secret always to the API. But i am not sure how secure this approach would be because any packet sniffer can easily sniff the parameters and hence the secret. Any other suggestions?


I think this is something similar to a question I answered a few days ago. Securing a REST API from Android

Namely, find a way to authenticate all of your requests using a shared secret.

If you sign both the path and params with a secret, then there should be no way for someone to forge requests.


Finally got hold of the answer from the android developer's blog article.


The short answer is no, sorry. If someone really wants to exploit your site/api/device/program/insert anything here and they have the time and resources then they will.

To directly answer your question, putting a key in your app isn't secure as anyone can decompile the app and try to reconstruct the key from the source files, they don't need to sniff traffic.


Correct me if I'm wrong! Packet sniffers can only be used with unencrypted WiFi and in (now) rare network configurations (a router or a switch prevent them).

For serious matters, you should consider secured connections (https).

That said, for standard content, I feel that a passphrase is secure enough. Many popular web apps don't use more than a cookie over http to let you log in, which is exactly what you're proposing.


I struggled with this issue and I actually ended up implementing a version of OAuth for securing my API. It can be difficult if you don't to launch a browser to do the "login" part of OAuth. I baked the login right into my my app and actually implemented the token exchanges under the covers. Too much involved to post the code here, but it works great. Obviously HTTPS is desired for an additional level of security.


If you could get some kind of signature back from package manager of your own app, you could use obfuscation to hopefully make it much more difficult, and have the signature/hash of signature from package manager be the key for your HMAC-SHA1.

Might have to try this ( How to get APK signing signature? )

If you did that, it would make it more difficult to use. Obviously, it could still be decompiled, but if they re-compiled it w/ debugging etc, it would have the wrong key. They would then have to actually make their own package manager on a rooted device to get the signature.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号