2

我编写了一个带有自定义二进制 websocket 协议的 Go 服务器和一个 Dart 客户端。服务器上的用户身份验证使用scrypt和推荐的参数N=16384, r=8, p=1(盐长度为 16,生成的密钥长度为 64),我的 i7 桌面可能需要一两秒才能通过身份验证服务器端。这与实际上是即时的,比如 SHA-512 身份验证相比。

我在为 Dart 找到 scrypt 实现时遇到了麻烦,虽然这个实现是有效的,但在浏览器 (Firefox) 中生成具有相同参数的相同哈希需要很长时间才能实际完成。我可以在同一台机器上使用 N=1024 和 r<=8 将其缩短到几秒钟,但如果我出于兼容性考虑,在服务器端,身份验证时间再次用于实际目的。

Scrypt 在服务器端很棒,但我想知道它对于浏览器客户端是否实用。诚然,我还没有看到任何/很多人使用 scrypt 进行浏览器身份验证的例子。我应该坚持并解决性能问题(例如,可能使用 dart 中的其他 javascript 库),还是目前这是一个基本限制?在您还不如只使用更广泛可用、优化的加密散列算法(如 SHA)之前,您可以将 scrypt 参数降低到多低?

4

2 回答 2

1

@maaartinus ...

I've never thought about not using HTTPS. I'm curious if offloading the password-based key derivation overhead to the client makes any sense.

If I may, I can come at this problem from non-Web direction and come back to the browser-use case. Way back when, I worked with EFT*POS security standards and working with secure communications for financial transactions. For example; the credit-card machine in the supermarket. Just establish my grounding on this topic. That said, I think the original question HAS be covered comprehensively. I decided to add a comment to enrich the conversation on this area (it is quite topical).

The procedure is about the a conversation between the terminal (iPhone, smartphone, browser, etc). Premise: you naturally don't want anyone sniffing your username/password pairing. Assume your typical web page or login screen at work. Over the Intranet, LAN, WAN and VPN what every you type is dispatched from your keyboard to the host. These links may already be encrypted these days. The WWW web on the Internet has two main options: HTTP (clear text) and HTTPS (encrypted) via the browser. If we just stick with the (username, password) pair.

Your terminal (such as browser or mobile) needs to be "trusted" by the host (server, phone company, etc).

There's a lot of standard stuff you can (should do) first; and get creative from there-on. Think of it as a pyramid. On the bottom are things you can do on your PC. That's the base of the pyramid. And there's loads of good information about that (e.g. Electronic Frontier Foundation, EFF), it is about protecting yourself, your data (intangible property) and your rights.

That said here are a few points to consider:

  • Everything sent via HTTP is clear-text. It can be read and copied.
    • A hash sent over clear-text can be decoded to get the password. It is just maths.
    • Even if you use scrypt or another method the hash is decodable -- Given enough time.
    • If you're on the web, any hash implemented in the browser (terminal/client), is transparent to anyone who can load the web page and javascript code [pointed out by ntoskrnl above.

HTTPS on the other hand, sends Everything-as-a-hash. In addition the hash used is negotiated is unique to the conversation and agreed at session-completion time. It is a slightly 'better-er' hash over the whole-of-the-Message.

The main thing making it better-er in the first instance, is the negotiation. The idea overall is that message hashes are based on a key only known to both end-points.

Once again that can be cracked if you have enough time, etc. The main thing making this challenging is establishing the to-and-fro for the negotiations.

Let's back-up a little and consider cryptography. The notion is to hide the message in a way that permits the message to be revealed. Think of this a as lock and key, where the door is the procedure/algorithm and your message is the contents of the room.

HTTPS works to separate the lock from the key in a pragmatic fashion, in time and via process.

Whatever is done in the HTTPS room, stays in the HTTPS-room. You must have the key to enter, poke about and do unwanted stuff. Imho, any extra security should be ONLY considered within a HTTPS space.

There are methods to improve on that foundation. I think of security like a pyramid. about 4 or 5 layers above the base considerations like the transport protocol.

Such options include, ...

  • SMS authentication number to your phone.
  • Something like a dongle or personalised ID-key.
  • An physical message like an s-mail or e-mail with an authentication Number.
  • anything you come up with.

In summary, if your need say make it safe; there are many things that can be accomplished. If you can't use HTTPS, hashing password(s) locally needs to be managed extremely carefully. Hashes have vulnerabilities. When you are not using HTTPS, anything you can do in the browser is like wet-rice-paper trying to stave-off a sword.

于 2014-05-01T11:09:56.297 回答
0

使用 HTTPS。如果您在浏览器中对密码进行哈希处理,然后将哈希发送到服务器进行比较,那么如何防止攻击者简单地嗅探哈希密码并通过自己发送相同的哈希来劫持会话?

即使您想出了一个加密方案来防止这种情况,攻击者也可以<script>通过 MITM 攻击简单地注入一个带有键盘记录器的附加标签,以在加密之前窃取密码。

基本上不管你怎么剪,你必须使用 HTTPS 来确保你的通信是不可嗅探的,并且没有发生 MITM 攻击。一旦你的连接已经通过 HTTPS 得到保护,它使用(最小)128 位密钥加密,并且需要比已知的宇宙年龄更长的时间来破解,你不妨只使用 HTTPS 连接来发送你的密码和可能不需要对密码客户端进行额外的加密。

于 2014-04-28T12:55:30.947 回答