diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/HttpServ.cc | 25 | ||||
-rw-r--r-- | lib/LuaHttp.cc | 46 |
2 files changed, 39 insertions, 32 deletions
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index ff61f1b..23f45d4 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -17,9 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: HttpServ.cc,v 1.57 2007-09-28 09:07:13 pixel Exp $ */ +/* $Id: HttpServ.cc,v 1.58 2007-09-28 09:23:36 pixel Exp $ */ -#include "sha1.h" #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -33,6 +32,7 @@ #include "Task.h" #include "Base64.h" #include "Domain.h" +#include "HashFunction.h" #include "gettext.h" String endhl = "\r\n", endnl = "\n"; @@ -672,24 +672,13 @@ void HttpResponse::PrepareResponse(Handle * b) { break; case HTTP_401_UNAUTHORIZED: if (domain != "") { - String to_digest; - sha1_context sha1; - static const char hconv[] = "0123456789ABCDEF"; - Uint8 sha1sum[20]; - char sha1sum_r[41]; - int i; + SHA1 h; + String digest; - to_digest = location + ":" + ((Uint64) time(0)) + ":" + domain + ":" + rand(); - sha1_starts(&sha1); - sha1_update(&sha1, (const unsigned char *) to_digest.to_charp(), to_digest.strlen()); - sha1_finish(&sha1, sha1sum); + h.Update(location + ":" + ((Uint64) time(0)) + ":" + domain + ":" + rand()); + digest = h.Finish(); - for (i = 0; i < 20; i++) { - sha1sum_r[i * 2 + 0] = hconv[sha1sum[i] >> 4]; - sha1sum_r[i * 2 + 1] = hconv[sha1sum[i] % 16]; - } - sha1sum_r[40] = 0; - (*b) << "WWW-Authenticate: Digest realm=\"" << location << "\", domain=\"" << domain << "\", nonce=\"" << sha1sum_r << "\", algorithm=\"MD5\", qop=\"auth\"\r\n"; + (*b) << "WWW-Authenticate: Digest realm=\"" << location << "\", domain=\"" << domain << "\", nonce=\"" << digest << "\", algorithm=\"MD5\", qop=\"auth\"\r\n"; } else { (*b) << "WWW-Authenticate: Basic realm=\"" << location << "\"\r\n"; } diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index 4dea10e..3324dff 100644 --- a/lib/LuaHttp.cc +++ b/lib/LuaHttp.cc @@ -17,14 +17,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: LuaHttp.cc,v 1.21 2007-07-27 10:05:52 pixel Exp $ */ +/* $Id: LuaHttp.cc,v 1.22 2007-09-28 09:23:36 pixel Exp $ */ -#include "md5.h" #include "Domain.h" #include "LuaHttp.h" #include "LuaHandle.h" #include "LuaTask.h" #include "Base64.h" +#include "HashFunction.h" class LuaDomain : public Domain { public: @@ -121,6 +121,8 @@ enum HttpResponse_functions_t { HTTPRESPONSE_BASE64_ENCODE, HTTPRESPONSE_BASE64_DECODE, HTTPRESPONSE_MD5, + HTTPRESPONSE_SHA1, + HTTPRESPONSE_SHA256, }; struct lua_functypes_t HttpResponse_methods[] = { @@ -134,6 +136,8 @@ struct lua_functypes_t HttpResponse_functions[] = { { HTTPRESPONSE_BASE64_ENCODE, "Base64Encode", 1, 1, { BLUA_STRING } }, { HTTPRESPONSE_BASE64_DECODE, "Base64Decode", 1, 1, { BLUA_STRING } }, { HTTPRESPONSE_MD5, "MD5", 1, 1, { BLUA_STRING } }, + { HTTPRESPONSE_SHA1, "SHA1", 1, 1, { BLUA_STRING } }, + { HTTPRESPONSE_SHA256, "SHA256", 1, 1, { BLUA_STRING } }, { -1, 0, 0, 0, 0 } }; @@ -146,6 +150,8 @@ class sLua_HttpResponse : public Base { DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_ENCODE); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE); DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_MD5); + DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1); + DECLARE_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256); private: static int HttpResponse_proceed(Lua * L, int n, HttpResponse * obj, int caller); static int HttpResponse_proceed_statics(Lua * L, int n, int caller); @@ -166,6 +172,8 @@ void LuaHttpResponse::pushstatics(Lua * L) throw (GeneralException) { PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_ENCODE); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_BASE64_DECODE); PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_MD5); + PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA1); + PUSH_FUNCTION(HttpResponse, HTTPRESPONSE_SHA256); export_enum(L, HTTP_200_OK); export_enum(L, HTTP_301_PERM_MOVED); @@ -243,10 +251,6 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) String enc, dec; char * enc_t; const char * dec_t; - md5_context ctx; - unsigned char md5sum[16]; - String md5sum_r; - static const char hconv[] = "0123456789ABCDEF"; switch (caller) { case HTTPRESPONSE_NEWHTTPRESPONSE: @@ -273,15 +277,29 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) case HTTPRESPONSE_MD5: dec = L->tostring(); - dec_t = dec.to_charp(); - md5_starts(&ctx); - md5_update(&ctx, (uint8 *) dec_t, dec.strlen()); - md5_finish(&ctx, md5sum); - for (i = 0; i < 16; i++) { - md5sum_r = md5sum_r + hconv[md5sum[i] >> 4]; - md5sum_r = md5sum_r + hconv[md5sum[i] % 16]; + { + MD5 h; + h.Update(dec); + L->push(h.Finish()); + } + r = 1; + break; + case HTTPRESPONSE_SHA1: + dec = L->tostring(); + { + SHA1 h; + h.Update(dec); + L->push(h.Finish()); + } + r = 1; + break; + case HTTPRESPONSE_SHA256: + dec = L->tostring(); + { + SHA256 h; + h.Update(dec); + L->push(h.Finish()); } - L->push(md5sum_r); r = 1; break; } |