Project

General

Profile

RE: How to deal with "salt" using authMSQL? ยป mod_auth_mysql-3.0.0-redmine.patch

richard rigby, 2011-08-16 19:19

View differences:

mod_auth_mysql-3.0.0/mod_auth_mysql.c 2011-08-16 18:03:17.000000000 +0100
static short pw_aes(POOL * pool, const char * real_pw, const char * sent_pw, const char * salt);
#endif
static short pw_sha1(POOL * pool, const char * real_pw, const char * sent_pw, const char * salt);
static short pw_sha1_rm(POOL * pool, const char * real_pw, const char * sent_pw, const char * salt);
static short pw_plain(POOL * pool, const char * real_pw, const char * sent_pw, const char * salt);
static char * format_remote_host(request_rec * r, char ** parm);
......
#if _AES
{"aes", SALT_REQUIRED, pw_aes},
#endif
{"sha1", NO_SALT, pw_sha1}};
{"sha1", NO_SALT, pw_sha1},
{"sha1-rm", SALT_OPTIONAL, pw_sha1_rm}};
typedef struct { /* User formatting patterns */
char pattern; /* Pattern to match */
char * (*func)(request_rec * r, char ** parm);
......
return strcasecmp(bin2hex(pool, scrambled_sent_pw, enc_len), real_pw) == 0;
}
/* checks SHA1 passwords - adjusted for use with redmine */
static short pw_sha1_rm(POOL * pool, const char * real_pw, const char * sent_pw, const char * salt) {
char salt_and_pw[500];
char scrambled_pw[500];
char *scrambled_sent_pw, *buffer=PCALLOC(pool, 128);
char *scrambled_salt_pw, *buffer01=PCALLOC(pool, 128);
short enc_len = 0;
short enc_len01 = 0;
#ifdef APACHE2
apr_sha1_base64(sent_pw, strlen(sent_pw), buffer);
buffer += 5; /* go past {SHA1} eyecatcher */
scrambled_sent_pw = PCALLOC(pool, apr_base64_decode_len(buffer) + 1);
enc_len = apr_base64_decode(scrambled_sent_pw, buffer);
//scramble (salt+scrambled_pw) for redmine:
strcpy(salt_and_pw,salt);
strcpy(scrambled_pw,bin2hex(pool, scrambled_sent_pw, enc_len));
//conver scrambled_pw to lower:
int i;
for (i = 0; scrambled_pw[i]; i++)
scrambled_pw[i] =tolower(scrambled_pw[ i ]);
//cat salt + scrambled_pw:
strcat(salt_and_pw,scrambled_pw);
apr_sha1_base64(salt_and_pw, strlen(salt_and_pw), buffer01);
buffer01 += 5; /* go past {SHA1} eyecatcher */
scrambled_salt_pw = PCALLOC(pool, apr_base64_decode_len(buffer01) + 1);
enc_len01 = apr_base64_decode(scrambled_salt_pw, buffer01);
#else
ap_sha1_base64(sent_pw, strlen(sent_pw), buffer);
buffer += 5; /* go past {SHA1} eyecatcher */
scrambled_sent_pw = PCALLOC(pool, ap_base64decode_len(buffer) + 1);
enc_len = ap_base64decode(scrambled_sent_pw, buffer);
#endif
scrambled_sent_pw[enc_len] = '\0';
return strcasecmp(bin2hex(pool, scrambled_salt_pw, enc_len), real_pw) == 0;
}
/* checks plain text passwords */
static short pw_plain(POOL * pool, const char * real_pw, const char * sent_pw, const char * salt) {
return strcmp(real_pw, sent_pw) == 0;
    (1-1/1)