有人见过 Javascript 中的 crypt(3) 实现吗?

发布于 2025-01-08 07:41:12 字数 1027 浏览 1 评论 0原文

我正在寻找 javascript 中 crypt(3) 的实现。 (不是通用的“crypt”算法,而是在 Linux 系统上的 /etc/shadow 中使用的 crypt(3) 算法)。有人见过吗?有开放许可证吗?

我也有点担心性能:是否可以用 javascript 编写一个?例如 sha512- crypt source has:

/* Repeatedly run the collected hash value through SHA512 to burn
   CPU cycles.  */
for (cnt = 0; cnt < rounds; ++cnt)
{ ... }

那么如果算法在 C 中“消耗 CPU 周期”,那么它在 javascript 中会做什么?炒? (例如在 IE6 中?哎呀!)我不是在 javascript 中编写暴力攻击实用程序,只是一次千载难逢的 crypt 调用,所以也许会没问题。

背景:我们希望从用户提供的 /etc/password//etc/shadow 文件中为我们的 Web 应用导入用户。由于我们拥有的有关用户密码的唯一信息将采用 crypt(3) 输出格式,因此为了避免以明文形式发送回用户密码,据我所知,我们需要一个客户端(javascript ) crypt(3) 的实现,因此当网络服务器提供盐时,客户端会发回 crypt(3) 输出(为了安全起见,经过适当的散列处理)。

使用 crypt(3) 客户端的任何替代方案都允许我们根据 /etc/password//etc/shadow 安全地对服务器端进行身份验证,并且不需要 https: // 也将被视为有效答案。

I'm looking for an implementation of crypt(3) in javascript. (Not a generic "crypt" algorithm, but the crypt(3) one used in /etc/shadow e.g. on Linux systems). Anybody seen one? With an open license?

I'm a little worried about performance too: Would it even be possible to write one in javascript? E.g. the sha512-crypt source has:

/* Repeatedly run the collected hash value through SHA512 to burn
   CPU cycles.  */
for (cnt = 0; cnt < rounds; ++cnt)
{ ... }

And so if the algorithm "burns CPU cycles" in C, what will it do in javascript? Fry? (E.g. in IE6? Yikes!) I'm not writing a brute-force attack util in javascript, just a crypt call once in a blue moon, so perhaps it'll be ok.

Background: We're looking to import users from a user-provided /etc/password//etc/shadow file for our webapp. Since the only information we have about the users' passwords would be in crypt(3) output format, then to avoid sending the users' passwords back in clear text, as far as I can see, we would need a client-side (javascript) implementation of crypt(3) so when the webserver provides a salt, the client sends back the crypt(3) output (appropriately hashed for security).

Any alternatives to using crypt(3) client side that allow us to safely authenticate server-side against /etc/password//etc/shadow and don't require https:// will also be considered valid answers.

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

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

发布评论

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

评论(1

黄昏下泛黄的笔记 2025-01-15 07:41:12

Javascript 加密技术并不安全。您必须使用 SSL 该链接有很多充分的理由,所以我在这里只发布一个:

如果您不信任网络会传递密码,或者更糟糕的是,不信任服务器不会保守用户机密,那么您就无法信任它们会传递安全代码。在您引入加密货币之前嗅探密码或阅读日记的攻击者只是在您引入加密货币之后劫持加密代码。

如果您通过 SSL 发送 Javascript 加密,则不再需要 Javascript 加密;你拥有“真正的”密码学。

此外,由于您只是发送密码的哈希值并将其与您拥有的哈希值进行比较,因此攻击者可以轻松复制哈希值并在需要时使用它。这称为重放攻击,它特别阴险,因为你无法告诉任何事情错误正在发生。

因此,您必须使用 SSL。让用户通过 SSL 连接发送密码,并在服务器上执行 crypt(3)。根据您使用的 Web 框架,您可以使用预先存在的模块(例如 Django 的 PAM 后端,它并不能完全满足您的要求,但是一个很好的起始参考)或推出您自己的实现。

Javascript cryptography isn't secure. You have to use SSL That link has a lot of good reasons why, so I'll post just one here:

If you don't trust the network to deliver a password, or, worse, don't trust the server not to keep user secrets, you can't trust them to deliver security code. The same attacker who was sniffing passwords or reading diaries before you introduce crypto is simply hijacking crypto code after you do.

If you send your Javascript crypto over SSL, you no longer need Javascript cryptography; you have "real" cryptography.

Additionally, since you're only sending the hash of the password and comparing it to a hash you have, it's trivial for an attacker to copy the hash and use it whenever they want. This is called a replay attack, and it's particularly insidious because you won't be able to tell anything wrong is happening.

Because of that, you have to use SSL. Have the user send their password over an SSL connection, and do the crypt(3) on the server. Depending on the web framework you're using, you can use a pre-existing module (such as Django's PAM backend, which doesn't quite do what you want but is a good starting reference) or roll your own implementation.

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