gsasl-commit
[Top][All Lists]
Advanced

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

[SCM] GNU gsasl branch, master, updated. gsasl-1-2-57-gdab8307


From: Simon Josefsson
Subject: [SCM] GNU gsasl branch, master, updated. gsasl-1-2-57-gdab8307
Date: Thu, 10 Sep 2009 09:05:01 +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 gsasl".

http://git.savannah.gnu.org/cgit/gsasl.git/commit/?id=dab8307beda64351712a653ffbe94b3045bc4a4c

The branch, master has been updated
       via  dab8307beda64351712a653ffbe94b3045bc4a4c (commit)
      from  5fe79a35e15190b1675d771927384d0f6a3d2f5e (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 dab8307beda64351712a653ffbe94b3045bc4a4c
Author: Simon Josefsson <address@hidden>
Date:   Thu Sep 10 11:04:57 2009 +0200

    SCRAM: Parsing of server first works.

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

Summary of changes:
 lib/scram/client.c |   21 +++++++++-
 lib/scram/parser.c |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/scram/parser.h |    3 +
 lib/scram/server.c |    6 +--
 4 files changed, 128 insertions(+), 8 deletions(-)

diff --git a/lib/scram/client.c b/lib/scram/client.c
index 29caa0a..1e4adee 100644
--- a/lib/scram/client.c
+++ b/lib/scram/client.c
@@ -42,6 +42,7 @@ struct scram_client_state
 {
   int step;
   char cnonce[CNONCE_ENTROPY_BYTES + 1];
+  struct scram_server_first sf;
 };
 
 int
@@ -51,12 +52,10 @@ _gsasl_scram_sha1_client_start (Gsasl_session * sctx, void 
**mech_data)
   size_t i;
   int rc;
 
-  state = (struct scram_client_state *) malloc (sizeof (*state));
+  state = (struct scram_client_state *) calloc (sizeof (*state), 1);
   if (state == NULL)
     return GSASL_MALLOC_ERROR;
 
-  state->step = 0;
-
   rc = gsasl_nonce (state->cnonce, CNONCE_ENTROPY_BYTES);
   if (rc != GSASL_OK)
     return rc;
@@ -88,6 +87,9 @@ _gsasl_scram_sha1_client_step (Gsasl_session * sctx,
   struct scram_client_state *state = mech_data;
   int res = GSASL_MECHANISM_CALLED_TOO_MANY_TIMES;
 
+  *output = NULL;
+  *output_len = 0;
+
   switch (state->step)
     {
     case 0:
@@ -123,6 +125,19 @@ _gsasl_scram_sha1_client_step (Gsasl_session * sctx,
        break;
       }
 
+    case 1:
+      {
+       if (strlen (input) != input_len)
+         return GSASL_MECHANISM_PARSE_ERROR;
+
+       if (scram_parse_server_first (input, &state->sf) < 0)
+         return GSASL_MECHANISM_PARSE_ERROR;
+
+       state->step++;
+       return GSASL_NEEDS_MORE;
+       break;
+      }
+
     default:
       break;
     }
diff --git a/lib/scram/parser.c b/lib/scram/parser.c
index a8e7b50..f43054f 100644
--- a/lib/scram/parser.c
+++ b/lib/scram/parser.c
@@ -123,5 +123,111 @@ scram_parse_client_first (const char *str,
 
   /* FIXME check that any extension fields follow valid syntax. */
 
+  if (scram_valid_client_first (cf) < 0)
+    return -1;
+
+  return 0;
+}
+
+int
+scram_parse_server_first (const char *str,
+                         struct scram_server_first *sf)
+{
+  /* Minimum server first string is 'r=ab,s=biws,i=1'. */
+  if (strlen (str) < 15)
+    return -1;
+
+  if (*str++ != 'r')
+    return -1;
+
+  if (*str++ != '=')
+    return -1;
+
+  {
+    char *p;
+    size_t len;
+
+    p = strchr (str, ',');
+    if (!p)
+      return -1;
+
+    len = p - str;
+
+    sf->nonce = malloc (len + 1);
+    if (!sf->nonce)
+      return -1;
+
+    memcpy (sf->nonce, str, len);
+    sf->nonce[len] = '\0';
+
+    str = p;
+  }
+
+  if (*str++ != ',')
+    return -1;
+
+  if (*str++ != 's')
+    return -1;
+
+  if (*str++ != '=')
+    return -1;
+
+  {
+    char *p;
+    size_t len;
+
+    p = strchr (str, ',');
+    if (!p)
+      return -1;
+
+    len = p - str;
+
+    sf->salt = malloc (len + 1);
+    if (!sf->salt)
+      return -1;
+
+    memcpy (sf->salt, str, len);
+    sf->salt[len] = '\0';
+
+    /* FIXME check that salt is valid base64. */
+
+    str = p;
+  }
+
+  if (*str++ != ',')
+    return -1;
+
+  if (*str++ != 'i')
+    return -1;
+
+  if (*str++ != '=')
+    return -1;
+
+  {
+    const char *p;
+
+    sf->iter = 0;
+    for (p = str; *p >= '0' && *p <= '9'; p++)
+      {
+       size_t last_iter = sf->iter;
+
+       sf->iter = sf->iter * 10 + (*p - '0');
+
+       /* Protect against wrap arounds. */
+       if (sf->iter < last_iter)
+         return -1;
+      }
+
+    if (*p != ',' && *p != '\0')
+      return -1;
+
+    str = p;
+  }
+
+  /* FIXME check that any extension fields follow valid syntax. */
+
+  if (scram_valid_server_first (sf) < 0)
+    return -1;
+
   return 0;
 }
diff --git a/lib/scram/parser.h b/lib/scram/parser.h
index 34fbda4..17ff895 100644
--- a/lib/scram/parser.h
+++ b/lib/scram/parser.h
@@ -29,4 +29,7 @@
 extern int scram_parse_client_first (const char *str,
                                     struct scram_client_first *cf);
 
+extern int scram_parse_server_first (const char *str,
+                                    struct scram_server_first *cf);
+
 #endif /* SCRAM_PARSER_H */
diff --git a/lib/scram/server.c b/lib/scram/server.c
index 3ebbae2..7e7cbf7 100644
--- a/lib/scram/server.c
+++ b/lib/scram/server.c
@@ -35,7 +35,7 @@
 
 #include "tokens.h"
 #include "parser.h"
-#include "validate.h"
+#include "printer.h"
 
 #define SNONCE_ENTROPY_BYTES 16
 
@@ -104,9 +104,6 @@ _gsasl_scram_sha1_server_step (Gsasl_session * sctx,
        if (scram_parse_client_first (input, &state->cf) < 0)
          return GSASL_MECHANISM_PARSE_ERROR;
 
-       if (scram_valid_client_first (&state->cf) < 0)
-         return GSASL_MECHANISM_PARSE_ERROR;
-
        /* Create new nonce. */
        {
          size_t cnlen = strlen (state->cf.client_nonce);
@@ -135,7 +132,6 @@ _gsasl_scram_sha1_server_step (Gsasl_session * sctx,
        break;
       }
 
-
     default:
       break;
     }


hooks/post-receive
-- 
GNU gsasl




reply via email to

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