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-37-g4a0a985


From: Simon Josefsson
Subject: [SCM] GNU gsasl branch, master, updated. gsasl-1-2-37-g4a0a985
Date: Wed, 09 Sep 2009 11:20:42 +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=4a0a985e1871a44a6ad55ae1da36c9031e093ad0

The branch, master has been updated
       via  4a0a985e1871a44a6ad55ae1da36c9031e093ad0 (commit)
       via  895195461c302a728d7bb3d17e81c6e544af7819 (commit)
      from  5c1260a9c4de38d748e3839a079f2e228ee21742 (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 4a0a985e1871a44a6ad55ae1da36c9031e093ad0
Author: Simon Josefsson <address@hidden>
Date:   Wed Sep 9 13:20:34 2009 +0200

    Add SCRAM printer functionality.

commit 895195461c302a728d7bb3d17e81c6e544af7819
Author: Simon Josefsson <address@hidden>
Date:   Wed Sep 9 13:04:20 2009 +0200

    Add SCRAM stuff.

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

Summary of changes:
 lib/scram/Makefile.am                      |    5 +-
 lib/scram/printer.c                        |   92 ++++++++++++++++++++++++++++
 lib/{digest-md5/qop.h => scram/printer.h}  |   15 +++--
 lib/{digest-md5/qop.h => scram/tokens.h}   |   21 +++++--
 lib/scram/validate.c                       |   68 ++++++++++++++++++++
 lib/{digest-md5/qop.h => scram/validate.h} |   17 +++--
 6 files changed, 199 insertions(+), 19 deletions(-)
 create mode 100644 lib/scram/printer.c
 copy lib/{digest-md5/qop.h => scram/printer.h} (76%)
 copy lib/{digest-md5/qop.h => scram/tokens.h} (75%)
 create mode 100644 lib/scram/validate.c
 copy lib/{digest-md5/qop.h => scram/validate.h} (74%)

diff --git a/lib/scram/Makefile.am b/lib/scram/Makefile.am
index ad024ed..f870b82 100644
--- a/lib/scram/Makefile.am
+++ b/lib/scram/Makefile.am
@@ -22,7 +22,10 @@ AM_CFLAGS += $(CFLAG_VISIBILITY)
 AM_CPPFLAGS = -I$(srcdir)/../src -I../src -I$(srcdir)/../gl -I../gl
 
 noinst_LTLIBRARIES = libgsasl-scram.la
-libgsasl_scram_la_SOURCES = scram.h mechinfo.c
+libgsasl_scram_la_SOURCES = scram.h mechinfo.c \
+       tokens.h \
+       printer.h \
+       validate.h validate.c
 
 if CLIENT
 libgsasl_scram_la_SOURCES += client.c
diff --git a/lib/scram/printer.c b/lib/scram/printer.c
new file mode 100644
index 0000000..de7357a
--- /dev/null
+++ b/lib/scram/printer.c
@@ -0,0 +1,92 @@
+/* printer.h --- Convert SCRAM token structures into strings.
+ * Copyright (C) 2009  Simon Josefsson
+ *
+ * This file is part of GNU SASL Library.
+ *
+ * GNU SASL Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * GNU SASL Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GNU SASL Library; if not, write to the Free
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/* Get prototypes. */
+#include "printer.h"
+
+/* Get free. */
+#include <stdlib.h>
+
+/* Get asprintf. */
+#include <stdio.h>
+
+/* Get token validator. */
+#include "validate.h"
+
+static char *
+scram_escape (const char *str)
+{
+  /* FIXME escape '=' and ',' in authzid to '=3D' and '=2C'
+     respectively. */
+  return strdup (str);
+}
+
+/* Print SCRAM client-first token into newly allocated output string
+   OUT.  Returns 0 on success, -1 on invalid token, and -2 on memory
+   allocation errors. */
+int
+scram_print_client_first (struct scram_client_first *cf, char **out)
+{
+  char *out = NULL;
+  char *username = NULL;
+  char *authzid = NULL;
+  int n;
+
+  /* Below we assume fields are sensible, so first verify that to
+     avoid crashes. */
+  if (!scram_valid_client_first (cf)!)
+    return -1;
+
+  /* Escape username and authzid. */
+
+  username = scram_escape (cf->username);
+  if (!username)
+    return -2;
+
+  if (cf->authzid)
+    {
+      authzid = scram_escape (cf->authzid);
+      if (!authzid)
+       return -2;
+    }
+
+  n = asprintf (&out, "%c%s%s,%s%s,n=%s,r=%s",
+               cf->cbflag,
+               cf->cbflag == 'p' ? "=" : "",
+               cf->cbflag == 'p' ? cf->cbname : "",
+               authzid ? "a=" : "",
+               authzid ? authzid : "",
+               username,
+               cf->client_nonce);
+
+  free (username);
+  free (authzid);
+
+  if (n <= 0 || out == NULL)
+    return NULL;
+
+  return out;
+}
diff --git a/lib/digest-md5/qop.h b/lib/scram/printer.h
similarity index 76%
copy from lib/digest-md5/qop.h
copy to lib/scram/printer.h
index 418f998..56aec61 100644
--- a/lib/digest-md5/qop.h
+++ b/lib/scram/printer.h
@@ -1,4 +1,4 @@
-/* qop.h --- Prototypes for DIGEST-MD5 qop handling.
+/* printer.h --- Convert SCRAM token structures into strings.
  * Copyright (C) 2009  Simon Josefsson
  *
  * This file is part of GNU SASL Library.
@@ -20,10 +20,13 @@
  *
  */
 
-#ifndef DIGEST_MD5_QOP_H
-# define DIGEST_MD5_QOP_H
+#ifndef SCRAM_PRINTER_H
+# define SCRAM_PRINTER_H
 
-extern int digest_md5_qopstr2qops (const char *qopstr);
-extern const char *digest_md5_qops2qopstr (int qops);
+/* Get token types. */
+#include "tokens.h"
 
-#endif /* DIGEST_MD5_QOP_H */
+extern int
+scram_print_client_first (struct scram_client_first *cf, char **out);
+
+#endif /* SCRAM_PRINTER_H */
diff --git a/lib/digest-md5/qop.h b/lib/scram/tokens.h
similarity index 75%
copy from lib/digest-md5/qop.h
copy to lib/scram/tokens.h
index 418f998..19e4a6d 100644
--- a/lib/digest-md5/qop.h
+++ b/lib/scram/tokens.h
@@ -1,4 +1,4 @@
-/* qop.h --- Prototypes for DIGEST-MD5 qop handling.
+/* tokens.h --- Types for SCRAM tokens.
  * Copyright (C) 2009  Simon Josefsson
  *
  * This file is part of GNU SASL Library.
@@ -20,10 +20,19 @@
  *
  */
 
-#ifndef DIGEST_MD5_QOP_H
-# define DIGEST_MD5_QOP_H
+#ifndef SCRAM_TOKENS_H
+# define SCRAM_TOKENS_H
 
-extern int digest_md5_qopstr2qops (const char *qopstr);
-extern const char *digest_md5_qops2qopstr (int qops);
+/* Get size_t. */
+#include <stddef.h>
 
-#endif /* DIGEST_MD5_QOP_H */
+struct scram_client_first
+{
+  char cbflag;
+  char *cbname;
+  char *authzid;
+  char *username;
+  char *client_nonce;
+};
+
+#endif /* SCRAM_TOKENS_H */
diff --git a/lib/scram/validate.c b/lib/scram/validate.c
new file mode 100644
index 0000000..8ffefa2
--- /dev/null
+++ b/lib/scram/validate.c
@@ -0,0 +1,68 @@
+/* validate.c --- Validate consistency of SCRAM tokens.
+ * Copyright (C) 2009  Simon Josefsson
+ *
+ * This file is part of GNU SASL Library.
+ *
+ * GNU SASL Library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * GNU SASL Library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GNU SASL Library; if not, write to the Free
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/* Get prototypes. */
+#include "validate.h"
+
+/* Get strcmp, strlen. */
+#include <string.h>
+
+bool
+scram_valid_client_first (struct scram_client_first *cf)
+{
+  /* Check that cbflag is one of permitted values. */
+  switch (cf->cbflag)
+    {
+    case 'p':
+    case 'n':
+    case 'y':
+      break;
+
+    default:
+      return false;
+    }
+
+  /* Check that cbname is only set when cbflag is p. */
+  if (cf->cbflag == 'p' && cf->cbname == NULL)
+    return false;
+  else if (cf->cbflag != 'p' && cf->cbname != NULL)
+    return false;
+
+  /* FIXME check that cbname matches [A-Za-z0-9.-]. */
+
+  /* We require a non-zero username string. */
+  if (cf->username == NULL || *cf->username == '\0')
+    return false;
+
+  /* FIXME check that client nonce is valid UTF-8 and does not contain
+     '=' or NUL. */
+
+  /* We require a non-zero client nonce. */
+  if (cf->client_nonce == NULL || *cf->client_nonce == '\0')
+    return false;
+
+  return true;
+}
diff --git a/lib/digest-md5/qop.h b/lib/scram/validate.h
similarity index 74%
copy from lib/digest-md5/qop.h
copy to lib/scram/validate.h
index 418f998..6016898 100644
--- a/lib/digest-md5/qop.h
+++ b/lib/scram/validate.h
@@ -1,4 +1,4 @@
-/* qop.h --- Prototypes for DIGEST-MD5 qop handling.
+/* validate.h --- Validate consistency of SCRAM tokens.
  * Copyright (C) 2009  Simon Josefsson
  *
  * This file is part of GNU SASL Library.
@@ -20,10 +20,15 @@
  *
  */
 
-#ifndef DIGEST_MD5_QOP_H
-# define DIGEST_MD5_QOP_H
+#ifndef SCRAM_VALIDATE_H
+# define SCRAM_VALIDATE_H
 
-extern int digest_md5_qopstr2qops (const char *qopstr);
-extern const char *digest_md5_qops2qopstr (int qops);
+/* Get token types. */
+#include "tokens.h"
 
-#endif /* DIGEST_MD5_QOP_H */
+/* Get bool. */
+#include <stdbool.h>
+
+extern bool scram_valid_client_first (struct scram_client_first *cf);
+
+#endif /* SCRAM_VALIDATE_H */


hooks/post-receive
-- 
GNU gsasl




reply via email to

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