--- myauth-1.2/mod_myauth.c.orig Sat Jan 22 17:57:56 2005 +++ myauth-1.2/mod_myauth.c Sat Jan 29 16:18:29 2005 @@ -27,6 +27,13 @@ #define ENC_CRYPT 2 #define ENC_MYSQL 4 /* default */ +#ifdef USE_OPENSSL +#include +#include +#define ENC_MD5BASE64 8 +#else +#define ENC_MD5BASE64 0 +#endif typedef struct { char *my_host; @@ -102,8 +109,10 @@ cfg->my_enctype |= ENC_CRYPT; if (strcasecmp (arg[i], "MySQL") == 0) cfg->my_enctype |= ENC_MYSQL; + if (strcasecmp (arg[i], "MD5Base64") == 0) + cfg->my_enctype |= ENC_MD5BASE64; if (strcasecmp (arg[i], "All") == 0) - cfg->my_enctype |= (ENC_PLAIN|ENC_CRYPT|ENC_MYSQL); + cfg->my_enctype |= (ENC_PLAIN|ENC_CRYPT|ENC_MYSQL|ENC_MD5BASE64); } return NULL; } @@ -276,11 +285,71 @@ return grptbl; } +#ifdef USE_OPENSSL +/** + Database and OS independent encryption: Create an MD5 digest from + msg, Base64 encode the obtained digest and store the result in buf. + + @param msg string to encode + @param buf where to store the null terminated result of encoding. + If buflen is actually smaller than the result, the result + is truncated, but still null-terminated. + @param buflen max. length of buf (including null-terminator) + + @return the length of the encoded string. +*/ +static int md5base64(const char *msg, char *buf, int buflen) +{ + EVP_MD_CTX mdctx; + const EVP_MD *md; + unsigned char md_value[EVP_MAX_MD_SIZE]; + int md_len, i; + BIO *mem, *bio, *b64; + + memset(buf, 0, buflen); + + /* digest md5 */ + md = EVP_md5(); + if(!md) { + return 0; + } + EVP_MD_CTX_init(&mdctx); + EVP_DigestInit_ex(&mdctx, md, NULL); + EVP_DigestUpdate(&mdctx, msg, strlen(msg)); + EVP_DigestFinal_ex(&mdctx, md_value, &md_len); + EVP_MD_CTX_cleanup(&mdctx); + + /* base64 encoding */ + b64 = BIO_new(BIO_f_base64()); + mem = BIO_new(BIO_s_mem()); + bio = BIO_push(b64, mem); + + BIO_write(bio, md_value, md_len); + BIO_flush(bio); + + i = BIO_read(mem, buf, buflen); + if (i > 0) { + i--; /* kill the newline char */ + } else { + i = 0; + } + buf[i] = '\0'; + BIO_free_all(bio); + return i; +} +#endif static int valid_pw (request_rec *r, const char *sent, const char *real, const int etyp) { char my_pw[64]; +#ifdef USE_OPENSSL + if (etyp & ENC_MD5BASE64) { + int i = md5base64(sent, my_pw, sizeof(my_pw)); + if (i > 0 && strcmp(real, my_pw) == 0) + return 1; + } +#endif if (etyp & ENC_MYSQL) { #ifdef HAVE_MAKE_SCRAMBLED_PASSWORD make_scrambled_password (my_pw, sent); @@ -304,7 +373,7 @@ /* Module initialization handler */ static int myauth_init_handler(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { - ap_add_version_component(pconf, "MyAuth/1.2"); + ap_add_version_component(pconf, "MyAuth/1.2jel"); return OK; }