myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9-386-g2


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9-386-g2238941
Date: Sun, 08 Nov 2009 18:27:53 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  223894195e5151fa6533dfe9905c39c814f74e42 (commit)
       via  da718a2dc3c571cce3cb63eb340b9acee4148d46 (commit)
      from  3391c897eab91cee315af98ca0b7390be80626af (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 223894195e5151fa6533dfe9905c39c814f74e42
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Nov 8 19:21:47 2009 +0100

    The AuthMethod::comparePassword method does not raise exceptions.
    
    Now AuthMethod::comparePassword catches any exception that
    CryptAlgoManager::check throws.  It is required in order to don't fail
    when an algorithm non present in the CryptAlgoManager collection is
    used.  This is the case of HTTP Digest A1.

diff --git a/myserver/documentation/security.texi 
b/myserver/documentation/security.texi
index cf1087f..3280c7a 100644
--- a/myserver/documentation/security.texi
+++ b/myserver/documentation/security.texi
@@ -88,6 +88,29 @@ the client specified password before compare it with the
 </SECURITY>
 @end example
 
address@hidden Http Digest
+If the HTTP digest authorization scheme is used, it is not possible to
+use any password hash but the original clear-text password.  The only
+exception to this rule is to specify the A1 part in the Digest
+scheme.
+
+It is computed by the function: MD5 (username:realm:password).
+
address@hidden
+  <DEFINE name="http.auth" value="digest" />
+  <USER name="user" algorithm="a1" password="c2deada0bcb64f99e65be0d33bb92d54"
+        READ="YES" EXECUTE="YES" BROWSE="YES" WRITE="NO"/>
address@hidden example
+
+The realm value used by MyServer is the virtual host name, including
+the port number, i.e. @example{localhost:8080}.
+The A1 password can be computed using the following shell command, be
+sure to use the right user, realm and password values.
+
address@hidden
+  printf "%s:%s:%s" user realm password | md5sum
address@hidden example
+
 @subsection FTP Anonymous user
 To allow the @file{.security.xml} re-use, the FTP ``Anonymous'' user
 is mapped internally by MyServer to the ``Guest'' user.
diff --git a/myserver/src/conf/security/auth_method.cpp 
b/myserver/src/conf/security/auth_method.cpp
index 2b2ff51..94bda0d 100644
--- a/myserver/src/conf/security/auth_method.cpp
+++ b/myserver/src/conf/security/auth_method.cpp
@@ -55,7 +55,14 @@ bool AuthMethod::comparePassword (const char *password,
       string savedpwStr (savedPassword);
       string algorithmStr (algorithm);
 
-      return cryptAlgoManager->check (savedpwStr, pwStr, algorithmStr);
+      try
+        {
+          return cryptAlgoManager->check (savedpwStr, pwStr, algorithmStr);
+        }
+      catch (...)
+        {
+          return false;
+        }
     }
 
   return false;
diff --git a/myserver/src/protocol/http/http.cpp 
b/myserver/src/protocol/http/http.cpp
index 27bd947..0348e6f 100644
--- a/myserver/src/protocol/http/http.cpp
+++ b/myserver/src/protocol/http/http.cpp
@@ -62,6 +62,25 @@ extern "C"
 #endif
 }
 
+/*FIXME: Move somewhere else.  */
+class HttpInternalException : public exception
+{
+public:
+  virtual const char *what () const throw ()
+  {
+    return message;
+  }
+
+  HttpInternalException (string & str)
+  {
+    this->message = str.c_str ();
+  }
+
+private:
+  const char *message;
+};
+
+
 int HttpProtocol::loadProtocol ()
 {
   const char *data = NULL;
@@ -378,7 +397,17 @@ int Http::getFilePermissions (string& filename, string& 
directory, string& file,
           if (!td->request.auth.compare ("Digest"))
             {
               if (!hud->digestChecked)
-                hud->digest = checkDigest ();
+                {
+                  try
+                    {
+                      hud->digest = checkDigest ();
+                    }
+                  catch (exception & e)
+                    {
+                      td->connection->host->warningsLogWrite (e.what ());
+                      return raiseHTTPError (500);
+                    }
+                }
 
               hud->digestChecked = 1;
               if (hud->digest == 1)
@@ -388,6 +417,9 @@ int Http::getFilePermissions (string& filename, string& 
directory, string& file,
                   *permissions = td->securityToken.getProvidedMask ();
                 }
             }
+          else
+            *permissions = 0;
+
           td->authScheme = HTTP_AUTH_SCHEME_DIGEST;
         }
       /* By default use the Basic authentication scheme. */
@@ -538,6 +570,9 @@ int Http::deleteHTTPRESOURCE (string& filename, int sysReq, 
int onlyHeader,
 
 /*!
  * Check the Digest authorization
+ *
+ * \return 1 if the client credentials are OK.
+ * \return 0 if the credentials are wrong.
  */
 u_long Http::checkDigest ()
 {
@@ -582,10 +617,10 @@ u_long Http::checkDigest ()
     }
   else
     {
-      td->connection->host->warningsLogWrite
-        (_("HTTP: internal error, when using digest auth only a1 and "  \
-           "cleartext passwords can be used"));
-      return 0;
+      string err (_("HTTP: internal error, when using digest auth only "\
+                    "a1 and cleartext passwords can be used"));
+
+      throw HttpInternalException (err);
     }
 
   md5.init ();
@@ -603,9 +638,10 @@ u_long Http::checkDigest ()
   md5.init ();
   td->auxiliaryBuffer->setLength (0);
   *td->auxiliaryBuffer << A1 << ":"
-          << hud->nonce << ":"
-          << td->request.digestNc << ":" << td->request.digestCnonce << ":"
-          << td->request.digestQop << ":" << A2;
+                       << hud->nonce << ":"
+                       << td->request.digestNc << ":"
+                       << td->request.digestCnonce << ":"
+                       << td->request.digestQop << ":" << A2;
   md5.update (*td->auxiliaryBuffer);
   md5.end (response);
 
@@ -1270,12 +1306,12 @@ int Http::requestAuthorization ()
         }
 
       *td->auxiliaryBuffer << "WWW-Authenticate: digest "
-                           << " qop=\"auth\", algorithm =\"MD5\", realm =\""
-                           << hud->realm << "\",  opaque =\"" << hud->opaque
-                           << "\",  nonce =\"" << hud->nonce << "\" ";
+                           << " qop=\"auth\", algorithm=\"MD5\", realm=\""
+                           << hud->realm << "\", opaque=\"" << hud->opaque
+                           << "\",  nonce=\"" << hud->nonce << "\" ";
 
       if (hud->cnonce[0])
-        *td->auxiliaryBuffer << ", cnonce =\"" << hud->cnonce << "\" ";
+        *td->auxiliaryBuffer << ", cnonce=\"" << hud->cnonce << "\" ";
 
       *td->auxiliaryBuffer << "\r\n";
     }
diff --git a/myserver/src/protocol/http/http_headers.cpp 
b/myserver/src/protocol/http/http_headers.cpp
index 3b13868..d5e5dac 100644
--- a/myserver/src/protocol/http/http_headers.cpp
+++ b/myserver/src/protocol/http/http_headers.cpp
@@ -693,7 +693,7 @@ int HttpHeaders::readReqRangeLine (HttpRequestHeader 
*request,
  * \param request HttpRequest object to fill.
  * \param connection Pointer to a connection structure.
  * \param token Pointer to the beginning of the authorization line.
- * \param lenOut Pointer to an itneger to keep the line length.
+ * \param lenOut Pointer to an integer to keep the line length.
  * \return 0 on success, any other value is the HTTP error.
  */
 int HttpHeaders::readReqAuthLine (HttpRequestHeader *request,
@@ -701,6 +701,8 @@ int HttpHeaders::readReqAuthLine (HttpRequestHeader 
*request,
                                   const char *token,
                                   int *lenOut)
 {
+  const char *origToken = token;
+
   while (*token==' ')
     token++;
   int tokenOff = getCharInString (token, " ", HTTP_REQUEST_AUTH_DIM);
@@ -752,7 +754,11 @@ int HttpHeaders::readReqAuthLine (HttpRequestHeader 
*request,
       connection->setLogin (login);
       connection->setPassword (password);
       delete decodedPwBuf;
+
       *lenOut = tokenOff = getEndLine (token, 100);
+      if (tokenOff == -1)
+        return 400;
+      *lenOut += token - origToken;
     }
   else if (!request->auth.compare ("Digest"))
     {
@@ -766,9 +772,12 @@ int HttpHeaders::readReqAuthLine (HttpRequestHeader 
*request,
       if (tokenOff == -1)
         return 400;
 
+      *lenOut += token - origToken;
+
+
       digestBuff = new char[tokenOff + 1];
       if (!digestBuff)
-        return 400;
+        return 500;
 
       memcpy (digestBuff, token, tokenOff);
       digestBuff[tokenOff] = '\0';
diff --git a/myserver/tests/test_auth_method.cpp 
b/myserver/tests/test_auth_method.cpp
index 65d2e25..3e9bf09 100644
--- a/myserver/tests/test_auth_method.cpp
+++ b/myserver/tests/test_auth_method.cpp
@@ -49,6 +49,7 @@ class TestAuthMethod : public CppUnit::TestFixture
   CPPUNIT_TEST (testCryptAlgoManager);
   CPPUNIT_TEST (testGetPermissionMask);
   CPPUNIT_TEST (testComparePassword);
+  CPPUNIT_TEST (testNoException);
   CPPUNIT_TEST_SUITE_END ();
 
 public:
@@ -78,6 +79,24 @@ public:
     CPPUNIT_ASSERT (tam.getPermissionMask (&st) >= 0);
   }
 
+  void testNoException ()
+  {
+    TestAuthMethodImpl tam;
+    CryptAlgoManager cam;
+    Md5::initialize (&cam);
+
+    try
+      {
+        tam.exposeComparePassword ("d5aa1729c8c253e5d917a5264855eab8",
+                                   "freedom",
+                                   "md5555");
+      }
+    catch (...)
+      {
+        CPPUNIT_FAIL ("exception raised!");
+      }
+  }
+
   void testComparePassword ()
   {
     TestAuthMethodImpl tam;
diff --git a/myserver/tests/test_http_request.cpp 
b/myserver/tests/test_http_request.cpp
index 5c70416..5ab9a3c 100644
--- a/myserver/tests/test_http_request.cpp
+++ b/myserver/tests/test_http_request.cpp
@@ -34,13 +34,15 @@ using namespace std;
 
 class TestHttpRequest : public CppUnit::TestFixture
 {
-  CPPUNIT_TEST_SUITE ( TestHttpRequest );
-  CPPUNIT_TEST ( testSimpleHeader );
-  CPPUNIT_TEST ( testRange );
-  CPPUNIT_TEST ( testIncompleteHeader );
-  CPPUNIT_TEST ( testDefaultHttpRequest );
-  CPPUNIT_TEST ( testValidRequest );
-  CPPUNIT_TEST ( testResetHttpRequest );
+  CPPUNIT_TEST_SUITE (TestHttpRequest);
+  CPPUNIT_TEST (testSimpleHeader);
+  CPPUNIT_TEST (testAuthBasic);
+  CPPUNIT_TEST (testAuthDigest);
+  CPPUNIT_TEST (testRange);
+  CPPUNIT_TEST (testIncompleteHeader);
+  CPPUNIT_TEST (testDefaultHttpRequest);
+  CPPUNIT_TEST (testValidRequest);
+  CPPUNIT_TEST (testResetHttpRequest);
   CPPUNIT_TEST_SUITE_END ();
 
 public:
@@ -147,6 +149,66 @@ public:
   }
 
 
+  void testAuthDigest ()
+  {
+    HttpRequestHeader header;
+    Connection connection;
+    const char *requestStr;
+    u_long  bufferLength;
+    u_long requestLength;
+    int ret;
+
+    requestStr = "GET /resource HTTP/1.1\r\nHost: localhost\r\n" \
+      "Authorization: Digest username=\"user\", realm=\"localhost:8080\", "\
+      "nonce=\"88b29c4b136e2efee059647dbac10427\", uri=\"/res/\", " \
+      "algorithm=MD5, response=\"e979c020b57cc0e86e46d5c8cad8497e\", " \
+      "opaque=\"8666683506aacd900bbd5a74ac4edf68\", qop=auth, nc=00000001, " \
+      "cnonce=\"c40dc807904a2357\"\r\n\r\n";
+    bufferLength = strlen (requestStr);
+
+    ret = HttpHeaders::buildHTTPRequestHeaderStruct (requestStr,
+                                                    bufferLength,
+                                                    &requestLength,
+                                                    &header,
+                                                    &connection);
+    CPPUNIT_ASSERT (ret == 200);
+    CPPUNIT_ASSERT (!strcmp (header.digestRealm, "localhost:8080"));
+    CPPUNIT_ASSERT (!strcmp (header.digestOpaque,
+                             "8666683506aacd900bbd5a74ac4edf68"));
+    CPPUNIT_ASSERT (!strcmp (header.digestNonce,
+                             "88b29c4b136e2efee059647dbac10427"));
+    CPPUNIT_ASSERT (!strcmp (header.digestUri, "/res/"));
+    CPPUNIT_ASSERT (!strcmp (header.digestUsername, "user")); 
+    CPPUNIT_ASSERT (!strcmp (header.digestNc, "00000001")); 
+    CPPUNIT_ASSERT (!strcmp (header.digestQop, "auth")); 
+    CPPUNIT_ASSERT (!strcmp (header.digestResponse,
+                             "e979c020b57cc0e86e46d5c8cad8497e")); 
+    CPPUNIT_ASSERT (!strcmp (header.digestCnonce, "c40dc807904a2357")); 
+
+  }
+
+  void testAuthBasic ()
+  {
+    HttpRequestHeader header;
+    Connection connection;
+    const char *requestStr;
+    u_long  bufferLength;
+    u_long requestLength;
+    int ret;
+
+    requestStr = "GET /resource HTTP/1.1\r\nHost: localhost\r\n" \
+      "Authorization: Basic dXNlcjpmcmVlZG9t\r\n\r\n";
+
+    bufferLength = strlen (requestStr);
+
+    ret = HttpHeaders::buildHTTPRequestHeaderStruct (requestStr,
+                                                    bufferLength,
+                                                    &requestLength,
+                                                    &header,
+                                                    &connection);
+    CPPUNIT_ASSERT (ret == 200);
+  }
+
   void testDefaultHttpRequest ()
   {
     HttpRequestHeader header;



commit da718a2dc3c571cce3cb63eb340b9acee4148d46
Author: Giuseppe Scrivano <address@hidden>
Date:   Sun Nov 8 13:05:41 2009 +0100

    Add a facility method to the CryptAlgo class.

diff --git a/myserver/include/base/crypt/crypt_algo.h 
b/myserver/include/base/crypt/crypt_algo.h
index fc1e1e0..9bcabf5 100644
--- a/myserver/include/base/crypt/crypt_algo.h
+++ b/myserver/include/base/crypt/crypt_algo.h
@@ -21,6 +21,7 @@
 
 # include "stdafx.h"
 # include <include/base/hash_map/hash_map.h>
+# include <include/base/mem_buff/mem_buff.h>
 
 class CryptAlgo
 {
@@ -28,7 +29,8 @@ public:
   CryptAlgo ();
   ~CryptAlgo ();
   virtual void init ();
-  virtual void update (char const *buf, unsigned long len);
+  void update (MemBuf &buf) {update (buf.getBuffer (), buf.getLength ());}
+  virtual void update (char const *buf, u_long len);
   virtual char* end (char *buf);
 };
 
diff --git a/myserver/include/base/crypt/md5.h 
b/myserver/include/base/crypt/md5.h
index cdae047..0cdb079 100644
--- a/myserver/include/base/crypt/md5.h
+++ b/myserver/include/base/crypt/md5.h
@@ -27,10 +27,12 @@
 class Md5 : public CryptAlgo
 {
 public:
+  using CryptAlgo::update;
+
   Md5 ();
   virtual ~Md5 ();
   virtual void init ();
-  virtual void update (char const *buf, unsigned long len);
+  virtual void update (char const *buf, u_long len);
   virtual char* end (char *buf);
   static void initialize (CryptAlgoManager *manager);
   static CryptAlgo *md5Builder ();
diff --git a/myserver/include/base/crypt/sha1.h 
b/myserver/include/base/crypt/sha1.h
index 4829bef..b33ef54 100644
--- a/myserver/include/base/crypt/sha1.h
+++ b/myserver/include/base/crypt/sha1.h
@@ -33,10 +33,12 @@ extern "C"
 class Sha1 : public CryptAlgo
 {
 public:
+  using CryptAlgo::update;
+
   Sha1 ();
   virtual ~Sha1 ();
   virtual void init ();
-  virtual void update (char const *buf, unsigned long len);
+  virtual void update (char const *buf, u_long len);
   virtual char* end (char *buf);
   static void initialize (CryptAlgoManager *manager);
   static CryptAlgo *sha1Builder ();
diff --git a/myserver/src/base/crypt/crypt_algo.cpp 
b/myserver/src/base/crypt/crypt_algo.cpp
index 939554f..a0212c4 100644
--- a/myserver/src/base/crypt/crypt_algo.cpp
+++ b/myserver/src/base/crypt/crypt_algo.cpp
@@ -29,7 +29,7 @@ void CryptAlgo::init ()
 /*!
  * Write new data.
  */
-void CryptAlgo::update (char const *buf, unsigned long len)
+void CryptAlgo::update (char const *buf, u_long len)
 {
 
 }
diff --git a/myserver/src/base/crypt/md5.cpp b/myserver/src/base/crypt/md5.cpp
index f68361f..79da992 100644
--- a/myserver/src/base/crypt/md5.cpp
+++ b/myserver/src/base/crypt/md5.cpp
@@ -31,7 +31,7 @@ void Md5::init ()
  * Update context to reflect the concatenation of another buffer full
  * of bytes.
  */
-void Md5::update (char const *buf, unsigned long len)
+void Md5::update (char const *buf, u_long len)
 {
   md5_process_bytes (buf, len, &ctx);
 }
diff --git a/myserver/src/base/crypt/sha1.cpp b/myserver/src/base/crypt/sha1.cpp
index 34fe3df..a522657 100644
--- a/myserver/src/base/crypt/sha1.cpp
+++ b/myserver/src/base/crypt/sha1.cpp
@@ -31,7 +31,7 @@ void Sha1::init ()
  * Update context to reflect the concatenation of another buffer full
  * of bytes.
  */
-void Sha1::update (char const *buf, unsigned long len)
+void Sha1::update (char const *buf, u_long len)
 {
   sha1_process_bytes (buf, len, &ctx);
 }
diff --git a/myserver/src/protocol/http/http.cpp 
b/myserver/src/protocol/http/http.cpp
index eab482d..27bd947 100644
--- a/myserver/src/protocol/http/http.cpp
+++ b/myserver/src/protocol/http/http.cpp
@@ -545,18 +545,15 @@ u_long Http::checkDigest ()
   char A1[48];
   char A2[48];
   char response[48];
-  char *uri;
+  const char *uri;
   u_long digestCount;
   HttpUserData *hud =
     static_cast<HttpUserData*>(td->connection->protocolBuffer);
 
-
-  /* Return 0 if the password is different.  */
   if (td->request.digestOpaque[0]
       && strcmp (td->request.digestOpaque, hud->opaque))
     return 0;
 
-  /*! If is not equal return 0.  */
   if (strcmp (td->request.digestRealm, hud->realm))
     return 0;
 
@@ -566,7 +563,6 @@ u_long Http::checkDigest ()
   else
     hud->nc++;
 
-
   string &algorithm = td->securityToken.getAlgorithm ();
 
   if (algorithm.length () == 0)
@@ -577,8 +573,7 @@ u_long Http::checkDigest ()
                            << td->request.digestRealm
                            << ":" << td->securityToken.getNeededPassword ();
 
-      md5.update ((char const*) td->auxiliaryBuffer->getBuffer (),
-                  (unsigned int) td->auxiliaryBuffer->getLength ());
+      md5.update (*td->auxiliaryBuffer);
       md5.end (A1);
     }
   else if (algorithm.compare ("a1") == 0)
@@ -588,8 +583,8 @@ u_long Http::checkDigest ()
   else
     {
       td->connection->host->warningsLogWrite
-        (_("HTTP: internal error, when using digest auth only a1 and cleartext 
" \
-           "passwords can be used"));
+        (_("HTTP: internal error, when using digest auth only a1 and "  \
+           "cleartext passwords can be used"));
       return 0;
     }
 
@@ -598,12 +593,11 @@ u_long Http::checkDigest ()
   if (td->request.digestUri[0])
     uri = td->request.digestUri;
   else
-    uri = (char*) td->request.uriOpts.c_str ();
+    uri = td->request.uriOpts.c_str ();
 
   td->auxiliaryBuffer->setLength (0);
   *td->auxiliaryBuffer << td->request.cmd.c_str () << ":" << uri;
-  md5.update ((char const*) td->auxiliaryBuffer->getBuffer (),
-              (unsigned int) td->auxiliaryBuffer->getLength ());
+  md5.update (*td->auxiliaryBuffer);
   md5.end (A2);
 
   md5.init ();
@@ -612,8 +606,7 @@ u_long Http::checkDigest ()
           << hud->nonce << ":"
           << td->request.digestNc << ":" << td->request.digestCnonce << ":"
           << td->request.digestQop << ":" << A2;
-  md5.update ((char const*) td->auxiliaryBuffer->getBuffer (),
-              (unsigned int) td->auxiliaryBuffer->getLength ());
+  md5.update (*td->auxiliaryBuffer);
   md5.end (response);
 
   return strcmp (response, td->request.digestResponse) ? 0 : 1;
diff --git a/myserver/tests/test_md5.cpp b/myserver/tests/test_md5.cpp
index 6de4e59..ca2491d 100644
--- a/myserver/tests/test_md5.cpp
+++ b/myserver/tests/test_md5.cpp
@@ -29,8 +29,12 @@ class TestMd5 : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE ( TestMd5 );
   CPPUNIT_TEST ( testHash );
+  CPPUNIT_TEST ( testHashMemBuf );
   CPPUNIT_TEST_SUITE_END ();
 
+#define msg "hello world!\n"
+#define expected "c897d1410af8f2c74fba11b1db511e9e"
+
   Md5* md5;
 public:
   void setUp ()
@@ -47,19 +51,29 @@ public:
   void testHash ()
   {
     char out[33];
-    const char* msg = "hello world!\n";
-
-    char *expected = (char*) "c897d1410af8f2c74fba11b1db511e9e";
-
     md5->init ();
     md5->update (msg, strlen (msg));
     char *ret = md5->end (out);
 
     CPPUNIT_ASSERT_EQUAL (ret, &out[0]);
 
-    for (int i = 0; i < 32; i++)
-      CPPUNIT_ASSERT_EQUAL (tolower (expected[i]), tolower (out[i]));
+    CPPUNIT_ASSERT_EQUAL (memcmp (expected, out, 32), 0);
+  }
+
+
+  void testHashMemBuf ()
+  {
+    MemBuf buffer;
+    char out[33];
+    buffer << msg;
+
+    md5->init ();
+    md5->update (buffer);
+    char *ret = md5->end (out);
+
+    CPPUNIT_ASSERT_EQUAL (ret, &out[0]);
 
+    CPPUNIT_ASSERT_EQUAL (memcmp (expected, out, 32), 0);
   }
 };
 
diff --git a/myserver/tests/test_sha1.cpp b/myserver/tests/test_sha1.cpp
index 1cb0e7e..67e928e 100644
--- a/myserver/tests/test_sha1.cpp
+++ b/myserver/tests/test_sha1.cpp
@@ -28,9 +28,14 @@ class TestSha1 : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE ( TestSha1 );
   CPPUNIT_TEST ( testHash );
+  CPPUNIT_TEST ( testHashMemBuf );
   CPPUNIT_TEST_SUITE_END ();
 
   Sha1* sha1;
+
+#define msg "GNU is not UNIX"
+#define expected "5ef99232e377af054b479eae19b1b06d688f2a7e"
+
 public:
   void setUp ()
   {
@@ -46,18 +51,29 @@ public:
   void testHash ()
   {
     char out[45];
-    const char* msg = "GNU is not UNIX";
+    sha1->init ();
+    sha1->update (msg, strlen (msg));
+    char *ret = sha1->end (out);
 
-    char *expected = (char*) "5ef99232e377af054b479eae19b1b06d688f2a7e";
+    CPPUNIT_ASSERT_EQUAL (ret, &out[0]);
+
+    CPPUNIT_ASSERT_EQUAL (memcmp (expected, out, 32), 0);
+  }
+
+  void testHashMemBuf ()
+  {
+    MemBuf buffer;
+    char out[45];
+
+    buffer << msg;
 
     sha1->init ();
-    sha1->update (msg, strlen (msg));
+    sha1->update (buffer);
     char *ret = sha1->end (out);
 
     CPPUNIT_ASSERT_EQUAL (ret, &out[0]);
 
-    for (int i = 0; i < 32; i++)
-      CPPUNIT_ASSERT_EQUAL (tolower (expected[i]), tolower (out[i]));
+    CPPUNIT_ASSERT_EQUAL (memcmp (expected, out, 32), 0);
   }
 };
 

-----------------------------------------------------------------------

Summary of changes:
 myserver/documentation/security.texi        |   23 ++++++++
 myserver/include/base/crypt/crypt_algo.h    |    4 +-
 myserver/include/base/crypt/md5.h           |    4 +-
 myserver/include/base/crypt/sha1.h          |    4 +-
 myserver/src/base/crypt/crypt_algo.cpp      |    2 +-
 myserver/src/base/crypt/md5.cpp             |    2 +-
 myserver/src/base/crypt/sha1.cpp            |    2 +-
 myserver/src/conf/security/auth_method.cpp  |    9 +++-
 myserver/src/protocol/http/http.cpp         |   77 ++++++++++++++++++--------
 myserver/src/protocol/http/http_headers.cpp |   13 ++++-
 myserver/tests/test_auth_method.cpp         |   19 +++++++
 myserver/tests/test_http_request.cpp        |   76 ++++++++++++++++++++++++---
 myserver/tests/test_md5.cpp                 |   26 +++++++--
 myserver/tests/test_sha1.cpp                |   26 +++++++--
 14 files changed, 236 insertions(+), 51 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]