diff -ur gq-0.4.0.orig/AUTHORS gq-0.4.0/AUTHORS --- gq-0.4.0.orig/AUTHORS Thu May 4 17:36:52 2000 +++ gq-0.4.0/AUTHORS Thu Jan 17 19:18:26 2002 @@ -1 +1,4 @@ Bert Vermeulen + +Keith Garner - helped add openldap friendly md5 and sha +Dave Dribin - helped add openldap friendly md5 and sha diff -ur gq-0.4.0.orig/src/encode.c gq-0.4.0/src/encode.c --- gq-0.4.0.orig/src/encode.c Mon Feb 19 19:08:25 2001 +++ gq-0.4.0/src/encode.c Thu Jan 17 19:15:49 2002 @@ -34,6 +34,9 @@ #include #include #include +#include +#include +#include #include #include @@ -45,6 +48,9 @@ #include "encode.h" +static void base64_encode(char *dest, int dest_max_length, const char *src, + int src_length); + extern struct tokenlist cryptmap[]; @@ -111,36 +117,62 @@ } - void encode_password_md5(struct formfill *form) { - int i; - unsigned char *password, password_out[64], md5_out[MD5_DIGEST_LENGTH]; + unsigned char *password, password_out[64], tmp_pout[64], md5_out[MD5_DIGEST_LENGTH]; password = form->values->data; MD5(password, strlen(password), md5_out); strcpy(password_out, "{md5}"); - for(i = 0; i < MD5_DIGEST_LENGTH; i++) - sprintf(password_out + strlen(password_out), "%.02x", md5_out[i]); + base64_encode(tmp_pout, sizeof(tmp_pout), md5_out, sizeof(md5_out)); + strncat(password_out, tmp_pout, 58); + g_free(form->values->data); form->values->data = g_strdup(password_out); - } + void encode_password_sha1(struct formfill *form) { - int i; - unsigned char *password, password_out[64], sha1_out[SHA_DIGEST_LENGTH]; + unsigned char *password, password_out[64], tmp_pout[64], sha1_out[SHA_DIGEST_LENGTH]; password = form->values->data; SHA1(password, strlen(password), sha1_out); strcpy(password_out, "{sha}"); - for(i = 0; i < SHA_DIGEST_LENGTH; i++) - sprintf(password_out + strlen(password_out), "%.02x", sha1_out[i]); + base64_encode(tmp_pout, sizeof(tmp_pout), sha1_out, sizeof(sha1_out)); + strncat(password_out, tmp_pout, 58); + g_free(form->values->data); form->values->data = g_strdup(password_out); +} + +static void base64_encode(char *dest, int dest_max_length, const char *src, + int src_length) +{ + BIO *b64, *bio; + BUF_MEM *mem; + int copy_size; + + b64 = BIO_new(BIO_f_base64()); + BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); + bio = BIO_new(BIO_s_mem()); + bio = BIO_push(b64, bio); + BIO_write(bio, src, src_length); + BIO_flush(bio); + BIO_get_mem_ptr(bio, &mem); + BIO_set_close(bio, BIO_NOCLOSE); + BIO_free_all(bio); + + if (mem->length > dest_max_length) + copy_size = dest_max_length - 1; + else + copy_size = mem->length; + memcpy(dest, mem->data, copy_size); + dest[copy_size] = '\0'; + + BUF_MEM_free(mem); } #endif