【发布时间】:2012-10-19 05:30:54
【问题描述】:
我最近开始了设置 PureFTP 服务器的任务。在工作中我们使用 Postgresql 8.4。架构基本上归结为,
username text
password character(40)
password_salt text
password 存储为sha1( password + salt ) 的哈希值。使用 Postgresql 的 pgcrypto,我可以提供 username 和 password 并查看用户是否具有身份验证:
SELECT
encode( digest( $password ||password_salt, 'sha1' ), 'hex' ) = password
AS password_correct
, username
, password
, password_salt
FROM contact.person;
现在我遇到的问题是这样的功能需要我在查询中输入密码。 Pureftp 当前的 auth-postgresql 实现似乎无法做到这一点。它只支持提供:
\L is replaced by the login of a user trying to authenticate.
\I is replaced by the IP address the client connected to.
\P is replaced by the port number the client connected to.
\R is replaced by the remote IP address the client connected from.
\D is replaced by the remote IPv4 address, as a long decimal number.
还有其他方法可以做到这一点吗?我要么需要将密码输入查询,要么取出盐和密码并找到另一种在 Pureftp 中编写代码的方法。
显然,我还有另一种写custom authentication module的选项,但我认为pg模块会支持这种基本的加盐。
参考
【问题讨论】:
-
我认为你必须这样做:用户的密码,明文,crypt()ed 格式或 MD5。 Pure-FTPd 也接受 PGSQLCrypt 字段的“任何”值。使用“any”,尝试所有散列函数(不是明文)。
-
是的,但他们在没有 DB 盐的情况下进行了尝试。 =(该死的,这不好。
-
您可能需要深入研究源代码才能找到答案,但它可能接受在 md5 或加密密码之前或之后添加的盐?我相信这就是 /etc/shadow 存储它们的方式。如果你最终编写了自己的身份验证并且可以做任何你想做的事情,你应该使用带有河豚算法的 postgres crypt 而不是 sha1。
标签: postgresql salt saltedhash pureftpd