有没有一种方法可以在 Ajax 中安全地发送信息?

发布于 2024-11-03 02:19:38 字数 666 浏览 0 评论 0 原文

我目前正在开发一个基于 HTML+JS 的应用程序,几乎完全基于 ajax 连接(使用 jQuery.ajax() 调用来简化该过程)。

我正在考虑在不使用 HTTPS 的情况下进行安全调用的最佳实践(至少在这个时候。我现在买不起证书)。

此时,我唯一关心的是注册和登录步骤。也许登录会更容易一些。我想到发送用户名和时间戳,然后使用用户的密码对它们进行加密。因此,通过这样做,我不会发送任何密码(像 OAuth 一样作为秘密保存)。服务器应检查用户,使用密码进行解密,并将收到的时间戳与解密结果配对。服务器应该将类似于随机数的数字保存到数据库中(以避免重复攻击),然后向用户返回另一个唯一的 ID(使用用户的密码加密)。此时,用户应该开始使用该密钥来加密他的所有信息(可能还有另一个随机数)并将其发送到服务器。如果您发现任何错误或泄漏,请纠正我。

对我来说最大的问题是注册。我无法使用常规密码加密信息,因为如果我在 javascript 中这样做,任何人都可能知道密码。如果我提供临时生成的密码进行加密并将其从服务器发送到客户端,则任何嗅探器都可以获取它并用于解密信息。

我知道 HTTPS 此时可以挽救我的生命(也许这是唯一的解决方案),但此时我无法使用它。

还有其他解决方案吗,或者我应该等到可以使用 HTTPS 为止吗?请记住,如果我可以跳过等待,那就更好了。谢谢伙伴们!

I'm currently developing an application in HTML+JS based almost entirely in ajax connections (using the jQuery.ajax() call to ease the process).

I was thinking about the best practice to make secure calls without using HTTPS (at least at this time. I can't afford paying for a certificate right now).

At this point, the only thing that concerns me is the registration and login steps. Maybe the login is a bit easier. I thought of sending the username and a timestamp, and then encrypt them using the user's password. So, by doing this, I wouldn't be sending any password (keeping as a secret like in OAuth). The server should check the user, decrypt using the password and pairing the recieved timestamp with the decrypted result. The server should keep the nonce-like number into a database (to avoid repetition attacks) and then give back to the user another unique id (encrypted with the user's password). At that point the user should start using that key to encrypt all his information (and probably another nonce) and send it to the server. Please correct me if you find any mistake or leak.

The very big problem to me is the registration. I can't encrypt with a regular password the information, because if I do that in the javascript, any could know the password. If I serve temporary generated passwords to encrypt and I send it from the server to the client, any sniffer could get it and use to decrypt the info.

I know HTTPS could save my life at this point (and maybe that's the only solution), but at this point I'm not able to use it.

Is there any other solution, or should I wait until I can use HTTPS? Bear in mind that if I could skip the wait, it would be better. Thanks mates!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

很酷不放纵 2024-11-10 02:19:38

简短的回答:没有 HTTPS,您就无法做到这

一点 较长的回答:如果您尝试在没有 HTTPS 的情况下做到这一点,您会发现自己试图重现 HTTPS 设计的所有功能。您可能会达到某个目标,但相信您将成功实现 HTTPS 提供的 1% 是不现实的。您将获得的唯一好处是一个模糊的安全机制(通过模糊实现安全性),这对于不关键的系统来说可能没问题,但在真正的关键情况下会严重失败。

您可以创建自己熟悉的证书,然后像使用常规 HTTP 调用一样使用 Ajax。唯一的缺点是用户会收到警告消息。

Short answer: You can't do it without HTTPS

Longer answer: If you try to do it without HTTPS, you will find yourself trying to reproduce everything that HTTPS was designed to do. You could reach at some point, but it is unrealistic to believe that you will succeed in implementing even the 1% that HTTPS offers. The only benefit you will have would be an obscure security mechanism (security through obscurity), which may be OK for not critical systems, but would fail miserably in a real critical situation.

You could create your own certificate you know and then work with Ajax the same way as with regular HTTP calls. The only drawback is that the users will get a warning message.

等待圉鍢 2024-11-10 02:19:38

使用 SSL 证书是唯一的方法,如果你用 JavaScript 对其进行加密,任何人都可以读取代码并解密。

http://www.startssl.com/

Using an SSL Certificate is the only way really, if you encrypt it in javascript anyone can read the code and decrypt it.

http://www.startssl.com/

相对绾红妆 2024-11-10 02:19:38
  • 在服务器上生成公钥/私钥对以及随机生成的盐。
  • 将密钥对和盐附加到用户会话对象。
  • 将公钥和盐发送到客户端代码。
  • 使用公钥和盐来加密 AJAX 请求。

这不是一项简单的任务。您可能会发现购买证书更便宜、更有效。

编辑:这也意味着所有常规 HTTP 流量(HTML、图像、CSS 等)均以明文形式发送。这可能是一个问题,因为它可能允许窃听者间接弄清楚用户在做什么。

  • Generate a public/private key pair on the server, along with a randomly-generated salt.
  • Attach the key pair and salt to the user session object.
  • Send the public key and the salt to the client-side code.
  • Use the public key and salt to encrypt the AJAX requests.

This would not be a trivial task. You'll probably find that it's cheaper and more effective to just buy a certificate.

EDIT: This also means that all the regular HTTP traffic (HTML, images, CSS, etc) is sent in the clear. That could be a problem, since it might allow an eavesdropper to indirectly figure out what the user is doing.

回心转意 2024-11-10 02:19:38

我认为你应该看看:

http://assl.sullof.com/assl/

以下是该项目的描述:

aSSL 是一个根据 MIT 许可证分发的库,它实现了类似于 SSL 的技术,但没有 HTTPS。

aSSL 使客户端能够使用 RSA 算法与服务器协商秘密随机 128 位密钥。连接建立后,将使用 AES 算法发送和接收数据。

aSSL 由一些 Javascript 文件和服务器端组件组成。因为我最近将协商算法从 RC4 更改为 RSA,所以当前只有纯 Javascript (ASP) 服务器组件可用。一旦库通过了 beta 阶段,我将尽快对主要的 Web 语言(PHP、Java、Perl、Python、TKL 等)进行移植。

I think you should have a look at :

http://assl.sullof.com/assl/

Here is the description of the project :

aSSL is a library distributed under MIT License thats implements a technology similar to SSL without HTTPS.

aSSL enables the client to negotiate a secret random 128-bit key with the server using the RSA algorithm. Once the connection has been established, the data will be sent and received using AES algorithm.

aSSL is composed of some Javascript files and a server side component. Because I have recently changed the negotiation algoritm from RC4 to RSA, only a pure Javascript (ASP) server component is currently available. I will do a porting for the main web languages (PHP, Java, Perl, Python, TKL, etc.) as soon as possible once the library has passed the beta phase.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文