简体   繁体   English

iPhone和服务器之间的安全通信?

[英]Secure Communication Between iPhone and Server?

I'm developing an app which connects to an XML based API. 我正在开发一个连接到基于XML的API的应用程序。 I have control over both the server and the app - is there any way I can make sure only my app can access the API? 我可以控制服务器和应用程序 - 有什么方法可以确保只有我的应用程序才能访问API?

There is no user authentication. 没有用户身份验证。

EDIT: 编辑:

The main concern is that bots steal data by scanning the XML. 主要担心的是机器人通过扫描XML来窃取数据。

How about this: 这个怎么样:

I request a session with the device UDID and I get a handshake key. 我请求与设备UDID的会话,我得到一个握手密钥。

<handshake>23354</handshake>

from this string a password is calculated on both the server and the client according to an agreed algorithm (it just has to be hard to reconstruct) 从该字符串开始,根据约定的算法在服务器和客户端上计算密码(只需要很难重建)

Let's say for now that I add 1 to the handshake key 让我们说现在我将1添加到握手键

password = 23354

On all API calls I then pass this password along with the UDID. 在所有API调用中,我然后将此密码与UDID一起传递。 This would allow the server to limit each session to a certain number of calls, no? 这将允许服务器将每个会话限制为一定数量的呼叫,不是吗?

What do you think? 你怎么看?

No, it is not possible to really ensure that only your app can contact your server. 不,不可能真正确保只有您的应用可以联系您的服务器。 There are obfuscation techniques for raising the bar somewhat on attackers, and those will work for most attackers. 有一些混淆技术可以提高攻击者的攻击力,这些技术对大多数攻击者都有效。 Your underlying problem is not solvable for a dedicated attacker. 对于专门的攻击者而言,您的潜在问题无法解决。 You can find a list of other posts on this subject at iPhone: How to encrypt a string . 您可以在iPhone上找到有关此主题的其他帖子列表:如何加密字符串 There are several techniques you can use in those posts, and some discussion of how and whether you should attack the underlying issues. 您可以在这些帖子中使用几种技术,并讨论如何以及是否应该攻击基础问题。

You can provide a quick challenge response mechanism, assuming you have control over the XML api. 假设您可以控制XML API,则可以提供快速质询响应机制。

Generate a number and include it in your app and on the server side. 生成一个数字并将其包含在您的应用程序和服务器端。 Use that as a seed to srand() on both client and server. 将其用作客户端和服务器上srand()的种子。

Have the request from the client include something like: 请客户提出以下要求:

<handshake id="123">12312931</handshake>

there id means the 123'rd generated random number and 12312931 is the value after calling rand() 123 times. id表示123'生成的随机数,12312931是调用rand()123次后的值。 The value 123 should be a randomly generated number (generated with a different seed!) as well. 值123应该是随机生成的数字(用不同的种子生成!)。

This isn't a fool proof challenge response, but it's simple and efficient, and doesn't rely on anything more than a basic ANSI C library set. 这不是一个简单的挑战响应,但它简单而有效,并且不依赖于基本的ANSI C库集。

Note that it's not terribly secure, either - all one would have to do is have your client challenge their own server, then generate the (in this example) 123'rd random number for every seed value until they find it. 请注意,它也不是非常安全 - 所有人都要做的就是让你的客户端挑战他们自己的服务器,然后为每个种子值生成(在这个例子中)第123个随机数,直到找到它为止。 So I wouldn't use this expecting it to provide cryptographic level authentication or access control. 所以我不会用它来期望它提供加密级别身份验证或访问控制。 It just provides a simple non-trivial challenge response that is efficient and simple to implement. 它只是提供了一个简单易懂的挑战响应,该响应高效且易于实现。

You can use some sort of signature in order to verify that it is indeed your app making the call, you calculate the signature both server side and app side, only if they match will the service return with a response to the request. 您可以使用某种签名来验证它确实是您的应用程序进行调用,您计算服务器端和应用程序端的签名,只有当它们匹配时,服务才会返回响应请求。 Typically signatures are composed of some s ort of parameters of your function followed by a secret key, then take the md5 hash of that and sned it through. 通常,签名由函数的一些参数组成,后跟一个密钥,然后获取该密钥的md5哈希值并通过它。 In the r equest no one will be able to find the secret key because it is in the md5 hash. 在请求中,没有人能够找到密钥,因为它位于md5哈希中。

通过https访问您的Web服务并进行身份验证。

I think the real question you need to ask is how much is your data at risk of attack. 我认为您需要提出的真正问题是您的数据存在多大的攻击风险。 I'd say 99% of the time you'll be fine with just an obfuscated URL that will be hard to guess, since chances of the average user trying to do anything with it outside your app are slim. 我会说99%的时间你会很好,只是一个难以猜测的模糊URL,因为普通用户试图在你的应用程序之外做任何事情的机会很小。 If you're worried about competitors stealing from you, I'd suggest something a little more nefarious: 如果你担心竞争对手偷了你,我会建议一些更邪恶的东西:

In your app, set it up so that your app and server change URLs every so often, maybe every two weeks. 在您的应用中,进行设置,以便您的应用和服务器每隔一段时间(可能每两周)更改一次网址。 Then if someone does attempt to access your XML API, they'll be fighting a constant battle of figuring out your URLs. 然后,如果有人确实试图访问您的XML API,那么他们将不断争夺您的网址。 And as icing on the cake, keep the old URLs active but have them return bad data. 作为锦上添花,保持旧URL活跃但让它们返回错误的数据。 I think you can let your imagination run and figure out the rest from here. 我想你可以让你的想象力从这里开始并从中找出其余部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM