Author: poeml Date: Thu Apr 19 23:27:11 2012 New Revision: 8283 URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8283&view=rev Log: mod_mirrorbrain: - fix generation of HTTP Instance Digests. ap_pbase64encode() is not suitable to encode binary data; it supposes that '\0' ends a string. Rather use apr_base64_encode(). hex_to_b64() wraps the conversion from database hex to binary to base64. Modified: trunk/mod_mirrorbrain/mod_mirrorbrain.c Modified: trunk/mod_mirrorbrain/mod_mirrorbrain.c URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mod_mirrorbrain/mod_mirrorbrain.c?rev=8283&r1=8282&r2=8283&view=diff ============================================================================== --- trunk/mod_mirrorbrain/mod_mirrorbrain.c (original) +++ trunk/mod_mirrorbrain/mod_mirrorbrain.c Thu Apr 19 23:27:11 2012 _at_@ -77,6 +77,7 @@ #include "apr_lib.h" #include "apr_fnmatch.h" #include "apr_hash.h" +#include "apr_base64.h" #include "apr_dbd.h" #include "mod_dbd.h" _at_@ -1143,6 +1144,19 @@ } return dst; +} + +static char *hex_to_b64(request_rec *r, const char *src, unsigned binlen) +{ + char *bin, *encoded; + + bin = hex_decode(r, src, binlen); + + encoded = (char *) apr_palloc(r->pool, 1 + apr_base64_encode_len(binlen)); + binlen = apr_base64_encode(encoded, bin, binlen); + encoded[binlen] = '\0'; /* make binary sequence into string */ + + return encoded; } static hashbag_t *hashbag_fill(request_rec *r, ap_dbd_t *dbd, char *filename) _at_@ -3618,22 +3632,19 @@ if (hashbag->md5hex) { apr_table_addn(r->err_headers_out, "Digest", apr_pstrcat(r->pool, "MD5=", - ap_pbase64encode(r->pool, - hex_decode(r, hashbag->md5hex, MD5_DIGESTSIZE)), + hex_to_b64(r, hashbag->md5hex, MD5_DIGESTSIZE), NULL)); } if (hashbag->sha1hex) { apr_table_addn(r->err_headers_out, "Digest", apr_pstrcat(r->pool, "SHA=", - ap_pbase64encode(r->pool, - hex_decode(r, hashbag->sha1hex, SHA1_DIGESTSIZE)), + hex_to_b64(r, hashbag->sha1hex, SHA1_DIGESTSIZE), NULL)); } if (hashbag->sha256hex) { apr_table_addn(r->err_headers_out, "Digest", apr_pstrcat(r->pool, "SHA-256=", - ap_pbase64encode(r->pool, - hex_decode(r, hashbag->sha256hex, SHA256_DIGESTSIZE)), + hex_to_b64(r, hashbag->sha256hex, SHA256_DIGESTSIZE), NULL)); } } _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Thu Apr 19 2012 - 21:27:12 GMT
This archive was generated by hypermail 2.3.0 : Thu Apr 19 2012 - 21:32:03 GMT