简体   繁体   English

在iPhone应用程序中使用REST API时的安全性

[英]Security When Using REST API in an iPhone Application

I know that this question has been asked in various forms before. 我知道以前曾以各种形式提出过这个问题。 However, I'm not looking for the "use https" answer. 但是,我不是在寻找“使用https”的答案。 I'm already using HTTPS and I'm not worried about the sensitivity of the payload being transmitted back and forth. 我已经在使用HTTPS了,我并不担心有效载荷来回传输的敏感性。

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). 但是,我正在处理的iPhone应用程序正在与我构建的REST API进行通信(我已经控制了应用程序和服务器 - 因此欢迎任何建议)。

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 . 我使用OAuth2协议进行身份验证,这意味着我的“API密钥”是客户端ID和客户端密钥的组合, 需要传输以获取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). 之后,使用access_token和包含请求主体的HMAC的标头(使用客户机密钥作为密钥)将所有请求发送到服务器。 The only reason for this addition was so that someone couldn't make API requests with JUST an access_token . 这种添加的唯一原因是,有人无法使用JUST access_token发出API请求。

The API that I'm talking to is going to be made public when I release the application. 我正在谈论的API将在我发布应用程序时公开。 So I'm not necessarily worried about others being able to make API calls to it. 所以我不一定担心别人能够对它进行API调用。

What I care about is: 我关心的是:

  • People being able to make API calls using my application's client credentials (which means that I can't detect on the server side that it didn't come from my application) 人们可以使用我的应用程序的客户端凭据进行API调用(这意味着我无法在服务器端检测到它不是来自我的应用程序)
  • People being able to abuse the additional scopes that my client ID will allow them to have, and traditional API users will not have 人们可以滥用我的客户ID允许他们拥有的其他范围,而传统的API用户也不会

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. 我的猜测是,这个问题并没有真正的解决方案(除了使用UIWebView并制作一个美化的webapp),但我想我还是会在这里问一下。

Can you all think of a way to protect the client ID/client secret if it needs to be consumed by the app? 如果应用程序需要使用客户端ID /客户端密码,您能想到保护客户端ID /客户端密钥的方法吗?

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. 为了实现您的两个目标,您需要验证访问API的客户端是否由您编写。 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. 虽然不是防弹,但它是防弹的,因为这样做需要大量的工作并且技术性很强,特别是如果你使用反RE技术,如缓冲涂抹,质量红鲱鱼等。

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. 如果你是Facebook,那就是灾难性的。 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. 您根本无法信任您无法控制的代码,并且一旦在其他人的设备上,您就不再控制客户端了。

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

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