Skip to content

Commit

Permalink
pam_unix: Add support for (gost-)yescrypt hashing methods.
Browse files Browse the repository at this point in the history
libxcrypt (v4.2 and later) has added support for the yescrypt
hashing method; gost-yescrypt has been added in v4.3.

* modules/pam_unix/pam_unix.8.xml: Documentation for (gost-)yescrypt.
* modules/pam_unix/pam_unix_acct.c: Use 64 bit type for control flags.
* modules/pam_unix/pam_unix_auth.c: Likewise.
* modules/pam_unix/pam_unix_passwd.c: Likewise.
* modules/pam_unix/pam_unix_sess.c: Likewise.
* modules/pam_unix/passverify.c: Add support for (gost-)yescrypt.
* modules/pam_unix/passverify.h: Use 64 bit type for control flags.
* modules/pam_unix/support.c: Set sane rounds for (gost-)yescrypt.
* modules/pam_unix/support.h: Add support for (gost-)yescrypt.
  • Loading branch information
besser82 authored and t8m committed Nov 23, 2018
1 parent b8ba9fa commit 16bd523
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 75 deletions.
35 changes: 33 additions & 2 deletions modules/pam_unix/pam_unix.8.xml
Expand Up @@ -331,14 +331,45 @@
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>gost_yescrypt</option>
</term>
<listitem>
<para>
When a user changes their password next,
encrypt it with the gost-yescrypt algorithm. If the
gost-yescrypt algorithm is not known to the <citerefentry>
<refentrytitle>crypt</refentrytitle><manvolnum>3</manvolnum>
</citerefentry> function,
fall back to MD5.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>yescrypt</option>
</term>
<listitem>
<para>
When a user changes their password next,
encrypt it with the yescrypt algorithm. If the
yescrypt algorithm is not known to the <citerefentry>
<refentrytitle>crypt</refentrytitle><manvolnum>3</manvolnum>
</citerefentry> function,
fall back to MD5.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>rounds=<replaceable>n</replaceable></option>
</term>
<listitem>
<para>
Set the optional number of rounds of the SHA256, SHA512
and blowfish password hashing algorithms to
Set the optional number of rounds of the SHA256, SHA512,
blowfish, gost-yescrypt, and yescrypt password hashing
algorithms to
<replaceable>n</replaceable>.
</para>
</listitem>
Expand Down
4 changes: 2 additions & 2 deletions modules/pam_unix/pam_unix_acct.c
Expand Up @@ -62,7 +62,7 @@
#include "support.h"
#include "passverify.h"

int _unix_run_verify_binary(pam_handle_t *pamh, unsigned int ctrl,
int _unix_run_verify_binary(pam_handle_t *pamh, unsigned long long ctrl,
const char *user, int *daysleft)
{
int retval=0, child, fds[2];
Expand Down Expand Up @@ -185,7 +185,7 @@ int _unix_run_verify_binary(pam_handle_t *pamh, unsigned int ctrl,
int
pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
unsigned int ctrl;
unsigned long long ctrl;
const void *void_uname;
const char *uname;
int retval, daysleft;
Expand Down
4 changes: 2 additions & 2 deletions modules/pam_unix/pam_unix_auth.c
Expand Up @@ -96,7 +96,7 @@ setcred_free (pam_handle_t *pamh UNUSED, void *ptr, int err UNUSED)
int
pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
unsigned int ctrl;
unsigned long long ctrl;
int retval, *ret_data = NULL;
const char *name;
const char *p;
Expand Down Expand Up @@ -194,7 +194,7 @@ pam_sm_setcred (pam_handle_t *pamh, int flags,
{
int retval;
const void *pretval = NULL;
unsigned int ctrl;
unsigned long long ctrl;

D(("called."));

Expand Down
12 changes: 6 additions & 6 deletions modules/pam_unix/pam_unix_passwd.c
Expand Up @@ -138,7 +138,7 @@ __taddr2port (const struct netconfig *nconf, const struct netbuf *nbuf)
}
#endif

static char *getNISserver(pam_handle_t *pamh, unsigned int ctrl)
static char *getNISserver(pam_handle_t *pamh, unsigned long long ctrl)
{
char *master;
char *domainname;
Expand Down Expand Up @@ -233,7 +233,7 @@ static char *getNISserver(pam_handle_t *pamh, unsigned int ctrl)

#ifdef WITH_SELINUX

static int _unix_run_update_binary(pam_handle_t *pamh, unsigned int ctrl, const char *user,
static int _unix_run_update_binary(pam_handle_t *pamh, unsigned long long ctrl, const char *user,
const char *fromwhat, const char *towhat, int remember)
{
int retval, child, fds[2];
Expand Down Expand Up @@ -388,7 +388,7 @@ static int check_old_password(const char *forwho, const char *newpass)

static int _do_setpass(pam_handle_t* pamh, const char *forwho,
const char *fromwhat,
char *towhat, unsigned int ctrl, int remember)
char *towhat, unsigned long long ctrl, int remember)
{
struct passwd *pwd = NULL;
int retval = 0;
Expand Down Expand Up @@ -512,7 +512,7 @@ static int _do_setpass(pam_handle_t* pamh, const char *forwho,
return retval;
}

static int _unix_verify_shadow(pam_handle_t *pamh, const char *user, unsigned int ctrl)
static int _unix_verify_shadow(pam_handle_t *pamh, const char *user, unsigned long long ctrl)
{
struct passwd *pwent = NULL; /* Password and shadow password */
struct spwd *spent = NULL; /* file entries for the user */
Expand Down Expand Up @@ -542,7 +542,7 @@ static int _unix_verify_shadow(pam_handle_t *pamh, const char *user, unsigned in
}

static int _pam_unix_approve_pass(pam_handle_t * pamh
,unsigned int ctrl
,unsigned long long ctrl
,const char *pass_old
,const char *pass_new,
int pass_min_len)
Expand Down Expand Up @@ -600,7 +600,7 @@ static int _pam_unix_approve_pass(pam_handle_t * pamh
int
pam_sm_chauthtok(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
unsigned int ctrl, lctrl;
unsigned long long ctrl, lctrl;
int retval;
int remember = -1;
int rounds = 0;
Expand Down
4 changes: 2 additions & 2 deletions modules/pam_unix/pam_unix_sess.c
Expand Up @@ -67,7 +67,7 @@ int
pam_sm_open_session(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
char *user_name, *service;
unsigned int ctrl;
unsigned long long ctrl;
int retval;
const char *login_name;

Expand Down Expand Up @@ -103,7 +103,7 @@ int
pam_sm_close_session(pam_handle_t *pamh, int flags, int argc, const char **argv)
{
char *user_name, *service;
unsigned int ctrl;
unsigned long long ctrl;
int retval;

D(("called."));
Expand Down
8 changes: 7 additions & 1 deletion modules/pam_unix/passverify.c
Expand Up @@ -387,7 +387,7 @@ crypt_md5_wrapper(const char *pass_new)
}

PAMH_ARG_DECL(char * create_password_hash,
const char *password, unsigned int ctrl, int rounds)
const char *password, unsigned long long ctrl, int rounds)
{
const char *algoid;
#if defined(CRYPT_GENSALT_OUTPUT_SIZE) && CRYPT_GENSALT_OUTPUT_SIZE > 64
Expand All @@ -404,6 +404,10 @@ PAMH_ARG_DECL(char * create_password_hash,
if (on(UNIX_MD5_PASS, ctrl)) {
/* algoid = "$1" */
return crypt_md5_wrapper(password);
} else if (on(UNIX_YESCRYPT_PASS, ctrl)) {
algoid = "$y$";
} else if (on(UNIX_GOST_YESCRYPT_PASS, ctrl)) {
algoid = "$gy$";
} else if (on(UNIX_BLOWFISH_PASS, ctrl)) {
algoid = "$2b$";
} else if (on(UNIX_SHA256_PASS, ctrl)) {
Expand Down Expand Up @@ -466,6 +470,8 @@ PAMH_ARG_DECL(char * create_password_hash,
pam_syslog(pamh, LOG_ERR,
"Algo %s not supported by the crypto backend, "
"falling back to MD5\n",
on(UNIX_YESCRYPT_PASS, ctrl) ? "yescrypt" :
on(UNIX_GOST_YESCRYPT_PASS, ctrl) ? "gost_yescrypt" :
on(UNIX_BLOWFISH_PASS, ctrl) ? "blowfish" :
on(UNIX_SHA256_PASS, ctrl) ? "sha256" :
on(UNIX_SHA512_PASS, ctrl) ? "sha512" : algoid);
Expand Down
2 changes: 1 addition & 1 deletion modules/pam_unix/passverify.h
Expand Up @@ -66,7 +66,7 @@ read_passwords(int fd, int npass, char **passwords);
#endif

PAMH_ARG_DECL(char * create_password_hash,
const char *password, unsigned int ctrl, int rounds);
const char *password, unsigned long long ctrl, int rounds);

PAMH_ARG_DECL(int get_account_info,
const char *name, struct passwd **pwd, struct spwd **spwdent);
Expand Down
33 changes: 21 additions & 12 deletions modules/pam_unix/support.c
Expand Up @@ -107,7 +107,7 @@ search_key (const char *key, const char *filename)

/* this is a front-end for module-application conversations */

int _make_remark(pam_handle_t * pamh, unsigned int ctrl,
int _make_remark(pam_handle_t * pamh, unsigned long long ctrl,
int type, const char *text)
{
int retval = PAM_SUCCESS;
Expand All @@ -122,10 +122,11 @@ int _make_remark(pam_handle_t * pamh, unsigned int ctrl,
* set the control flags for the UNIX module.
*/

int _set_ctrl(pam_handle_t *pamh, int flags, int *remember, int *rounds,
int *pass_min_len, int argc, const char **argv)
unsigned long long _set_ctrl(pam_handle_t *pamh, int flags, int *remember,
int *rounds, int *pass_min_len, int argc,
const char **argv)
{
unsigned int ctrl;
unsigned long long ctrl;
char *val;
int j;

Expand Down Expand Up @@ -243,15 +244,23 @@ int _set_ctrl(pam_handle_t *pamh, int flags, int *remember, int *rounds,
set(UNIX__NONULL, ctrl);
}

/* Set default rounds for blowfish */
if (on(UNIX_BLOWFISH_PASS, ctrl) && off(UNIX_ALGO_ROUNDS, ctrl) && rounds != NULL) {
*rounds = 5;
set(UNIX_ALGO_ROUNDS, ctrl);
/* Set default rounds for blowfish, gost-yescrypt and yescrypt */
if (off(UNIX_ALGO_ROUNDS, ctrl) && rounds != NULL) {
if (on(UNIX_BLOWFISH_PASS, ctrl) ||
on(UNIX_GOST_YESCRYPT_PASS, ctrl) ||
on(UNIX_YESCRYPT_PASS, ctrl)) {
*rounds = 5;
set(UNIX_ALGO_ROUNDS, ctrl);
}
}

/* Enforce sane "rounds" values */
if (on(UNIX_ALGO_ROUNDS, ctrl)) {
if (on(UNIX_BLOWFISH_PASS, ctrl)) {
if (on(UNIX_GOST_YESCRYPT_PASS, ctrl) ||
on(UNIX_YESCRYPT_PASS, ctrl)) {
if (*rounds < 3 || *rounds > 11)
*rounds = 5;
} else if (on(UNIX_BLOWFISH_PASS, ctrl)) {
if (*rounds < 4 || *rounds > 31)
*rounds = 5;
} else if (on(UNIX_SHA256_PASS, ctrl) || on(UNIX_SHA512_PASS, ctrl)) {
Expand Down Expand Up @@ -532,7 +541,7 @@ int _unix_comesfromsource(pam_handle_t *pamh,
#include <sys/wait.h>

static int _unix_run_helper_binary(pam_handle_t *pamh, const char *passwd,
unsigned int ctrl, const char *user)
unsigned long long ctrl, const char *user)
{
int retval, child, fds[2];
struct sigaction newsa, oldsa;
Expand Down Expand Up @@ -658,7 +667,7 @@ static int _unix_run_helper_binary(pam_handle_t *pamh, const char *passwd,
*/

int
_unix_blankpasswd (pam_handle_t *pamh, unsigned int ctrl, const char *name)
_unix_blankpasswd (pam_handle_t *pamh, unsigned long long ctrl, const char *name)
{
struct passwd *pwd = NULL;
char *salt = NULL;
Expand Down Expand Up @@ -706,7 +715,7 @@ _unix_blankpasswd (pam_handle_t *pamh, unsigned int ctrl, const char *name)
}

int _unix_verify_password(pam_handle_t * pamh, const char *name
,const char *p, unsigned int ctrl)
,const char *p, unsigned long long ctrl)
{
struct passwd *pwd = NULL;
char *salt = NULL;
Expand Down

0 comments on commit 16bd523

Please sign in to comment.