Eva*_*oll 5 postgresql salt saltedhash pureftpd
我最近开始设置PureFTP服务器的任务.在工作中我们使用Postgresql 8.4.架构基本上归结为,
username text
password character(40)
password_salt text
Run Code Online (Sandbox Code Playgroud)
该password存储为哈希sha1( password + salt ).使用Postgresql的pgcrypto我可以提供一个username,password并找出用户是否有auth:
SELECT
encode( digest( $password ||password_salt, 'sha1' ), 'hex' ) = password
AS password_correct
, username
, password
, password_salt
FROM contact.person;
Run Code Online (Sandbox Code Playgroud)
现在我遇到的问题是这样的功能需要我将密码输入查询.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.
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以做到这一点吗?我要么需要在查询中获取密码,要么取出盐和密码,并找到另一种在Pureftp中编写代码的方法.
显然,我有另一种编写自定义身份验证模块的选项,但我认为pg模块将支持这种基本的salting.
我也遇到了同样的问题。然而,编写我自己的自定义身份验证模块将是一种矫枉过正,因为可用的 pgsql 身份验证几乎可以完成我想要的一切。以下是我为满足我的需求而对其进行的更改:
在 log_pgsql_p.h 中添加static char *salting;and并用andstatic char *sqlreq_getsalt;扩展。static ConfigKeywords pgsql_config_keywords[]{ "PGSQLSalting", &salting },{ "PGSQLGetSalt", &sqlreq_getsalt },
在 log_pgsql.h 中我添加了#define SALT_SQL_APPEND "append",#define SALT_SQL_PREPEND "prepend"和#define SALT_SQL_NONE "none"。
在 log_pgsql.c 中,我对函数进行了以下更改pw_psql_check:
我宣布const char *salt = NULL;并char * salted_password = NULL;在顶部。就在spwd将查询结果分配给sqlreq_getpw我之前添加的
if (strcasecmp(salting, SALT_SQL_NONE) != 0) {
salt = pw_pgsql_getquery(id_sql_server, sqlreq_getsalt,
escaped_account, escaped_ip,
escaped_port, escaped_peer_ip,
escaped_decimal_ip);
}
Run Code Online (Sandbox Code Playgroud)
然后,在加密发生之前:
if (salt != NULL) {
int salted_pw_size = strlen(salt) + strlen(password) + 1;
salted_password = (char *) malloc(salted_pw_size);
if (strcasecmp(salting, SALT_SQL_APPEND) == 0) {
strcpy(salted_password, password);
strcat(salted_password, salt);
} else if (strcasecmp(salting, SALT_SQL_PREPEND) == 0) {
strcpy(salted_password, salt);
strcat(salted_password, password);
}
} else {
salted_password = (char *) malloc(strlen(password));
strcpy(salted_password, password);
}
Run Code Online (Sandbox Code Playgroud)
然后我将password后续调用 crypt 方法(crypt、crypto_hash_md5、crypto_hash_sha1)和strcasecmp“cleartext”的参数替换为(const char*)salted_password.
现在剩下要做的就是整理我们分配的内存。特别是带有附加/前置盐的明文密码不应保留在内存中 - 如果您愿意,可以将其称为偏执狂。所以在bye:标签后添加
free((void *) salt;
if(strcasecmp(salting, SALT_SQL_NONE) != 0) {
volatile char *salted_password_ = (volatile char *) salted_password;
while(*salted_password_ != 0) {
*salted_password_++ = 0;
}
free((void *) salted_password);
}
Run Code Online (Sandbox Code Playgroud)
通过这些更改,您的配置文件中现在有两个可用的附加参数:
编辑:哦,不要忘记在函数结束时释放分配的内存!
我还可以提供适用于 1.0.36 版本的 diff 文件..给你!但请注意,我稍后在释放 salted_password 时添加了 if (因为我后来才意识到,如果 salted_password 指向密码,这可能会导致错误),所以这不在差异中,我懒得更改差异文件 :/
| 归档时间: |
|
| 查看次数: |
1284 次 |
| 最近记录: |