Determining if a request came from an iPhone app

风流意气都作罢 提交于 2019-12-11 23:32:45

问题


I have an iPhone app that communicates with a server (both of which I own and wrote the code for). I need to way to determine if a request on my server came from an iPhone (or any mobile device running the app I wrote for that matter). Basically, I only want to allow apps that I wrote to communicate with the server and need a way to verify that. Since I'm writing the apps, I can modify the headers and what not any way I need to.

I read up a little on Public Key Encryption, but I don't think it'd work. If I sent some sort of secret hashed word in my headers to verify it, couldn't some outside party simply get those headers and use the same ones in their request?


回答1:


You can use a checksum. Let's say that you have something like: date subject

and calculate the checksum by using, let's say MD5 of (date + "string" + subject), and you calculate the MD5 in the very same way on the server. If they match, they are from the mobile client.

This will work until someone figures out your algorithm.




回答2:


You could have your server send a message to your app that contains a random code. This message and code changes every time it is sent.

Your app then does some kind of algorithm on that message to "encrypt" it and send it back to the server and the server can then check it. That way there's nothing to intercept and use without knowing your "encryption".

Of course, they could intercept the message from each direction and then work out your algorithm, but if you make it sufficiently difficult, then that would be a while.




回答3:


You could just use HTTP Basic authentication, unless you needed something more secure.



来源:https://stackoverflow.com/questions/9331488/determining-if-a-request-came-from-an-iphone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!