Skip to content

Commit

Permalink
auth: Don't crash when trying to use CRYPT scheme when crypt() doesn'…
Browse files Browse the repository at this point in the history
…t support DES
  • Loading branch information
sirainen committed Nov 9, 2015
1 parent 265cb53 commit 54a1b35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 16 additions & 0 deletions src/auth/password-scheme-crypt.c
Expand Up @@ -23,6 +23,19 @@ void password_set_encryption_rounds(unsigned int rounds)
encryption_rounds = rounds;
}

static void
crypt_generate_des(const char *plaintext, const char *user ATTR_UNUSED,
const unsigned char **raw_password_r, size_t *size_r)
{
#define CRYPT_SALT_LEN 2
const char *password, *salt;

salt = password_generate_salt(CRYPT_SALT_LEN);
password = t_strdup(mycrypt(plaintext, salt));
*raw_password_r = (const unsigned char *)password;
*size_r = strlen(password);
}

static void
crypt_generate_blowfisch(const char *plaintext, const char *user ATTR_UNUSED,
const unsigned char **raw_password_r, size_t *size_r)
Expand Down Expand Up @@ -98,6 +111,7 @@ static const struct {
const char *salt;
const char *expected;
} sample[] = {
{ "08/15!test~4711", "JB", "JBOZ0DgmtucwE" },
{ "08/15!test~4711", "$2a$04$0123456789abcdefABCDEF",
"$2a$04$0123456789abcdefABCDE.N.drYX5yIAL1LkTaaZotW3yI0hQhZru" },
{ "08/15!test~4711", "$5$rounds=1000$0123456789abcdef",
Expand All @@ -110,6 +124,8 @@ static const struct {

/* keep in sync with the sample struct above */
static const struct password_scheme crypt_schemes[] = {
{ "CRYPT", PW_ENCODING_NONE, 0, crypt_verify,
crypt_generate_des },
{ "BLF-CRYPT", PW_ENCODING_NONE, 0, crypt_verify,
crypt_generate_blowfisch },
{ "SHA256-CRYPT", PW_ENCODING_NONE, 0, crypt_verify,
Expand Down
14 changes: 0 additions & 14 deletions src/auth/password-scheme.c
Expand Up @@ -341,19 +341,6 @@ int crypt_verify(const char *plaintext, const char *user ATTR_UNUSED,
return strcmp(crypted, password) == 0 ? 1 : 0;
}

static void
crypt_generate(const char *plaintext, const char *user ATTR_UNUSED,
const unsigned char **raw_password_r, size_t *size_r)
{
#define CRYPT_SALT_LEN 2
const char *password, *salt;

salt = password_generate_salt(CRYPT_SALT_LEN);
password = t_strdup(mycrypt(plaintext, salt));
*raw_password_r = (const unsigned char *)password;
*size_r = strlen(password);
}

static int
md5_verify(const char *plaintext, const char *user,
const unsigned char *raw_password, size_t size, const char **error_r)
Expand Down Expand Up @@ -803,7 +790,6 @@ rpa_generate(const char *plaintext, const char *user ATTR_UNUSED,
}

static const struct password_scheme builtin_schemes[] = {
{ "CRYPT", PW_ENCODING_NONE, 0, crypt_verify, crypt_generate },
{ "MD5", PW_ENCODING_NONE, 0, md5_verify, md5_crypt_generate },
{ "MD5-CRYPT", PW_ENCODING_NONE, 0,
md5_crypt_verify, md5_crypt_generate },
Expand Down

0 comments on commit 54a1b35

Please sign in to comment.