1 \input texinfo @c -*- mode: texinfo; coding: us-ascii; -*-
2 @c This file is part of GNU SASL.
3 @c See below for copyright and license.
5 @setfilename gsasl.info
7 @settitle GNU Simple Authentication and Security Layer @value{VERSION}
10 @c Unify some of the indices.
15 This manual was last updated @value{UPDATED} for version
16 @value{VERSION} of GNU SASL.
18 Copyright @copyright{} 2002, 2003, 2004, 2005, 2006, 2007 Simon Josefsson.
21 Permission is granted to copy, distribute and/or modify this document
22 under the terms of the GNU Free Documentation License, Version 1.2 or
23 any later version published by the Free Software Foundation; with no
24 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
25 copy of the license is included in the section entitled ``GNU Free
26 Documentation License''.
30 @dircategory GNU Libraries
32 * libgsasl: (gsasl). Simple Authentication and Security Layer Library.
35 @dircategory GNU utilities
37 * gsasl: (gsasl)Invoking gsasl. Command line interface to GNU SASL.
42 @subtitle Simple Authentication and Security Layer for the GNU system
43 @subtitle for version @value{VERSION}, @value{UPDATED}
44 @author Simon Josefsson
46 @vskip 0pt plus 1filll
54 @top GNU Simple Authentication and Security Layer
59 * Introduction:: How to use this manual.
60 * Preparation:: What you should do before using the library.
61 * Using the Library:: High level overview of how to use the library.
62 * Properties:: How to specify username, password, etc.
63 * Mechanisms:: Mechanism specific information.
64 * Global Functions:: Functions that can be used at all times.
65 * Callback Functions:: Set and use callbacks.
66 * Property Functions:: Specify username, password etc.
67 * Session Functions:: Perform an authentication.
68 * Utilities:: Functions for various odd things.
69 * Memory Handling:: Memory de-allocation.
70 * Error Handling:: Error codes and such.
71 * Examples:: Demonstrate how to use the library.
72 * Acknowledgements:: Whom to blame.
74 * Invoking gsasl:: Command line interface to the library.
78 * Protocol Clarifications:: Our notes on the SASL protocol.
79 * Old Functions:: Descriptions of old API functions.
80 * Copying Information:: How you can copy and share GNU SASL.
84 * Concept Index:: Index of concepts and programs.
85 * Function and Data Index:: Index of functions, variables and data types.
88 @c **********************************************************
89 @c ******************* Introduction ***********************
90 @c **********************************************************
94 GNU SASL is an implementation of the Simple Authentication and
95 Security Layer framework and a few common SASL mechanisms.
96 @acronym{SASL} is used by network servers (e.g., @acronym{IMAP},
97 @acronym{SMTP}) to request authentication from clients, and in clients
98 to authenticate against servers.
100 GNU SASL consists of a library (`libgsasl'), a command line utility
101 (`gsasl') to access the library from the shell, and a manual. The
102 library includes support for the framework (with authentication
103 functions and application data privacy and integrity functions) and at
104 least partial support for the CRAM-MD5, EXTERNAL, GSSAPI, ANONYMOUS,
105 PLAIN, SECURID, DIGEST-MD5, LOGIN, and NTLM mechanisms.
107 The library is easily ported because it does not do network
108 communication by itself, but rather leaves it up to the calling
109 application. The library is flexible with regards to the
110 authorization infrastructure used, as it utilize a callback into the
111 application to decide whether a user is authorized or not.
113 GNU SASL is developed for the GNU/Linux system, but runs on over 20
114 platforms including most major Unix platforms and Windows, and many
115 kind of devices including iPAQ handhelds and S/390 mainframes.
117 GNU SASL is written in pure ANSI C89 to be portable to embedded and
118 otherwise limited platforms. The entire library, with full support
119 for ANONYMOUS, EXTERNAL, PLAIN, LOGIN and CRAM-MD5, and the front-end
120 that support client and server mode, and the IMAP and SMTP protocols,
121 fits in under 60kb on an Intel x86 platform, without any modifications
122 to the code. (This figure was accurate as of version 0.0.13.)
124 The library is licensed under the GNU Lesser General Public License
125 version 2.1. The command-line application (src/), examples
126 (examples/), self-test suite (tests/) are licensed under the GNU
127 General Public License license version 3.0. The documentation (doc/)
128 is licensed under the GNU Free Documentation License version 1.2.
130 @float Illustration,fig:abstraction
131 @image{abstraction,10cm,5cm}
133 @caption{Logical overview showing how applications use authentication
134 mechanisms through an abstract interface.}
143 * Supported Platforms::
145 * Commercial Support::
146 * Downloading and Installing::
151 @node Getting Started
152 @section Getting Started
154 This manual documents the GNU SASL Library programming interface. All
155 functions and data types provided by the library are explained.
157 The reader is assumed to possess basic familiarity with SASL and
158 network programming in C or C++.
160 This manual can be used in several ways. If read from the beginning
161 to the end, it gives a good introduction into the library and how it
162 can be used in an application. Forward references are included where
163 necessary. Later on, the manual can be used as a reference manual to
164 get just the information needed about any particular interface of the
165 library. Experienced programmers might want to start looking at the
166 examples at the end of the manual, and then only read up those parts
167 of the interface which are unclear.
172 GNU SASL might have a couple of advantages over other libraries doing
176 @item It's Free Software
177 Anybody can use, modify, and redistribute it under the terms of the
178 GNU General Public License version 3.0. The library can also be
179 distributed under the GNU Lesser General Public License version 2.1.
181 @item It's thread-safe
182 No global variables are used and multiple library handles and session
183 handles may be used in parallel.
185 @item It's internationalized
186 It handles non-ASCII username and passwords and user visible strings
187 used in the library (error messages) can be translated into the users'
191 It should work on all Unix like operating systems, including Windows.
192 The library itself should be portable to any C89 system, not even
197 Note that the library do not implement any policy to decide whether a
198 certain user is ``authenticated'' or ``authorized'' or not. Rather,
199 it uses a callback into the application to answer these questions.
202 @section SASL Overview
204 This section describes SASL from a protocol point of view.
206 The Simple Authentication and Security Layer (SASL) is a method for
207 adding authentication support to connection-based protocols. A
208 protocol includes a command for identifying and authenticating a user
209 to a server and for optionally negotiating a security layer for
210 subsequent protocol interactions.
212 The command has a required argument identifying a SASL mechanism.
213 SASL mechanisms are named by strings, from 1 to 20 characters in
214 length, consisting of upper-case letters, digits, hyphens, and/or
217 If a server supports the requested mechanism, it initiates an
218 authentication protocol exchange. This consists of a series of
219 server challenges and client responses that are specific to the
220 requested mechanism. The challenges and responses are defined by the
221 mechanisms as binary tokens of arbitrary length. The protocol's
222 profile then specifies how these binary tokens are then encoded for
223 transfer over the connection.
225 After receiving the authentication command or any client response, a
226 server may issue a challenge, indicate failure, or indicate
227 completion. The protocol's profile specifies how the server
228 indicates which of the above it is doing.
230 After receiving a challenge, a client may issue a response or abort
231 the exchange. The protocol's profile specifies how the client
232 indicates which of the above it is doing.
234 During the authentication protocol exchange, the mechanism performs
235 authentication, transmits an authorization identity (frequently known
236 as a userid) from the client to server, and negotiates the use of a
237 mechanism-specific security layer. If the use of a security layer is
238 agreed upon, then the mechanism must also define or negotiate the
239 maximum cipher-text buffer size that each side is able to receive.
241 The transmitted authorization identity may be different than the
242 identity in the client's authentication credentials. This permits
243 agents such as proxy servers to authenticate using their own
244 credentials, yet request the access privileges of the identity for
245 which they are proxying. With any mechanism, transmitting an
246 authorization identity of the empty string directs the server to
247 derive an authorization identity from the client's authentication
250 If use of a security layer is negotiated, it is applied to all
251 subsequent data sent over the connection. The security layer takes
252 effect immediately following the last response of the authentication
253 exchange for data sent by the client and the completion indication
254 for data sent by the server. Once the security layer is in effect,
255 the protocol stream is processed by the security layer into buffers
256 of cipher-text. Each buffer is transferred over the connection as a
257 stream of octets prepended with a four octet field in network byte
258 order that represents the length of the following buffer. The length
259 of the cipher-text buffer must be no larger than the maximum size
260 that was defined or negotiated by the other side.
263 @section Requirements
265 The GNU SASL library does not have any required external dependencies,
266 but some optional features are enabled if you have a specific external
271 The NTLM mechanism requires the library LibNTLM,
272 @url{http://josefsson.org/libntlm/}.
275 The GSS-API mechanism requires a GSS-API library, such as GNU GSS
276 (@url{http://josefsson.org/gss/}), MIT Kerberos or Heimdal.
279 Processing of non-ASCII username and passwords requires the SASLprep
280 implementation in GNU LibIDN (@url{http://josefsson.org/libidn/}).
281 This is needed for full conformance with the latest SASL protocol
282 drafts, but is optional in the library for improved portability.
285 The GNU SASL library ships with its own cryptographic implementation,
286 but it can use the one in libgcrypt (@url{http://www.gnupg.org/})
287 instead, if it is available. This is typically useful for desktop
288 machines which have libgcrypt installed.
291 The command-line interface to GNU SASL requires a POSIX or Windows
292 platform for network connectivity. The command-line tool can make use
293 of GnuTLS (@url{http://josefsson.org/gnutls/}) to support the STARTTLS
294 modes of IMAP and SMTP, but GnuTLS is not required.
296 Note that the library does not need a POSIX platform or network
299 @node Supported Platforms
300 @section Supported Platforms
302 GNU SASL has at some point in time been tested on the following
307 @item Debian GNU/Linux 3.0 (Woody)
310 GCC 2.95.4 and GNU Make. This is the main development platform.
311 @code{alphaev67-unknown-linux-gnu}, @code{alphaev6-unknown-linux-gnu},
312 @code{arm-unknown-linux-gnu}, @code{hppa-unknown-linux-gnu},
313 @code{hppa64-unknown-linux-gnu}, @code{i686-pc-linux-gnu},
314 @code{ia64-unknown-linux-gnu}, @code{m68k-unknown-linux-gnu},
315 @code{mips-unknown-linux-gnu}, @code{mipsel-unknown-linux-gnu},
316 @code{powerpc-unknown-linux-gnu}, @code{s390-ibm-linux-gnu},
317 @code{sparc-unknown-linux-gnu}.
319 @item Debian GNU/Linux 2.1
322 GCC 2.95.1 and GNU Make. @code{armv4l-unknown-linux-gnu}.
327 Tru64 UNIX C compiler and Tru64 Make. @code{alphaev67-dec-osf5.1},
328 @code{alphaev68-dec-osf5.1}.
333 GCC 2.96 and GNU Make. @code{alphaev6-unknown-linux-gnu},
334 @code{alphaev67-unknown-linux-gnu}.
336 @item SuSE Linux 7.2a
339 GCC 3.0 and GNU Make. @code{ia64-unknown-linux-gnu}.
341 @item RedHat Linux 7.2
344 GCC 2.96 and GNU Make. @code{alphaev6-unknown-linux-gnu},
345 @code{alphaev67-unknown-linux-gnu}, @code{ia64-unknown-linux-gnu}.
347 @item RedHat Linux 8.0
350 GCC 3.2 and GNU Make. @code{i686-pc-linux-gnu}.
352 @item RedHat Advanced Server 2.1
353 @cindex RedHat Advanced Server
355 GCC 2.96 and GNU Make. @code{i686-pc-linux-gnu}.
357 @item Slackware Linux 8.0.01
360 GCC 2.95.3 and GNU Make. @code{i686-pc-linux-gnu}.
362 @item Mandrake Linux 9.0
365 GCC 3.2 and GNU Make. @code{i686-pc-linux-gnu}.
370 MIPS C compiler, IRIX Make. @code{mips-sgi-irix6.5}.
375 IBM C for AIX compiler, AIX Make. @code{rs6000-ibm-aix4.3.2.0}.
377 @item Microsoft Windows 2000 (Cygwin)
380 GCC 3.2, GNU make. @code{i686-pc-cygwin}.
385 HP-UX C compiler and HP Make. @code{ia64-hp-hpux11.22},
386 @code{hppa2.0w-hp-hpux11.11}.
388 @item SUN Solaris 2.8
391 Sun WorkShop Compiler C 6.0 and SUN Make. @code{sparc-sun-solaris2.8}.
393 @item SUN Solaris 2.9
396 Sun Forte Developer 7 C compiler and GNU
397 Make. @code{sparc-sun-solaris2.9}.
402 GCC 2.95.3 and GNU Make. @code{alpha-unknown-netbsd1.6},
403 @code{i386-unknown-netbsdelf1.6}.
405 @item OpenBSD 3.1 and 3.2
408 GCC 2.95.3 and GNU Make. @code{alpha-unknown-openbsd3.1},
409 @code{i386-unknown-openbsd3.1}.
414 GCC 2.95.4 and GNU Make. @code{alpha-unknown-freebsd4.7},
415 @code{i386-unknown-freebsd4.7}.
417 @item Cross compiled to uClinux/uClibc on Motorola Coldfire.
418 @cindex Motorola Coldfire
422 GCC 3.4 and GNU Make @code{m68k-uclinux-elf}.
426 If you port GNU SASL to a new platform, please report it to the author
427 so this list can be updated.
430 @section Getting help
432 A mailing list where users may help each other exists, and you can
433 reach it by sending e-mail to @email{help-gsasl@@gnu.org}. Archives
434 of the mailing list discussions, and an interface to manage
435 subscriptions, is available through the World Wide Web at
436 @url{http://lists.gnu.org/mailman/listinfo/help-gsasl}.
438 @node Commercial Support
439 @section Commercial Support
441 Commercial support is available for users of GNU SASL. The kind of
442 support that can be purchased may include:
446 @item Implement new features.
447 Such as a new SASL mechanism.
449 @item Port GNU SASL to new platforms.
450 This could include porting to an embedded platforms that may need
451 memory or size optimization.
453 @item Integrating SASL as a security environment in your existing project.
455 @item System design of components related to SASL.
459 If you are interested, please write to:
462 Simon Josefsson Datakonsult
467 E-mail: simon@josefsson.org
470 If your company provide support related to GNU SASL and would like to
471 be mentioned here, contact the author (@pxref{Bug Reports}).
473 @node Downloading and Installing
474 @section Downloading and Installing
478 The package can be downloaded from several places, including:
480 @url{http://josefsson.org/gsasl/releases/}
482 The latest version is stored in a file, e.g.,
483 @samp{gsasl-@value{VERSION}.tar.gz} where the @samp{@value{VERSION}}
484 value is the highest version number in the directory.
486 The package is then extracted, configured and built like many other
487 packages that use Autoconf. For detailed information on configuring
488 and building it, refer to the @file{INSTALL} file that is part of the
489 distribution archive.
491 Here is an example terminal session that download, configure, build
492 and install the package. You will need a few basic tools, such as
493 @samp{sh}, @samp{make} and @samp{cc}.
496 $ wget -q http://josefsson.org/gsasl/releases/gsasl-@value{VERSION}.tar.gz
497 $ tar xfz gsasl-@value{VERSION}.tar.gz
498 $ cd gsasl-@value{VERSION}/
507 After that gsasl should be properly installed and ready for use.
509 A few @code{configure} options may be relevant, summarized in the
514 @item --disable-client
515 @itemx --disable-server
516 If your target system require a minimal implementation, you may wish
517 to disable the client or the server part of the code. This do not
518 remove symbols from the library, so if you attempt to call an
519 application that uses server functions in a library built with
520 @code{--disable-server}, the function will return an error code.
522 @item --disable-obsolete
523 This remove backwards compatibility (@pxref{Old Functions}). Use if
524 you want to limit the size of the library.
526 @item --disable-anonymous
527 @itemx --disable-external
528 @itemx --disable-plain
529 @itemx --disable-login
530 @itemx --disable-securid
531 @itemx --disable-ntlm
532 @itemx --disable-cram-md5
533 @itemx --disable-digest-md5
534 @itemx --disable-gssapi
535 @itemx --enable-kerberos_v5
536 Disable or enable individual mechanisms (@pxref{Mechanisms}).
538 @item --without-stringprep
539 Disable internationalized string processing. Note that this will
540 result in a SASL library that is only compatible with RFC 2222.
544 For the complete list, refer to the output from @code{configure
549 @cindex Reporting Bugs
551 If you think you have found a bug in GNU SASL, please investigate it
556 @item Please make sure that the bug is really in GNU SASL, and
557 preferably also check that it hasn't already been fixed in the latest
560 @item You have to send us a test case that makes it possible for us to
563 @item You also have to explain what is wrong; if you get a crash, or
564 if the results printed are not good and in that case, in what way.
565 Make sure that the bug report includes all information you would need
566 to fix this kind of bug for someone else.
570 Please make an effort to produce a self-contained report, with
571 something definite that can be tested or debugged. Vague queries or
572 piecemeal messages are difficult to act on and don't help the
575 If your bug report is good, we will do our best to help you to get a
576 corrected version of the software; if the bug report is poor, we won't
577 do anything about it (apart from asking you to send better bug
580 If you think something in this manual is unclear, or downright
581 incorrect, or if the language needs to be improved, please also send a
584 Send your bug report to:
586 @center @samp{bug-gsasl@@gnu.org}
589 @section Contributing
593 If you want to submit a patch for inclusion -- from solve a typo you
594 discovered, up to adding support for a new feature -- you should
595 submit it as a bug report (@pxref{Bug Reports}). There are some
596 things that you can do to increase the chances for it to be included
597 in the official package.
599 Unless your patch is very small (say, under 10 lines) we require that
600 you assign the copyright of your work to the Free Software Foundation.
601 This is to protect the freedom of the project. If you have not
602 already signed papers, we will send you the necessary information when
603 you submit your contribution.
605 For contributions that doesn't consist of actual programming code, the
606 only guidelines are common sense. Use it.
608 For code contributions, a number of style guides will help you:
613 Follow the GNU Standards document (@pxref{top, GNU Coding Standards,,
616 If you normally code using another coding standard, there is no
617 problem, but you should use @samp{indent} to reformat the code
618 (@pxref{top, GNU Indent,, indent}) before submitting your work.
620 @item Use the unified diff format @samp{diff -u}.
623 No reason whatsoever should abort the execution of the library. Even
624 memory allocation errors, e.g. when malloc return NULL, should work
625 although result in an error code.
627 @item Design with thread safety in mind.
628 Don't use global variables. Don't even write to per-handle global
629 variables unless the documented behaviour of the function you write is
630 to write to the per-handle global variable.
632 @item Avoid using the C math library.
633 It causes problems for embedded implementations, and in most
634 situations it is very easy to avoid using it.
636 @item Document your functions.
637 Use comments before each function headers, that, if properly
638 formatted, are extracted into Texinfo manuals and GTK-DOC web pages.
640 @item Supply a ChangeLog and NEWS entries, where appropriate.
644 @c **********************************************************
645 @c ******************* Preparation ************************
646 @c **********************************************************
650 To use GNU SASL, you have to perform some changes to your sources and
651 the build system. The necessary changes are small and explained in
652 the following sections. At the end of this chapter, it is described
653 how the library is initialized, and how the requirements of the
654 library are verified.
656 A faster way to find out how to adapt your application for use with
657 GNU SASL may be to look at the examples at the end of this manual
664 * Building the source::
671 All interfaces (data types and functions) of the library are defined
672 in the header file `gsasl.h'. You must include this in all programs
673 using the library, either directly or through some other header file,
680 The name space is @code{gsasl_*} for function names, @code{Gsasl*} for
681 data types and @code{GSASL_*} for other symbols. In addition the same
682 name prefixes with one prepended underscore are reserved for internal
683 use and should never be used by an application.
686 @section Initialization
688 The library must be initialized before it can be used. The library is
689 initialized by calling @code{gsasl_init} (@pxref{Global Functions}).
690 The resources allocated by the initialization process can be released
691 if the application no longer has a need to call `Libgsasl' functions,
692 this is done by calling @code{gsasl_done}. For example:
696 main (int argc, char *argv[])
701 rc = gsasl_init (&ctx);
704 printf ("SASL initialization failure (%d): %s\n",
705 rc, gsasl_strerror (rc));
711 In order to make error messages from @code{gsasl_strerror} be
712 translated (@pxref{Top,,,gettext,GNU Gettext}) the application must
713 set the current locale using @code{setlocale} before calling
714 @code{gsasl_init}. For example:
718 main (int argc, char *argv[])
723 setlocale (LC_ALL, "");
725 rc = gsasl_init (&ctx);
728 printf (gettext ("SASL initialization failure (%d): %s\n"),
729 rc, gsasl_strerror (rc));
735 In order to take advantage of the secure memory features in
736 Libgcrypt@footnote{Note that GNU SASL normally use its own internal
737 implementation of the cryptographic functions. Take care to verify
738 that GNU SASL really use Libgcrypt, if this is what you want.}, you
739 need to initialize secure memory in your application, and for some
740 platforms even make your application setuid root. See the Libgcrypt
741 documentation for more information. Example code to initialize secure
748 main (int argc, char *argv[])
753 /* Check version of libgcrypt. */
754 if (!gcry_check_version (GCRYPT_VERSION))
755 die ("version mismatch\n");
757 /* Allocate a pool of 16k secure memory. This also drops priviliges
759 gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);
761 /* Tell Libgcrypt that initialization has completed. */
762 gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
764 rc = gsasl_init (&ctx);
767 printf ("SASL initialization failure (%d): %s\n",
768 rc, gsasl_strerror (rc));
774 If you do not do this, keying material will not be allocated in secure
775 memory (which for most application is not the biggest secure problem
776 anyway). Note that the GNU SASL Library has not been audited to make
777 sure it only ever stores passwords or keys in secure memory.
780 @section Version Check
782 It is often desirable to check that the version of the library used is
783 indeed one which fits all requirements. Even with binary
784 compatibility new features may have been introduced but due to problem
785 with the dynamic linker an old version is actually used. So you may
786 want to check that the version is okay right after program startup.
788 @include texi/gsasl_check_version.texi
790 The normal way to use the function is to put something similar to the
791 following early in your @code{main}:
794 if (!gsasl_check_version (GSASL_VERSION))
796 printf ("gsasl_check_version failed:\n"
797 "Header file incompatible with shared library.\n");
802 @node Building the source
803 @section Building the source
804 @cindex Compiling your application
806 If you want to compile a source file including the `gsasl.h' header
807 file, you must make sure that the compiler can find it in the
808 directory hierarchy. This is accomplished by adding the path to the
809 directory in which the header file is located to the compilers include
810 file search path (via the @option{-I} option).
812 However, the path to the include file is determined at the time the
813 source is configured. To solve this problem, the library uses the
814 external package @command{pkg-config} that knows the path to the
815 include file and other configuration options. The options that need
816 to be added to the compiler invocation at compile time are output by
817 the @option{--cflags} option to @command{pkg-config libgsasl}. The
818 following example shows how it can be used at the command line:
821 gcc -c foo.c `pkg-config libgsasl --cflags`
824 Adding the output of @samp{pkg-config libgsasl --cflags} to the
825 compilers command line will ensure that the compiler can find the
826 `gsasl.h' header file.
828 A similar problem occurs when linking the program with the library.
829 Again, the compiler has to find the library files. For this to work,
830 the path to the library files has to be added to the library search path
831 (via the @option{-L} option). For this, the option @option{--libs} to
832 @command{pkg-config libgsasl} can be used. For convenience, this option
833 also outputs all other options that are required to link the program
834 with the `libgsasl' libarary (for instance, the @samp{-lidn}
835 option). The example shows how to link @file{foo.o} with the `libgsasl'
836 library to a program @command{foo}.
839 gcc -o foo foo.o `pkg-config libgsasl --libs`
842 Of course you can also combine both examples to a single command by
843 specifying both options to @command{pkg-config}:
846 gcc -o foo foo.c `pkg-config libgsasl --cflags --libs`
850 @section Autoconf tests
851 @cindex Autoconf tests
852 @cindex Configure tests
854 If you work on a project that uses Autoconf (@pxref{top, GNU
855 Autoconf,, autoconf}) to help find installed libraries, the
856 suggestions in the previous section are not the entire story. There
857 are a few methods to detect and incorporate the GNU SASL Library into
858 your Autoconf based package. The preferred approach, is to use
859 Libtool in your project, and use the normal Autoconf header file and
862 @subsection Autoconf test via @samp{pkg-config}
864 If your audience is a typical GNU/Linux desktop, you can often assume
865 they have the @samp{pkg-config} tool installed, in which you can use
866 its Autoconf M4 macro to find and set up your package for use with
867 Libgsasl. The following illustrate this scenario.
871 AC_HELP_STRING([--disable-gsasl], [don't use GNU SASL]),
873 if test "$gsal" != "no" ; then
874 PKG_CHECK_MODULES(GSASL, libgsasl >= @value{VERSION},
877 if test "$gsasl" != "yes" ; then
879 AC_MSG_WARN([Cannot find GNU SASL, disabling])
882 AC_DEFINE(USE_GSASL, 1, [Define to 1 if you want GNU SASL.])
885 AC_MSG_CHECKING([if GNU SASL should be used])
886 AC_MSG_RESULT($gsasl)
889 @subsection Standalone Autoconf test using Libtool
891 If your package uses Libtool(@pxref{top, GNU Libtool,, libtool}), you
892 can use the normal Autoconf tests to find Libgsasl and rely on the
893 Libtool dependency tracking to include the proper dependency libraries
894 (e.g., Libidn). The following illustrate this scenario.
897 AC_CHECK_HEADER(gsasl.h,
898 AC_CHECK_LIB(gsasl, gsasl_check_version,
899 [gsasl=yes AC_SUBST(GSASL_LIBS, -lgsasl)],
903 AC_HELP_STRING([--disable-gsasl], [don't use GNU SASL]),
905 if test "$gsasl" != "no" ; then
906 AC_DEFINE(USE_SASL, 1, [Define to 1 if you want GNU SASL.])
908 AC_MSG_WARN([Cannot find GNU SASL, diabling])
910 AC_MSG_CHECKING([if GNU SASL should be used])
911 AC_MSG_RESULT($gsasl)
914 @c **********************************************************
915 @c ***************** Using the Library ********************
916 @c **********************************************************
917 @node Using the Library
918 @chapter Using the Library
920 Your application's use of the library can be roughly modeled into the
921 following steps: initialize the library, optionally specify the
922 callback, perform the authentication, and finally clean up. The
923 following image illustrate this.
925 @image{controlflow,15cm,5cm}
927 The third step may look the most complex, but for a simple client it
928 will actually not involve any code. If your application need to
929 handle several concurrent clients, or if it is a server that need to
930 serve many clients simultaneous, things do get a bit more complicated.
932 For illustration, we will write a simple client. Writing a server
933 would be similar, the only difference is that, later on, instead of
934 supplying username or passwords, you need to decide whether someone
935 should be allowed to log in or not. The code for what we have
936 discussed so far make up our @code{main} function in our client
940 int main (int argc, char *argv[])
945 if ((rc = gsasl_init (&ctx)) != GSASL_OK)
947 printf ("Cannot initialize libgsasl (%d): %s",
948 rc, gsasl_strerror (rc));
960 Here, the call to the function @code{client} correspond to the third
961 step in the image above.
963 For a more complicated application, that have several clients running
964 simultaneous, instead of simply calling @code{client}, it may have
965 created new threads for each session, and call @code{client} within
966 each thread. The library is thread safe.
968 An actual authentication session is more complicated than what we have
969 seen so far. The steps that make up it are: decide which mechanism to
970 use, start the session, optionally specify the callback, optionally
971 set any properties, perform the authentication loop, and clean up.
972 Naturally, your application will start to talk its own protocol (e.g.,
973 SMTP or IMAP) after these steps have concluded.
975 The authentication loop is based on sending tokens (typically short
976 messages encoded in base 64) back and forth between the client and
977 server. It continue until authentication succeeds or there is an
978 error. The format of the data to transfer, the number of iterations
979 in the loop, and other details are specified by each mechanism. The
980 goal of the library is to isolate your application from the details of
981 all different mechanisms.
983 Note that the library do not send data to the server itself, but
984 return it in an buffer. You must send it to the server yourself,
985 according to an application protocol profile. For example, the
986 @acronym{SASL} application protocol profile for @acronym{SMTP} is
987 described in @acronym{RFC} 2554.
989 The following image illustrate the steps we have been talking about.
991 @image{controlflow2,16cm,12cm}
993 We will now show the implementation of the @code{client} function used
997 void client (Gsasl *ctx)
999 Gsasl_session *session;
1000 const char *mech = "PLAIN";
1003 /* Create new authentication session. */
1004 if ((rc = gsasl_client_start (ctx, mech, &session)) != GSASL_OK)
1006 printf ("Cannot initialize client (%d): %s\n",
1007 rc, gsasl_strerror (rc));
1011 /* Set username and password in session handle. This info will be
1012 lost when this session is deallocated below. */
1013 gsasl_property_set (session, GSASL_AUTHID, "jas");
1014 gsasl_property_set (session, GSASL_PASSWORD, "secret");
1017 client_authenticate (ctx, session);
1020 gsasl_finish (session);
1024 This function is responsible for deciding which mechanism to use. In
1025 this case, the @samp{PLAIN} mechanism is hard coded, but you will see
1026 later how this can be made more flexible. The function create a new
1027 session, store the username and password in the session handle, then
1028 call another function @code{client_authenticate} to handle the
1029 authentication loop, and end by cleaning up. Let's continue with the
1030 implementation of @code{client_authenticate}.
1033 void client_authenticate (Gsasl * ctx, Gsasl_session * session)
1035 char buf[BUFSIZ] = "";
1039 /* This loop mimic a protocol where the server get to send data
1044 printf ("Input base64 encoded data from server:\n");
1045 fgets (buf, sizeof (buf) - 1, stdin);
1046 if (buf[strlen (buf) - 1] == '\n')
1047 buf[strlen (buf) - 1] = '\0';
1049 rc = gsasl_step64 (session, buf, &p);
1051 if (rc == GSASL_NEEDS_MORE || rc == GSASL_OK)
1053 printf ("Output:\n%s\n", p);
1057 while (rc == GSASL_NEEDS_MORE);
1063 printf ("Authentication error (%d): %s\n",
1064 rc, gsasl_strerror (rc));
1068 /* The client is done. Here you would typically check if the
1069 server let the client in. If not, you could try again. */
1071 printf ("If server accepted us, we're done.\n");
1075 This last function need to be discussed in some detail. First, you
1076 should be aware that there are two versions of this function, that
1077 differ in a subtle way. The version above (@pxref{Example 2}) is used
1078 for application profiles where the server send data first. For some
1079 mechanisms, this may waste a roundtrip, because the server need input
1080 from the client to proceed. Therefor, today the recommended approach
1081 is to permit client to send data first (@pxref{Example 1}). Which
1082 version you should use depend on which application protocol you are
1085 Further, you should realize that it is bad programming style to use a
1086 fixed size buffer. On GNU systems, you may use the @code{getline}
1087 functions instead of @code{fgets}. However, in practice, there are
1088 few mechanisms that use very large tokens. In typical configurations,
1089 the mechanism with the largest tokens (GSSAPI) can use at least 500
1090 bytes. A fixed buffer size of 8192 bytes may thus be sufficient for
1091 now. But don't say I didn't warn you, when a future mechanism doesn't
1092 work in your application, because of a fixed size buffer.
1094 The @code{gsasl_step64} (and of course also @code{gasl_step}) return
1095 two non-error return codes. @code{GSASL_OK} is used for success,
1096 indicating that the library consider the authentication finished.
1097 That may include a successful server authentication, depending on the
1098 mechanism. You must not let the client continue to the application
1099 protocol part unless you receive @code{GSASL_OK} from these functions.
1100 In particular, don't be fooled into believing authentication were
1101 successful if the server reply ``OK'' but these function has failed
1102 with an error. The server may have been hacked, and could be tricking
1103 you into sending confidential data, without having successfully
1104 authenticated the server.
1106 The non-error return code @code{GSASL_NEEDS_MORE} is used to signal to
1107 your application that you should send the output token to the peer,
1108 and wait for a new token, and do another iteration. If the server
1109 conclude the authentication process, with no data, you should call
1110 @code{gsasl_step64} (or @code{gsasl_step}) specifying a zero-length
1113 If the functions (@code{gsasl_step} and @code{gsasl_step64}) return
1114 any non-error code, the content of the output buffer is undefined.
1115 Otherwise, it is the callers responsibility to deallocate the buffer,
1116 by calling @code{free}. Note that in some situations, where the
1117 buffer is empty, @code{NULL} is returned as the buffer value. You
1118 should treat this as an empty buffer.
1120 @section Choosing a mechanism
1122 Our earlier code was hard coded to use a specific mechanism. This is
1123 rarely a good idea. Instead, it is recommended to select the best
1124 mechanism available from the list of mechanism supported by the
1125 server. Note that without TLS or similar, the list may have been
1126 maliciously altered, by an attacker. This means that you should abort
1127 if you cannot find any mechanism that exceeds your minimum security
1128 level. There is a function @code{gsasl_client_suggest_mechanism}
1129 (@pxref{Global Functions}) that will try to pick the ``best''
1130 available mechanism from a list of mechanisms. Our simple interactive
1131 example client (@pxref{Example 3}) include the following function to
1132 decide which mechanism to use. Note that the code doesn't blindly use
1133 what is returned from @code{gsasl_client_suggest_mechanism}, but
1134 rather let some logic (in this case the user, through an interactive
1135 query) decide which mechanism is acceptable.
1138 const char *client_mechanism (Gsasl *ctx)
1140 static char mech[GSASL_MAX_MECHANISM_SIZE + 1] = "";
1141 char mechlist[BUFSIZ] = "";
1142 const char *suggestion;
1144 printf ("Enter list of mechanism that server support, separate by SPC:\n");
1145 fgets (mechlist, sizeof (mechlist) - 1, stdin);
1147 suggestion = gsasl_client_suggest_mechanism (ctx, mechlist);
1149 printf ("Library suggest use of `%s'.\n", suggestion);
1151 printf ("Enter mechanism to use:\n");
1152 fgets (mech, sizeof (mech) - 1, stdin);
1153 mech[strlen (mech) - 1] = '\0';
1159 When running this example code, it might look like in the following
1163 Enter list of mechanism that server support, separate by SPC:
1164 CRAM-MD5 DIGEST-MD5 GSSAPI FOO BAR
1165 Library suggest use of `GSSAPI'.
1166 Enter mechanism to use:
1168 Input base64 encoded data from server:
1171 amFzIDkyY2U1NWE5MTM2ZTY4NzEyMTUyZTFjYmFmNjVkZjgx
1173 If server accepted us, we're done.
1176 @section Using a callback
1178 Our earlier code specified the username and password before the
1179 authentication loop, as in:
1182 gsasl_property_set (ctx, GSASL_AUTHID, "jas");
1183 gsasl_property_set (ctx, GSASL_PASSWORD, "secret");
1186 This may work for simple mechanisms, that only ever need an username
1187 and a password. But some mechanism require more information, such as
1188 an authorization identity, a special PIN or passcode, a realm, a
1189 hostname, a service name, or an anonymous identifier. Querying the
1190 user for all that information, without knowing exactly which of it is
1191 really needed will result in a poor user interface. The user should
1192 not have to input private information, if it isn't required.
1194 The approach is a bad idea for another reason. What if the server
1195 abort the authentication process? Then your application have already
1196 queried the user for a username and password. It would be better if
1197 you only asked the user for this information, annoying to input, when
1198 it is known to be needed.
1200 A better approach to this problem is to use a callback. Then the
1201 mechanism may query your application whenever it need some
1202 information, like the username and password. It will only do this at
1203 the precise step in the authentication when the information is
1204 actually needed. Further, if the user abort, e.g., a password prompt,
1205 the mechanism is directly informed of this (because it invoked the
1206 callback), and could recover somehow.
1208 Our final example (@pxref{Example 4}) specify a callback function,
1209 inside @code{main} as below.
1212 /* Set the callback handler for the library. */
1213 gsasl_callback_set (ctx, callback);
1216 The function itself is implemented as follows.
1219 int callback (Gsasl * ctx, Gsasl_session * sctx, Gsasl_property prop)
1221 char buf[BUFSIZ] = "";
1222 int rc = GSASL_NO_CALLBACK;
1224 /* Get user info from user. */
1226 printf ("Callback invoked, for property %d.\n", prop);
1230 case GSASL_PASSCODE:
1231 printf ("Enter passcode:\n");
1232 fgets (buf, sizeof (buf) - 1, stdin);
1233 buf[strlen (buf) - 1] = '\0';
1235 gsasl_property_set (sctx, GSASL_PASSCODE, buf);
1240 printf ("Enter username:\n");
1241 fgets (buf, sizeof (buf) - 1, stdin);
1242 buf[strlen (buf) - 1] = '\0';
1244 gsasl_property_set (sctx, GSASL_AUTHID, buf);
1249 printf ("Unknown property! Don't worry.\n");
1257 Again, it is bad style to use a fixed size buffer. Mmm'kay.
1259 Which properties you should handle is up to you. If you don't know
1260 how to respond to a certain property, simply return
1261 @code{GSASL_NO_CALLBACK}. The basic properties to support are
1262 authentication identity (@code{GSASL_AUTHID}), authorization identity
1263 (@code{GSASL_AUTHZID}), and password (@code{GSASL_PASSWORD}). See
1264 @xref{Properties}, for the list of all properties, and what your
1265 callback should (ideally) do for them, and which properties each
1266 mechanism require in order to work.
1268 @c **********************************************************
1269 @c ******************* Properties *************************
1270 @c **********************************************************
1274 @c FIXME: Write introductions to properties. Discuss differences
1275 @c between client and server properties. Discuss validating
1278 Properties with associated data:
1282 @item @code{GSASL_AUTHID}
1284 The authentication identity.
1286 @item @code{GSASL_AUTHZID}
1288 The authorization identity.
1290 @item @code{GSASL_PASSWORD}
1292 The password of the authentication identity.
1294 @item @code{GSASL_ANONYMOUS_TOKEN}
1296 The anonymous token. This is typically the email address of the user.
1298 @item @code{GSASL_SERVICE}
1300 The registered GSSAPI service name of the application service,
1301 e.g. ``imap''. While the names are registered for GSSAPI, other
1302 mechanisms such as DIGEST-MD5 may also use this.
1304 @item @code{GSASL_HOSTNAME}
1306 Should be the local host name of the machine.
1308 @item @code{GSASL_GSSAPI_DISPLAY_NAME}
1310 Contain the GSSAPI ``display name'', set by the server GSSAPI
1311 mechanism. Typically you retrieve this property in your callback,
1312 when invoked for @code{GSASL_VALIDATE_GSSAPI}.
1314 @item @code{GSASL_REALM}
1316 The name of the authentication domain. This is used by several
1317 mechanisms, including DIGEST-MD5, GSS-API, KERBEROS_V5 and NTLM.
1319 @item @code{GSASL_PASSCODE}
1321 The SecurID passcode.
1323 @item @code{GSASL_PIN}
1325 The SecurID personal identification number (PIN).
1327 @item @code{GSASL_SUGGESTED_PIN}
1329 A SecurID personal identification number (PIN) suggested by the server.
1333 Abstract properties, used to trigger the callback, typically used in
1334 servers to validate client credentials:
1338 @item @code{GSASL_VALIDATE_SIMPLE}
1340 You may retrieve GSASL_AUTHID, GSASL_AUTHZID and GSASL_PASSWORD and
1341 use them to make an authentication and authorization decision.
1343 @item @code{GSASL_VALIDATE_EXTERNAL}
1345 Used by EXTERNAL mechanism on the server side to validate the client.
1346 The GSASL_AUTHID will contain the authorization identity of the
1349 @item @code{GSASL_VALIDATE_ANONYMOUS}
1351 Used by ANONYMOUS mechanism on the server side to validate the client.
1352 The GSASL_ANONYMOUS_TOKEN will contain token that identity the client.
1354 @item @code{GSASL_VALIDATE_GSSAPI}
1356 Used by the GSSAPI mechanism on the server side, to validate the
1357 client. You may retrieve the authorization identity from
1358 GSASL_AUTHZID and the GSS-API display name from
1359 GSASL_GSSAPI_DISPLAY_NAME.
1361 @item @code{GSASL_VALIDATE_SECURID}
1363 Used by SECURID mechanism on the server side to validate client. The
1364 GSASL_AUTHID, GSASL_AUTHZID, GSASL_PASSCODE, and GSASL_PIN will be
1365 set. It can return GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE to
1366 ask the client to supply another passcode, and
1367 GSASL_SECURID_SERVER_NEED_NEW_PIN to require the client to supply a
1373 @c **********************************************************
1374 @c ******************* Mechanisms *************************
1375 @c **********************************************************
1379 Different SASL mechanisms have different requirements on the
1380 application using it. To handle these differences the library can use
1381 a callback function into your application in several different ways.
1382 Some mechanisms, such as @samp{PLAIN}, are simple to explain and use.
1383 The client callback query the user for a username and password. The
1384 server callback hand the username and password into any local policy
1385 deciding authentication system (such as @file{/etc/passwd} via PAM).
1387 Mechanism such as @samp{CRAM-MD5} and @samp{DIGEST-MD5} uses hashed
1388 passwords. The client callback behaviour is the same as for PLAIN.
1389 However, the server do not receive the plain text password over the
1390 network but rather a hash of it. Existing policy deciding systems
1391 like PAM cannot handle this, so the server callback for these
1392 mechanisms are more complicated.
1394 Further, mechanisms like GSSAPI (Kerberos 5) assume a specific
1395 authentication system. In theory this means that the SASL library
1396 would not need to interact with the application, but rather call this
1397 specific authentication system directly. However, some callbacks are
1398 supported anyway, to modify the behaviour of how the specific
1399 authentication system is used (i.e., to handle ``super-user'' login as
1402 Some mechanisms, like @samp{EXTERNAL} and @samp{ANONYMOUS} are
1403 entirely dependent on callbacks.
1406 * EXTERNAL:: Authentication via out of band information.
1407 * ANONYMOUS:: Mechanism for anonymous access to resources.
1408 * PLAIN:: Clear text username and password.
1409 * LOGIN:: Non-standard clear text username and password.
1410 * CRAM-MD5:: Challenge-Response Authentication Mechanism.
1411 * DIGEST-MD5:: Digest Authentication.
1412 * NTLM:: Microsoft NTLM authentication.
1413 * SECURID:: Authentication using tokens.
1414 * GSSAPI:: GSSAPI (Kerberos 5) authentication.
1415 * KERBEROS_V5:: Experimental KERBEROS_V5 authentication.
1419 @section The EXTERNAL mechanism
1421 The EXTERNAL mechanism is used to authenticate a user to a server
1422 based on out-of-band authentication. EXTERNAL is typically used over
1423 TLS authenticated channels. Note that in the server, you need to make
1424 sure that TLS actually authenticated the client successfully. It is
1425 normally not sufficient that TLS is used, since they also support
1428 In the client, this mechanism is always enabled, and will send the
1429 @code{GSASL_AUTHZID} property as the authorization name to the server,
1430 if the property is set. If the property is not set, the empty
1431 authorization name is sent. You need not implement a callback.
1433 In the server, this mechanism will invoke the
1434 @code{GSASL_VALIDATE_EXTERNAL} callback to decide whether the client
1435 is authenticated and authorized to log in. Your callback can retrieve
1436 the @code{GSASL_AUTHZID} property to inspect the requested
1437 authorization name from the client.
1440 @section The ANONYMOUS mechanism
1442 The ANONYMOUS mechanism is used to ``authenticate'' clients to
1443 anonymous services; or rather, just indicate that the client wishes to
1444 use the service anonymously. The client sends a token, usually her
1445 email address, which serve the purpose of some trace information
1446 suitable for log files. The token is not permitted to be empty.
1448 In the client, this mechanism is always enabled, and will send the
1449 @code{GSASL_ANONYMOUS_TOKEN} property as the trace information to the
1452 In the server, this mechanism will invoke the
1453 @code{GSASL_VALIDATE_ANONYMOUS} callback to decide whether the client
1454 should be permitted to log in. Your callback can retrieve the
1455 @code{GSASL_ANONYMOUS_TOKEN} property to, for example, save it in a
1456 log file. The token is normally not used to decide whether the client
1457 should be permitted to log in or not.
1460 @section The PLAIN mechanism
1462 The PLAIN mechanism uses username and password to authenticate users.
1463 Two user names are relevant. The first, the authentication identity,
1464 indicate the credential holder, i.e., whom the provided password
1465 belongs to. The second, the authorization identity, is typically
1466 empty, to indicate that the user requests to log on to the server as
1467 herself. However, if the authorization identity is not empty, the
1468 server should decide whether the authenticated user may log on as the
1469 authorization identity. Normally, only ``super-user'' accounts such
1470 as @samp{admin} or similar should be allowed this.
1472 In the client, this mechanism is always enabled, and require the
1473 @code{GSASL_AUTHID} and @code{GSASL_PASSWORD} properties. If set,
1474 @code{GSASL_AUTHZID} will also be used.
1476 In the server, the mechanism is always enabled. Two approaches to
1477 authenticate and authorize the client is provided.
1479 In the first approach, the server side of the mechanism will invoke
1480 the @code{GSASL_VALIDATE_SIMPLE} callback property to decide whether
1481 the client should be accepted or not. The callback may inspect the
1482 @code{GSASL_AUTHID}, @code{GSASL_AUTHID}, and @code{GSASL_PASSWORD}
1483 properties. These properties values will be normalized.
1485 If the first approach fails (because, e.g., your callback return
1486 @samp{GSASL_NO_CALLBACK} to signal that it does not implement
1487 @code{GSASL_VALIDATE_SIMPLE}) the mechanism will continue to query the
1488 application for a password, via the @code{GSASL_PASSWORD} property.
1489 Your callback may use the @code{GSASL_AUTHID} and @code{GSASL_AUTHZID}
1490 properties to select the proper password. The password is then
1491 normalized and compared to the client credential.
1493 Which approach to use? If your database store hashed passwords, you
1494 have no option, but must use the first approach. If passwords in your
1495 user database are stored in prepared (@acronym{SASLprep}) form, the
1496 first approach will be faster. If you do not have prepared passwords
1497 available, you can use the second approach to make sure the password
1498 is prepared properly before comparison.
1501 @section The LOGIN mechanism
1503 The LOGIN mechanism is a non-standard mechanism, and is similar to the
1504 PLAIN mechanism except that LOGIN lack the support for authorization
1505 identities. Always use PLAIN instead of LOGIN in new applications.
1507 The callback behaviour is the same as for PLAIN, except that
1508 @code{GSASL_AUTHZID} is not used nor required, and that the server do
1509 not normalize the password using @acronym{SASLprep}.
1511 @xref{Use of SASLprep in LOGIN}, for a proposed clarification of the
1512 interpretation of a hypothetical LOGIN specification.
1515 @section The CRAM-MD5 mechanism
1517 The CRAM-MD5 is a widely used, but officially deprecated (apparently
1518 in favor of DIGEST-MD5), challenge-response mechanism that transfer
1519 hashed passwords instead of clear text passwords. For insecure
1520 channels (e.g., when @acronym{TLS} is not used), it is safer than
1521 PLAIN. The CRAM-MD5 mechanism do not support authorization
1522 identities; making the relationship between CRAM-MD5 and DIGEST-MD5
1523 similar to the relationship between LOGIN and PLAIN.
1525 The disadvantage with hashed passwords is that the server cannot use
1526 normal authentication infrastructures such as PAM, because the server
1527 must have access to the correct password in order to validate an
1528 authentication attempt.
1530 In the client, this mechanism is always enabled, and require the
1531 @code{GSASL_AUTHID} and @code{GSASL_PASSWORD} properties.
1533 In the server, the mechanism will invoke the @code{GSASL_PASSWORD}
1534 callback, which may use the @code{GSASL_AUTHID} property to determine
1535 which users' password should be used. The @code{GSASL_AUTHID} will be
1536 in normalized form. The server will then normalize the returned
1537 password, and compare the client response with the computed correct
1538 response, and accept the user accordingly.
1540 @xref{Use of SASLprep in CRAM-MD5}, for a clarification on the
1541 interpretation of the CRAM-MD5 specification that this implementation
1545 @section The DIGEST-MD5 mechanism
1547 The DIGEST-MD5 mechanism is based on repeated hashing using MD5, which
1548 after the MD5 break may be argued to be weaker than HMAC-MD5, but
1549 supports more features. For example, authorization identities and
1550 data integrity and privacy protection are supported. Like CRAM-MD5,
1551 only a hashed password is transfered. Consequently, DIGEST-MD5 need
1552 access to the correct password (although it may be hashed, another
1553 improvement compared to CRAM-MD5) to verify the client response.
1554 Alas, this make it impossible to use, e.g., @acronym{PAM} on the
1557 In the client, this mechanism is always enabled, and require the
1558 @code{GSASL_AUTHID}, @code{GSASL_PASSWORD}, @code{GSASL_SERVICE}, and
1559 @code{GSASL_HOSTNAME} properties. If set, @code{GSASL_AUTHZID} and
1560 @code{GSASL_REALM} will also be used.
1562 In the server, the mechanism will invoke the @code{GSASL_PASSWORD}
1563 callback, which may use the @code{GSASL_AUTHID}, @code{GSASL_AUTHZID}
1564 and @code{GSASL_REALM} properties to determine which users' password
1565 should be used. The server will then compare the client response with
1566 a computed correct response, and accept the user accordingly.
1568 Currently only the authentication quality of service is implemented.
1569 In other words, payload integrity or privacy protection are not
1570 supported. Consequently, there are no properties for the maximum
1571 buffer size, quality of protection, and cipher fields.
1574 @section The NTLM mechanism
1576 The NTLM is a non-standard mechanism. Do not use it in new
1577 applications, and do not expect it to be secure. Currently only the
1578 client side is supported.
1580 In the client, this mechanism is always enabled, and require the
1581 @code{GSASL_AUTHID} and @code{GSASL_PASSWORD} properties. It will set
1582 the @samp{domain} field in the NTLM request to the value of
1583 @code{GSASL_REALM}. Some servers reportedly need non-empty but
1584 arbitrary values in that field.
1587 @section The SECURID mechanism
1589 The SECURID mechanism uses authentication and authorization identity
1590 together with a passcode from a hardware token to authenticate users.
1592 In the client, this mechanism is always enabled, and require the
1593 @code{GSASL_AUTHID} and @code{GSASL_PASSCODE} properties. If set,
1594 @code{GSASL_AUTHZID} will also be used. If the server requests it,
1595 the @code{GSASL_PIN} property is also required, and its callback may
1596 inspect the @code{GSASL_SUGGESTED_PIN} property to discover a
1597 server-provided PIN to use.
1599 In the server, this mechanism will invoke the
1600 @code{GSASL_VALIDATE_SECURID} callback. The callback may inspect the
1601 @code{GSASL_AUTHID}, @code{GSASL_AUTHZID}, and @code{GSASL_PASSCODE}
1602 properties. The callback can return
1603 @code{GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE} to ask for
1604 another additional passcode from the client. The callback can return
1605 @code{GSASL_SECURID_SERVER_NEED_NEW_PIN} to ask for a new PIN code
1606 from the client, in which case it may also set the
1607 @code{GSASL_SUGGESTED_PIN} property to indicate a recommended new PIN.
1608 If the callbacks has invoked again, after having returned
1609 @code{GSASL_SECURID_SERVER_NEED_NEW_PIN}, it may also inspect the
1610 @code{GSASL_PIN} property, in addition to the other properties, to
1611 find out the client selected PIN code.
1614 @section The GSSAPI mechanism
1616 GSS-API is a framework, similar to SASL, for authentication. The
1617 GSSAPI mechanism only support the Kerberos 5 GSS-API mechanism,
1618 though. (A new SASL mechanism to support non-Kerberos 5 GSS-API
1619 mechanisms may be supported in the future.)
1621 In the client, the mechanism is enabled only if the user has acquired
1622 credentials (i.e., a ticket granting ticket), and require the
1623 @code{GSASL_AUTHID}, @code{GSASL_SERVICE}, and @code{GSASL_HOSTNAME}
1626 In the server, the mechanism require the @code{GSASL_SERVICE}, and
1627 @code{GSASL_HOSTNAME} properties, and will invoke the
1628 @code{GSASL_VALIDATE_GSSAPI} callback in order to validate the user.
1629 The callback may inspect the @code{GSASL_AUTHZID} and
1630 @code{GSASL_GSSAPI_DISPLAY_NAME} properties to decide whether to
1631 authorize the user. Note that authentication is performed by the
1634 XXX: explain more about quality of service, maximum buffer size, etc.
1637 @section The KERBEROS_V5 mechanism
1639 The KERBEROS_V5 is an experimental mechanism, the protocol
1640 specification is available on the GNU SASL homepage. It can operate
1641 in three modes, non-infrastructure mode, infrastructure mode and
1642 proxied infrastructure mode. Currently only non-infrastructure mode
1645 In the non-infrastructure mode, it works as a superset of most
1646 features provided by PLAIN, CRAM-MD5, DIGEST-MD5 and GSSAPI while at
1647 the same time building on what is believed to be proven technology
1648 (the RFC 1510 network security system). In the non-infrastructure
1649 mode, the client must specify (via callbacks) the name of the user,
1650 and optionally the server name and realm. The server must be able to
1651 retrieve passwords given the name of the user.
1653 In the infrastructure mode (proxied or otherwise), it allows clients
1654 and servers to authenticate via SASL in an RFC 1510 environment, using
1655 a trusted third party, a ``Key Distribution Central''. In the normal
1656 mode, clients aquire tickets out of band and then invokes a one
1657 roundtrip AP-REQ and AP-REP exchange. In the proxied mode, which can
1658 be used by clients without IP addresses or without connectivity to the
1659 KDC (e.g., when the KDC is IPv4 and the client is IPV6-only), the
1660 client uses the server to proxy ticket requests and finishes with the
1661 AP-REQ/AP-REP exchange. In infrastructure mode (proxied or
1662 otherwise), the client nor server need to implement any callbacks
1663 (this will likely change later, to allow a server to authorize users,
1664 similar to the GSSAPI callback).
1666 XXX: update when implementation has matured
1668 @c **********************************************************
1669 @c ***************** Global Functions *********************
1670 @c **********************************************************
1671 @node Global Functions
1672 @chapter Global Functions
1674 @include texi/init.c.texi
1675 @include texi/done.c.texi
1676 @include texi/listmech.c.texi
1677 @include texi/supportp.c.texi
1678 @include texi/suggest.c.texi
1679 @include texi/register.c.texi
1682 @c **********************************************************
1683 @c ****************** Callback Functions ******************
1684 @c **********************************************************
1685 @node Callback Functions
1686 @chapter Callback Functions
1689 The callback is used by mechanisms to retrieve information, such as
1690 username and password, from the application. In a server, the
1691 callback is used to decide whether a user is permitted to log in or
1692 not. You tell the library of your callback function by calling
1693 @code{gsasl_callback_set}.
1695 Since your callback may need to access to data from other parts of
1696 your application, there are hooks to store and retrieve application
1697 specific pointers. This avoid the use of global variables in your
1698 application, which wouldn't be thread safe. You store a pointer to
1699 some information (opaque from the point of view of the library) by
1700 calling @code{gsasl_callback_hook_set} and can later retrieve this
1701 data in your callback by calling @code{gsasl_callback_hook_get}.
1703 @include texi/callback.c.texi
1705 @c **********************************************************
1706 @c ****************** Property Functions ******************
1707 @c **********************************************************
1708 @node Property Functions
1709 @chapter Property Functions
1712 @include texi/property.c.texi
1715 @c **********************************************************
1716 @c ***************** Session Functions ********************
1717 @c **********************************************************
1718 @node Session Functions
1719 @chapter Session Functions
1720 @cindex SASL sessions
1722 @include texi/xstart.c.texi
1723 @include texi/xstep.c.texi
1724 @include texi/xfinish.c.texi
1725 @include texi/xcode.c.texi
1729 @c **********************************************************
1730 @c ******************* Utilities **************************
1731 @c **********************************************************
1735 @include texi/saslprep.c.texi
1736 @include texi/base64.c.texi
1737 @include texi/md5pwd.c.texi
1738 @include texi/crypto.c.texi
1740 @c **********************************************************
1741 @c **************** Memory Handling ***********************
1742 @c **********************************************************
1743 @node Memory Handling
1744 @chapter Memory Handling
1746 @include texi/free.c.texi
1749 @c **********************************************************
1750 @c ******************* Errors ****************************
1751 @c **********************************************************
1752 @node Error Handling
1753 @chapter Error Handling
1754 @cindex Error Handling
1756 Most functions in the GNU SASL Library are returning an error if they
1757 fail. For this reason, the application should always catch the error
1758 condition and take appropriate measures, for example by releasing the
1759 resources and passing the error up to the caller, or by displaying a
1760 descriptive message to the user and cancelling the operation.
1762 Some error values do not indicate a system error or an error in the
1763 operation, but the result of an operation that failed properly.
1766 * Error values:: A list of all error values used.
1767 * Error strings:: How to get a descriptive string from a value.
1771 @section Error values
1773 Errors are returned as an @code{int}. Except for the OK case an
1774 application should always use the constants instead of their numeric
1775 value. Applications are encouraged to use the constants even for OK
1776 as it improves readability. Possible values are:
1779 @item @code{GSASL_OK}
1780 This value indicates success. The value of this error is guaranteed
1781 to always be @code{0} so you may use it in boolean constructs.
1783 @include gsasl-api-error-labels.texi
1788 @section Error strings
1790 @include texi/error.c.texi
1792 @c **********************************************************
1793 @c *********************** Examples ***********************
1794 @c **********************************************************
1799 This chapter contains example code which illustrate how the GNU SASL
1800 Library can be used when writing your own application.
1803 * Example 1:: SASL client.
1804 * Example 2:: SASL client where server send data first.
1805 * Example 3:: SASL client, with a choice of mechanism to use.
1806 * Example 4:: SASL client, with callback for user info.
1813 @verbatiminclude client.c
1820 @verbatiminclude client-serverfirst.c
1827 @verbatiminclude client-mech.c
1834 @verbatiminclude client-callback.c
1838 @c **********************************************************
1839 @c ******************* Acknowledgements *******************
1840 @c **********************************************************
1841 @node Acknowledgements
1842 @chapter Acknowledgements
1844 The makefiles, manuals, etc borrowed much from Libgcrypt written by
1847 Cryptographic functions for some SASL mechanisms uses Libgcrypt by
1848 Werner Koch et al. The NTLM mechanism uses Libntlm by Grant Edwards
1849 et al, using code from Samba written by Andrew Tridgell, and now
1850 maintained by Simon Josefsson. The KERBEROS_V5 mechanism uses Shishi
1851 by Simon Josefsson. The GSSAPI mechanism uses a GSS-API
1852 implementation, such as GSSLib by Simon Josefsson.
1854 Gnulib is used to simplify portability.
1856 This manual borrows text from the SASL specification.
1858 @c **********************************************************
1859 @c ******************** Invoking gsasl ********************
1860 @c **********************************************************
1861 @node Invoking gsasl
1862 @chapter Invoking gsasl
1865 @cindex invoking @command{gsasl}
1866 @cindex command line
1870 GNU SASL (gsasl) -- Command line interface to libgsasl.
1872 @majorheading Description
1873 @code{gsasl} is the main program of GNU SASL.
1875 This section only lists the commands and options available.
1877 Mandatory or optional arguments to long options are also mandatory or
1878 optional for any corresponding short options.
1880 @majorheading Commands
1881 @code{gsasl} recognizes these commands:
1884 -c, --client Act as client (the default).
1885 --client-mechanisms Write name of supported client mechanisms
1886 separated by space to stdout.
1887 -s, --server Act as server.
1888 --server-mechanisms Write name of supported server mechanisms
1889 separated by space to stdout.
1892 @majorheading Network Options
1894 Normally the SASL negotiation is performed on the terminal, with
1895 reading from stdin and writing to stdout. It is also possible to
1896 perform the negotiation with a server over a TCP network connection.
1899 --connect=HOSTNAME[:SERVICE]
1900 Connect to TCP server and negotiate on stream
1901 instead of stdin/stdout. SERVICE is the protocol
1902 service, or an integer denoting the port, and
1903 defaults to 143 (imap) if not specified. Also sets
1904 the --hostname default.
1907 @majorheading Miscellaneous Options:
1909 These parameters affect overall behaviour.
1912 -d, --application-data After authentication, read data from stdin and run
1913 it through the mechanism's security layer and
1914 print it base64 encoded to stdout. The default is
1915 to terminate after authentication.
1916 --imap Use a IMAP-like logon procedure (client only).
1917 Also sets the --service default to "imap".
1918 -m, --mechanism=STRING Mechanism to use.
1919 --no-client-first Disallow client to send data first (client only).
1922 @majorheading SASL Mechanism Options
1924 These options modify the behaviour of the callbacks (@pxref{Callback
1925 Functions}) in the library. The default is the query the user on the
1929 -n, --anonymous-token=STRING Token for anonymous authentication, usually
1930 mail address (ANONYMOUS only).
1931 -a, --authentication-id=STRING Identity of credential owner.
1932 -z, --authorization-id=STRING Identity to request service for.
1933 --disable-cleartext-validate
1934 Disable cleartext validate hook, forcing server to
1935 prompt for password.
1936 --enable-cram-md5-validate Validate CRAM-MD5 challenge and response
1938 --hostname=STRING Set the name of the server with the requested
1940 -p, --password=STRING Password for authentication (insecure for
1941 non-testing purposes).
1942 --passcode=NUMBER Passcode for authentication (SECURID only).
1943 --quality-of-protection=<auth | auth-int | auth-conf>
1944 How application payload will be protected. "auth"
1945 means no protection, "auth-int" means integrity
1946 protection, "auth-conf" means integrity and
1947 confidentialiy protection. Currently only used by
1948 DIGEST-MD5, where the default is "auth-conf".
1949 -r, --realm=STRING Realm. Defaults to hostname.
1950 --service=STRING Set the requested service name (should be a
1951 registered GSSAPI host based service name).
1952 --service-name=STRING Set the generic server name in case of a
1953 replicated server (DIGEST-MD5 only).
1954 -x, --maxbuf=NUMBER Indicate maximum buffer size (DIGEST-MD5 only).
1957 @majorheading STARTTLS options
1960 --starttls Force use of STARTTLS. The default is to use
1961 STARTTLS when available. (default=off)
1962 --no-starttls Unconditionally disable STARTTLS.
1964 --x509-ca-file=FILE File containing one or more X.509 Certificate
1965 Authorities certificates in PEM format, used
1966 to verify the certificate received from the
1967 server. If not specified, no verification of
1968 the remote server certificate will be done.
1969 --x509-cert-file=FILE File containing client X.509 certificate in PEM
1970 format. Used together with --x509-key-file
1971 to specify the certificate/key pair.
1972 --x509-key-file=FILE Private key for the client X.509 certificate in
1973 PEM format. Used together with
1974 --x509-key-file to specify the
1975 certificate/key pair.
1978 @majorheading Other Options
1980 These are some standard parameters.
1983 -q, --quiet, --silent Don't produce any diagnostic output.
1984 -v, --verbose Produce verbose output.
1986 -?, --help Give this help list
1987 --usage Give a short usage message
1988 -V, --version Print program version
1991 @c **********************************************************
1992 @c ******************* Appendices *************************
1993 @c **********************************************************
1995 @node Protocol Clarifications
1996 @appendix Protocol Clarifications
1998 This appendix contain clarification to various SASL specification that
1999 we felt were necessary to include, if for nothing else it may serve as
2000 a guide for other implementors that worry about the same issues.
2003 * Use of SASLprep in CRAM-MD5::
2004 * Use of SASLprep in LOGIN::
2007 @node Use of SASLprep in CRAM-MD5
2008 @section Use of SASLprep in CRAM-MD5
2010 The specification, as of @file{draft-ietf-sasl-crammd5-04.txt}, is
2011 silent on whether a SASL server implementation applying
2012 @acronym{SASLprep} on a password received from an external, non-SASL
2013 specific database (i.e., the passwords are not stored in
2014 @acronym{SASLprep} form in the database), should set or clear the
2015 AllowUnassigned bit. The motivation for the AU-bit in
2016 @acronym{StringPrep}/@acronym{SASLprep} is for stored vs query
2017 strings. It could be argued that in this situation the server can
2018 treat the external password either as a stored string (from a
2019 database) or as a query (the server uses the string as a query into
2020 the fixed HMAC-MD5 hash).
2022 The specification is also unclear on whether clients should set or
2023 clear the AllowUnassigned flag.
2025 In the server, GNU SASL apply @acronym{SASLprep} to the password with
2026 the AllowUnassigned bit cleared.
2028 @node Use of SASLprep in LOGIN
2029 @section Use of SASLprep in LOGIN
2031 The non-standard mechanism LOGIN presumably does not support
2032 non-ASCII. We suggest that the client should send unprepared UTF-8
2033 and that the server apply SASLprep with the AllowUnassigned bit
2034 cleared on the received username and password.
2036 @c **********************************************************
2037 @c ******************* Old Functions **********************
2038 @c **********************************************************
2040 @appendix Old Functions
2041 @cindex Deprecated functions
2042 @cindex Obsolete functions
2044 As GNU SASL is still under heavy development, some API functions have
2045 been found to be less useful. Those old API functions will be
2046 supported during a transition period. Refer to the NEWS file to find
2047 out since when a function has been deprecated.
2049 @include texi/obsolete.c.texi
2051 @section Obsolete callback function prototypes
2053 @deftypefn Prototype int (*Gsasl_client_callback_anonymous) (Gsasl_session_ctx * @var{ctx}, char * @var{out}, size_t * @var{outlen})
2055 @var{ctx}: libgsasl handle.
2057 @var{out}: output array with client token.
2059 @var{outlen}: on input the maximum size of the output array, on output
2060 contains the actual size of the output array.
2062 Type of callback function the application implements. It should
2063 populate the output array with some input from the user and set the
2064 output array length, and return @code{GSASL_OK}, or fail with an error
2067 If OUT is NULL, the function should only populate the output length
2068 field with the length, and return GSASL_OK. This usage may be used by
2069 the caller to allocate the proper buffer size.
2073 @deftypefn Prototype int (*Gsasl_server_callback_anonymous) (Gsasl_session_ctx * @var{ctx}, const char * @var{token})
2075 @var{ctx}: libgsasl handle.
2077 @var{ctx}: output array with client token.
2079 @var{ctx}: on input the maximum size of the output array, on output
2080 contains the actual size of the output array. If OUT is
2082 Type of callback function the application implements. It should
2083 return @code{GSASL_OK} if user should be permitted anonymous access,
2084 otherwise @code{GSASL_AUTHENTICATION_ERROR}.
2088 @include gsasl-callback-authentication.texi
2089 @include gsasl-callback-authorization.texi
2090 @include gsasl-callback-client-service.texi
2091 @include gsasl-callback-cram-md5.texi
2092 @include gsasl-callback-digest-md5.texi
2094 @deftypefn Prototype int (*Gsasl_server_callback_external) (Gsasl_session_ctx * @var{ctx})
2096 @var{ctx}: libgsasl handle.
2098 Type of callback function the application implements. It should
2099 return @code{GSASL_OK} if user is authenticated by out of band means,
2100 otherwise @code{GSASL_AUTHENTICATION_ERROR}.
2104 @include gsasl-callback-gssapi.texi
2105 @include gsasl-callback-passcode.texi
2106 @include gsasl-callback-password.texi
2107 @include gsasl-callback-retrieve.texi
2108 @include gsasl-callback-securid.texi
2109 @include gsasl-callback-server-service.texi
2110 @include gsasl-callback-validate.texi
2112 @node Copying Information
2113 @appendix Copying Information
2116 * GNU Free Documentation License:: License for copying this manual.
2117 * GNU LGPL:: License for copying the library.
2118 * GNU GPL:: License for copying the programs.
2121 @node GNU Free Documentation License
2122 @appendixsec GNU Free Documentation License
2124 @cindex FDL, GNU Free Documentation License
2129 @appendixsec GNU Lesser General Public License
2130 @cindex LGPL, GNU Lesser General Public License
2131 @cindex License, GNU LGPL
2133 @include lgpl-2.1.texi
2136 @appendixsec GNU General Public License
2137 @cindex GPL, GNU General Public License
2138 @cindex License, GNU GPL
2140 @include gpl-3.0.texi
2142 @node Function and Data Index
2143 @unnumbered Function and Data Index
2148 @unnumbered Concept Index