我不得不制定出一个计划来开发一个RESTful API,它可以通过我们未来的Web应用程序(Angularjs)和移动应用(iOS版/ Android设备)中使用(Python的/瓶)。
我一直在研究了三天所遇到的几种情况:使用HTTPS是在以下方法顶部的一种方式,以保持它更安全。 但是,HTTPS较慢,这可能意味着我们需要更快,更昂贵的服务器。
- 使用基本-HTTP-AUTH和平原(尚未HTTPS)在导线的每个请求的API发送用户名/密码。
- 使用摘要,验证,这是密码,跟踪将自动这为Web应用程序工作的哈希值,但我无法证实,如果iPhone和Android将支持这一本身。 如果他们这样做,这可能是一个简单的解决方案!
- 使用自定义HTTP头,在那里我会在HTTP标头在成功验证发送自定义验证字符串。 但我必须确保我送为每个用户进行请求,该授权码。 这使得它酷似1),差别在于一般密码不被使用和授权码没有任何危险到期。 也存在问题是在auth代码的跟踪,这是不再自动化如2)
- 使用OAuth是一种选择。 但其相当难以成立。 如果没有更好的办法,也许这就是唯一的出路?
- 因为这所描述确保像Amazon S3 API的大文章 。 总之,他说,服务器和客户端都知道的私钥,他们会使用散列的通信。 它会像强盗握手,您只将信任交付的男孩,如果他知道了匪帮握手。 再往下有人问评论:
如何保持一个纯粹的HTML5应用程序的私有密钥“安全”?
你是完全正确的; 在纯HTML5(JS / CSS / HTML)应用程序,没有保护的关键。 你会做在这种情况下你不需要的关键,因为你可以放心地确定使用标准API_KEY或无HMAC的需要或复杂一些其他友好标识的客户端HTTPS所有通信。
因此,换句话说,甚至还有没有一点使用方法在首位的web应用程序。 和诚实,我不知道应如何在移动设备上工作,要么。 用户下载我们的应用程序?如何从iPhone发送到服务器的私有密钥? 我转到它的那一刻,也将受到损害。
越我研究我得到了更多的举棋不定。
我希望问一些专业人士谁曾这样做,可以分享他们的经验。 非常感谢
You seem to be confusing/merging two different concepts together. We start of talking about encrypting traffic (HTTPS) and then we start talking about different ways to manage authenticated sessions. In a secure application these are not mutually exclusive tasks. There also seem to potentially be a misunderstanding how session management can impact authentication. Based on that I will provide a primer on web application/web api session management, authentication, and encryption.
Introduction
Session Management
HTTP transactions are stateless by default. HTTP does not specify any method to let your application know that a HTTP request has been sent from a specific user (authenticated or not).
For robust web applications, this is not acceptable. We need a way to associate requests and data made across multiple requests. To do this, on initial request to the server a user needs to be assigned a "session". Generally sessions have some kind of unique id that is sent to the client. The client sends that session id with every request and the server uses the session id sent in every request to properly prepare a response for the user.
It is important to remember that a 'session id' can be called many other things. Some examples of those are: session token, token, etc. For consistency I will use 'session id' for the rest of this response.
Each HTTP request from the client needs to include the session id; this can be done in many ways. Popular examples are:
- It can be stored in a cookie - cookies for the current domain are automatically sent on every request.
- It can be sent on the URL - each request could send the session id on the URL, not suggested since session ids will stay in the clients history
- It can be sent via as a HTTP header - each request would need to specify the header
Most web application frameworks use cookies. However application that rely on JavaScript and single page designs may opt to use a HTTP header/store it in some other location that is observable by the server.
It is very important to remember that the HTTP response that notifies the client of their session id and the client's requests that contain the session id are completely plain text and 100% unsafe. To battle that, all HTTP traffic needs to be encrypted; that is where HTTPS comes in.
It is also important to point out we have not talked about linking a session to a specific user in our system. Session management is just associating data to a specific client accessing our system. The client can be in both authenticated and unauthenticated states, but in both states they generally have a session.
Authentication
Authentication is where we link a session to a specific user in our system. This is generally handled by a login process where a user supplies credentials, those credentials are verified, and then we link a session to a specific user record in our system.
The user is in turn associated with privileges for fine grained access control via access control lists and access control entries (ACL and ACE). This is generally referred to as "Authorization". Most system always have both Authentication and Authorization. In some simple systems all authenticated users are equals in which case you won't have authorization past simple authentication. Further information on this is out of scope for this question, but consider reading about ACE/ACL.
A specific session can be flagged as representing an authenticated user in different ways.
- Their session data stored server side could store their user id / some other flag that denotes that the use is authenticated as a specific user
- Another user token could be send to the client just like a session id (which over unencrypted HTTP is just as unsafe as sending a session id unencrypted)
Either option is fine. It generally comes down to the technology you are working in and what they offer by default.
A client generally initiates the authentication process. This can be done by sending credentials to a specific url (e.g. yoursite.com/api/login). However if we want to be 'RESTful' we generally would referencing a resource by some noun and doing the action of 'create'. This could be done by requiring a POST of the credentials to yoursite.com/api/authenticatedSession/. Where the idea would be to create an authenticated session. Most sites just POST the credentials to /api/login or the like. This is a departure from "true" or "pure" RESTful ideals, but most people find this a simpler concept rather than thinking of it as "creating an authenticated session".
Encryption
HTTPS是用于在客户端和服务器之间的加密HTTP通信。 上依赖于认证和未认证的用户的系统中,依赖于用户的所有流量被认证需要经由HTTPS进行加密; 有没有办法解决这个。
这样做的原因是,如果你验证用户,与他们(他们的会话ID等)共享一个秘密,然后开始游行那个秘密在普通HTTP其会话可以通过人在这方面的中间人攻击劫持。 黑客将等待的流量通过一个观测的网络并窃取秘密(因为它通过HTTP明文),然后开始故作原始客户端与服务器的连接。
人们解决这一问题的方法是通过关联请求远程IP地址的认证会话。 这是无效的单独任何黑客能够欺骗他们的请求远程IP地址在他们的虚假请求,然后观察您的服务器正在发回的响应。 大多数人会认为这是不值得实施,除非你正在跟踪历史数据,并用它来识别特定用户的登录模式(如谷歌一样)。
如果您需要在HTTP和HTTPS部分分割你的网站,这是至关重要的是,HTTP流量不发送或接收会话ID或用于管理用户的认证状态的任何标记。 同样重要的是,你没有在非HTTPS请求/响应发送敏感应用程序数据。
确保Web应用程序中的数据的唯一方法/ API的是加密的流量。
你的话题一个接一个
基本-HTTP-AUTH
这是由唯一的网络资源进行身份验证的方法。 基本身份验证验证通过URL识别资源的用途。 这是最普遍被Apache HTTP Web服务器与使用基于目录的.htaccess /位置认证的实施。 凭证必须与每个请求一起发送; 客户一般为用户处理了这个透明。
基本认证可以通过其它系统作为认证模式下使用。 然而,利用基本-HTTP-验证的系统提供认证和会话管理,而不是基本-HTTP-AUTH本身。
- 这不是会话管理。
- 这不是加密; 内容和证书几乎是100%的纯文本
- 这不保护应用程序的HTTP请求/响应的内容。
文摘-验证
这是完全一样的基本-HTTP-AUTH增加了一些简单的MD5消化的。 这种消化也不应代替使用加密的依据。
- 这不是会话管理。
- 这不是加密; 摘要容易破裂
- 这不保护应用程序的HTTP请求/响应的内容。
OAuth的
OAuth的只是让你有一个外部服务验证凭据。 之后,它是由你来管理/工作与认证请求您的OAuth提供商的结果。
- 这不是会话管理。
- 这不是加密; 您的网站的流量仍然是纯文本。 认证过程会因HTTPS限制的安全,但您的应用程序仍然是脆弱的。
- 这不保护应用程序的HTTP请求/响应的内容。
歹徒握手 / 自定义HTTP标头
- 验证:YES,潜在地
- 会话管理:是的,有可能
- 加密:NO
“自定义HTTP标头”是一种类型的“强盗握手”的; 因此我将使用相同的部分进行讨论。 唯一的区别在于,“自定义HTTP标头”被指定其中hanshake(会话ID,令牌,用户认证托克等)将被存储(即,在HTTP报头)。
需要注意的是,这些不指定认证将如何处理,也不会指定会话管理将如何处理是很重要的。 他们基本上是描述如何以及在何处会话ID /认证令牌将被保存。
认证需要通过应用程序或通过第三方(如OAuth的)来处理。 会话管理仍然需要实施为好。 有趣的是,你可以选择合并两个如果你想。
- 这不是加密; 您的网站的流量仍然是纯文本。 认证过程将是安全的,由于HTTPS的限制,如果你使用OAuth,但您的应用程序仍然是脆弱的。
- 这不保护应用程序的HTTP请求/响应的内容。
你需要做什么
......我强烈建议你一定要明白,一个强大的Web应用程序,安全需要执行以下操作:
- 加密(HTTPS几乎是你唯一的选择)
- 会话管理
- 认证/授权
授权依赖于认证。 验证依赖于会话管理和加密可以确保会议不被劫持,而且凭据不会拦截。
烧瓶登录
我想你应该看看烧瓶登录的方式,以避免重新实现车轮。 我个人从来没有使用过(我在Python中使用金字塔的Web应用程序)。 不过,我已经看到它在Web应用程序/蟒蛇板前面提到的。 它可以处理认证和会话管理。 投掷通过HTTPS您的Web API /应用程序,你有三个(加密,会话管理,以及用户认证)。
如果不这样做/不能使用烧瓶登陆,准备写你自己的,但首先做研究关于如何创建安全的认证机制。
如果可能的话,如果你不知道如何写一个验证过程,请不先学习黑客如何使用基于模式的攻击,定时攻击等不会尝试这样做
请加密你的流量
...搬过去,你能避免使用HTTPS与一些“聪明”的标记使用的想法。 搬过去,你应该避免使用HTTPS的想法/加密,因为“它的缓慢”,工艺精深,等,这是工艺精深,因为它是一种加密算法。 需要确保用户的数据和应用程序数据的安全应该永远是你的最高优先级。 你不想去通过通知他们的数据遭到了破坏用户的恐怖。
https的速度下降,但不是没有。 只有握手较慢。 对我们来说,最大的问题是要维护的服务器端手机和权利的密钥对。 我们已经实现了一个消息摘要过。 它的问题是:很难正确地设置PHP,Android的IOS版本。 完成此操作后(参数需要改变什么以第一名的成绩只在Android的侧面暗示谷歌)的问题将与低端设备:以大量的CPU使用率,慢于解密 - 加密过程,慢了很多HTTPS,尤其是当您需要转换10KB字符串(可能需要几分钟)。
如果我不美国宇航局数据传输到哈马斯,比我会用一个非常简单的加密过简单的HTTP走:像反转位左右...
去使用HTTPS。 这是(略)慢,但你从中获得了相对较短的投资时间(购买SSL证书,只是改变你的网址,HTTP到HTTPS)的安全性是值得的。 如果没有HTTPS,你运行你的用户的会话的风险在不安全的公共网络,这是非常得到劫持容易有人做 。