7 Network Working Group C. Newman
8 Internet Draft: SASL C API Innosoft
9 Document: draft-newman-sasl-c-api-01.txt A. Melnikov
15 Simple Authentication and Security Layer C API
20 This document is an Internet-Draft and is in full conformance with
21 all provisions of Section 10 of RFC2026 [RFC2026].
23 Internet-Drafts are working documents of the Internet Engineering
24 Task Force (IETF), its areas, and its working groups. Note that other
25 groups may also distribute working documents as Internet-Drafts.
27 Internet-Drafts are draft documents valid for a maximum of six months
28 and may be updated, replaced, or obsoleted by other documents at any
29 time. It is inappropriate to use Internet-Drafts as reference
30 material or to cite them other than as "work in progress."
32 The list of current Internet-Drafts can be accessed at
33 http://www.ietf.org/ietf/1id-abstracts.txt
35 The list of Internet-Draft Shadow Directories can be accessed at
36 http://www.ietf.org/shadow.html.
40 Almost every protocol needs authentication. However, there does not
41 exist an authentication mechanism suitable for all organizations, nor
42 is it likely that a small fixed set of authentication mechanisms will
43 remain suitable. SASL [SASL] provides the on-the-wire framework for
44 authentication (and a security layer) which separates the design of
45 authentication mechanisms from the protocols in which they're used.
47 The SASL protocol model suggests a software architecture where
48 application protocols call a generic API to authenticate which in
49 turn calls a generic plug-in interface for extensible authentication
50 modules. This memo documents the API used in one implementation of
51 this architecture in the hope that it will be useful to others. An
52 associated memo documenting the plug-in interface is forthcoming.
54 1. Conventions Used in this Memo
58 Newman et al. Expires: August 2003 FORMFEED[Page 1]
64 INTERNET DRAFT SASL C API February 2003
67 The key words "MUST", "MUST NOT", "SHOULD", "SHOULD NOT", and "MAY"
68 in this document are to be interpreted as defined in "Key words for
69 use in RFCs to Indicate Requirement Levels" [KEYWORDS].
71 This assumes familiarity the SASL [SASL] specification.
75 The following concepts are necessary to understand this
79 A realm is a name (usually a domain-style name) associated with a
80 set of users on a server. One realm may span multiple servers.
81 Alternatively, a single server may have multiple realms. Thus
82 there may be multiple users with the username "chris" on the same
83 server, each in a different realm. Some authentication mechanisms
84 have a special field for the realm (e.g., DIGEST-MD5). For other
85 mechanisms, a realm can be specified by the client by using the
86 syntax "username@realm" in the username field.
89 A service is a basic function provided by one or more protocols.
90 The GSSAPI service name [GSSAPI] registry is available at:
92 <http://www.iana.org/numbers.html#G>
94 This registry is used by SASL and the SASL API. The service name
95 may be used for service-specific passwords for advanced users, or
96 advanced authentication mechanisms may restrict the services a
97 given server may offer.
101 When a single server has multiple realms and there is a DNS server
102 entry for each realm pointing to the same server IP address, then
103 those realms are "virtual domains". Virtual domains are extremely
104 popular with web hosting services and are becoming more popular
105 with POP mail services. The key to providing virtual domain sup-
106 port is that the client informs the server of the domain it
107 believes it is speaking to either through a special protocol ele-
108 ment or by using a username of the form "user@realm".
111 2. Overview of the SASL C API
113 The SASL API is initialized once at process startup. The
114 sasl_server_init() and sasl_client_init() functions provide basic
118 Newman et al. Expires: August 2003 FORMFEED[Page 2]
124 INTERNET DRAFT SASL C API February 2003
129 When a network connection occurs where SASL will be used, a connec-
130 tion-specific context is created for authentication with
131 sasl_client_new() or sasl_server_new(). The API implementation must
132 support multi-threaded servers and clients by creating the connection
133 context in a thread-safe fashion permitting multiple contexts in a
134 given process. At this point, the caller may adjust security policy
135 for the context, and the set of mechanisms which are enabled is
136 determined by requirements from the configuration or by the caller.
138 The server end of the API may request a list of enabled authentica-
139 tion mechanisms either in general or for a specific user. The client
140 may either select a single mechanism or request a list from the
141 server (if the SASL profile for the protocol in question supports
142 that) and pass the list to the API for automated mechanism selection
143 by configured policy.
145 The SASL exchange begins with sasl_client_start() which determines if
146 one of the desired mechanisms is available on the client and may gen-
147 erate an initial client response. The client then sends the appro-
148 priate protocol message to initiate the SASL exchange that the server
149 passes to sasl_server_start().
151 The SASL exchange continues with calls to sasl_client_step() and
152 sasl_server_step(), until the server indicates completion or the
153 client cancels the exchange.
155 The server queries the user name and user realm resulting from the
156 exchange with the sasl_getprop() routine.
158 A connection context is released with sasl_dispose() and process ter-
159 mination is indicated with sasl_done().
161 There are a number of utility functions and customization functions
162 available in the API for additional services.
164 Note, that all functions described in this documen can be implemented
165 as macroses, so an application using this API MUST NOT assume that
168 An application or library trying to use SASL API described in this
169 document must include "sasl.h" include file.
171 3. Basic SASL API Routines
173 This section describes the types and functions likely to be used by
174 every caller of the SASL API.
178 Newman et al. Expires: August 2003 FORMFEED[Page 3]
184 INTERNET DRAFT SASL C API February 2003
187 3.1. Basic SASL API Data Structures
189 The following datastructures are basic to the SASL API.
191 3.1.1. sasl_callback_t
193 The sasl_callback_t structure is used for the caller of the SASL API
194 to provide services to both the core SASL API and SASL plug-ins via
195 callbacks. The most important callback is the "getopt" callback (see
196 section 3.3.3) which is used to retrieve security policy option set-
197 tings from the caller's preferences.
199 typedef struct sasl_callback {
205 id is the label for the callback (XXX IANA registry needed), proc is
206 a function pointer whose exact type is determined by the id, and con-
207 text is a context variable which will be passed to the callback (usu-
208 ally as the first argument). The last callback in the list of call-
209 backs is indicated with an id of SASL_CB_LIST_END.
211 If proc is NULL, this means that the application doesn't want to
212 specify a corresponding callback, but would provide the necessary
213 data via interaction. See also section 3.1.4.
217 The sasl_secret_t structure is used to hold text or binary passwords
220 typedef struct sasl_secret {
222 unsigned char data[1];
225 The len field holds the length of the password, while the data field
226 holds the actual data. The structure is variable sized: enough space
227 must be reserved after the data field to hold the desired password.
228 An additional that binary passwords are permitted to contain '\0'
233 The sasl_conn_t data type is an opaque data type which reflects the
234 SASL context for a single server connection. Only one SASL API call
238 Newman et al. Expires: August 2003 FORMFEED[Page 4]
244 INTERNET DRAFT SASL C API February 2003
247 using a given sasl_conn_t as an argument may be active at a time.
248 However, each sasl_conn_t is independent and thus the SASL API may be
249 used in a true multi-processor multi-threaded environment.
251 3.1.4. sasl_interact_t
253 The sasl_interact_t structure is used by sasl_client_start and
254 sasl_client_step to request certain information from the application,
255 when the application did not provide corresponding callbacks. For
256 example, an application may choose to present a single dialog to the
257 user in order to collect all required information interactively.
259 typedef struct sasl_interact {
261 const char *challenge;
263 const char *defresult;
268 The id field holds the value of the callback ID. The prompt field
269 contains a string that should be presented to the user. If non-NULL,
270 challenge is a NUL-terminated string that will allow the user to pre-
271 sent a specific credential when prompted. This is different from the
272 prompt in that the prompt is more like a label for a text box (for
273 example "Response:" while challenge is a string that tells the user
274 what specifically is required by the response (for example, an OTP
275 challenge string). The defresult field contains a default value, if
276 any. Upon return from sasl_client_* the "result" field points to the
277 defresult. The client must present the information in the challenge
278 and the prompt to the user and store the result and its length in the
279 result and the len fields respectively.
281 For example, SASL_CB_PASS interaction may contain the following
286 defresult - NULL (no default).
288 3.2. Basic SASL API Client Routines
290 This section discusses the functions likely to be used by every
291 client caller of the SASL API.
293 3.2.1. sasl_client_init function
298 Newman et al. Expires: August 2003 FORMFEED[Page 5]
304 INTERNET DRAFT SASL C API February 2003
308 sasl_callback_t *callbacks
312 SASL_NOMEM -- Not enough memory
313 SASL_BADVERS -- Mechanism version mismatch
314 SASL_BADPARAM -- Error in config file
316 This function initializes the client routines for the SASL API.
318 The callbacks argument is the default list of callbacks (see sec-
319 tion 3.1.1 for definition of sasl_callback_t structure) and SHOULD
320 include the sasl_getopt_t callback (see section 3.3.3). The call-
321 backs may be NULL. On success, SASL_OK is returned, and on fail-
322 ure a SASL C API error code such as the ones listed above is
323 returned. This function may be called a second time to change the
324 default callbacks used for new connections, but the first call
325 must be made in a single-threaded environment. The data refer-
326 enced by the sasl_callback_t structure must persist until
327 sasl_done() is called.
329 3.2.2. sasl_client_new function
333 const char *server_name,
334 const char *iplocalport,
335 const char *ipremoteport,
336 const sasl_callback_t *prompt_supp,
342 SASL_NOTINIT -- SASL API not initialized
343 SASL_NOMECH -- No mechanisms available
344 SASL_NOMEM -- Not enough memory
346 This function creates a client connection context variable. As
347 long as each thread uses its own connection context, the SASL C
350 The service argument is an IANA registered GSSAPI service element
351 as defined in section 1.1. It MUST NOT be NULL.
353 The server_name is the host name or IP address of the server to
354 which the client is connecting. NULL may be used for server_name,
358 Newman et al. Expires: August 2003 FORMFEED[Page 6]
364 INTERNET DRAFT SASL C API February 2003
367 but may result in advanced mechanisms such as Kerberos being
370 The iplocalport is the string with the client IPv4/IPv6 address,
371 followed by ":" and than by port number. An IPv6 address must be
372 enclosed in "[" and "]". NULL may be used for iplocalport, but may
373 result in mechanisms requiring IP address being unavailable.
375 The ipremoteport is the string with the server IPv4/IPv6 address,
376 followed by ":" and than by port number. An IPv6 address must be
377 enclosed in "[" and "]". NULL may be used for ipremoteport, but
378 may result in mechanisms requiring IP address being unavailable.
380 User input to the SASL C API may be provided in two ways: either
381 by supplying callbacks (prompt_supp) to this function, or by using
382 an interaction model with the sasl_client_start/sasl_client_step
383 functions. Callbacks are more convenient to obtain information
384 programmatically, such as pulling authentication information
385 directly from a configuration file. Interactions are more conve-
386 nient if one wants to get all the data in parallel, for example by
387 displaying a single dialog box instead of a separate popup for
388 authentication name, authorization, password, etc.
390 The prompt_supp is a list of supported user prompting callbacks
391 discussed in the section 3.1.1. The prompt_supp argument MAY be
392 NULL, which means that interactions (i.e. prompt_need parameter to
393 sasl_client_start (see 3.2.3) and sasl_client_step (see 3.2.4))
394 are used instead of callbacks. If prompt_supp is NULL, the
395 prompt_need argument to sasl_client_start (see 3.2.3) and
396 sasl_client_step (see 3.2.4) MUST NOT be NULL.
398 The flags argument represents client-supported security flags.
399 The only values currently supported are SASL_SECURITY_LAYER to
400 indicate the client supports the SASL security layer, or 0 to
403 The pconn argument is set to point to the newly created connection
404 context. The sasl_conn_t type is opaque to the calling applica-
407 3.2.3. sasl_client_start function
418 Newman et al. Expires: August 2003 FORMFEED[Page 7]
424 INTERNET DRAFT SASL C API February 2003
429 const char *mechlist,
430 sasl_interact_t **prompt_need,
431 const char **clientout,
432 unsigned int *clientoutlen,
436 SASL_NOTINIT -- SASL API not initialized
437 SASL_BADPARAM -- conn or mechlist is NULL
438 SASL_NOMECH -- No matching mechanisms available
439 SASL_NOMEM -- Not enough memory
440 SASL_INTERACT -- User interaction needed to continue
441 (see prompt_need description below)
444 This selects an authentication mechanism to use and optionally
445 generates an initial client response.
447 The conn argument is the connection context from sasl_client_new.
449 The mechlist argument is a '\0' terminated string containing one
450 or more SASL mechanism names. All characters in the string that
451 are not permitted in a SASL mechanism name [SASL] are ignored
452 except for the purposes of delimiting mechanism names (this per-
453 mits passing direct results from many protocol capability lists
454 unparsed). Unknown mechanism names are ignored (although
455 SASL_NOMECH is returned if no known mechanisms are found). Mecha-
456 nisms are tried in an implementation-dependent order. Implementa-
457 tions SHOULD try to use the most secure mechanism possible, within
458 the constraints specified by the application (e.g. SSF value).
460 For applications which support interactions, the prompt_need argu-
461 ment should initially point to a NULL pointer. If the selected
462 mechanism needs information from the user (for example, username
463 or password), then prompt_need will be set to point to an array of
464 sasl_interact_t structures (terminated by an entry with id equal
465 to SASL_CB_LIST_END), and sasl_client_start will return
466 SASL_INTERACT. After that the client must fill in the requested
467 information and call this function again with the same parameters.
469 Applications that do not support interactions MUST pass NULL for
472 The clientout and clientoutlen parameters are set to the initial
473 client response, if any. If a protocol's SASL profile uses base64
474 encoding, this represents the data prior to the encoding (see
478 Newman et al. Expires: August 2003 FORMFEED[Page 8]
484 INTERNET DRAFT SASL C API February 2003
487 sasl_encode64). If a protocol's SASL profile doesn't include an
488 optional initial client response, then these may be NULL and 0
489 respectively. The memory used by clientout is interally managed by
490 the SASL API and may be overwritten on the next call to
491 sasl_client_step or a call to sasl_dispose.
493 The mech argument is set to point to a '\0' terminated string
494 specifying the mechanism actually selected using all uppercase
495 letters. It may be NULL if the client does not care which mecha-
496 nism was selected from mechlist.
498 If sasl_client_start is called a second time using the same con-
499 nection context, it will discard any cached information (e.g., the
500 username and password) and restart the exchange from the begin-
503 3.2.4. sasl_client_step function
507 const char *serverin,
508 unsigned int serverinlen,
509 sasl_interact_t **prompt_need,
510 const char **clientout,
511 unsigned int *clientoutlen
514 SASL_NOTINIT -- SASL API not initialized
515 SASL_NOMECH -- sasl_client_start not called
516 SASL_BADPROT -- server protocol incorrect/cancelled
517 SASL_BADSERV -- server failed mutual auth
518 SASL_INTERACT -- user interaction needed
521 This routine performs one step in an authentication sequence.
523 The conn argument must be a connection context created by
524 sasl_client_new and used in a previous call to sasl_client_start.
526 The serverin and serverinlen parameters hold the SASL octet string
527 received from the server. Note that for those SASL profiles which
528 base64 encode the exchange, this is the result after the removal
529 of the base64 encoding (see the sasl_decode64 routine below). The
530 serverin MUST have a terminating NUL character not counted by
533 The prompt_need argument is the same as for sasl_client_start.
538 Newman et al. Expires: August 2003 FORMFEED[Page 9]
544 INTERNET DRAFT SASL C API February 2003
547 The clientout and clientoutlen parameters hold the SASL octet
548 string to encode (if necessary) and send to the server.
550 3.3. Basic SASL API Callback Routines
552 This section describes the basic callback functions needed for a
553 simple client implementation. See the definition of sasl_call-
554 back_t in section 3.1.1 for a description of the basic callback
557 3.3.1. sasl_getsimple_t
569 This callback is used by the SASL API to request a simple constant
570 string from the application. This is used with id SASL_CB_USER
571 for the username, SASL_CB_AUTHNAME for the authentication name (if
572 different), and SASL_CB_LANGUAGE for a comma separated list of RFC
575 The context is the context variable from the sasl_callback_t
576 structure, the id is the id from the sasl_callback_t structure,
577 and the callback is expected to set the result to a constant
578 string and the len to the length of that string. The result and
579 len parameters are never NULL.
581 3.3.2. sasl_getsecret_t
587 sasl_secret_t **psecret
593 This callback is expected to create, prompt or locate a secret and
594 set it in the connection context with sasl_setprop. The conn
598 Newman et al. Expires: August 2003 FORMFEED[Page 10]
604 INTERNET DRAFT SASL C API February 2003
607 argument is the connection context, the context and id parameters
608 are from the sasl_callback_t structure. The id SASL_CB_PASS is
609 used to request a clear text password.
615 const char *plugin_name,
624 This callback is used by the SASL API to read options from the
625 application. This allows a SASL configuration to be encapsulated
626 in the caller's configuration system. Configuration items may be
627 mechanism-specific and are arbitrary strings. If the application
628 does not provide a sasl_getopt_t callback, then the API MAY obtain
629 configuration information from other sources, for example from a
632 The context is the context variable from the sasl_callback_t
633 structure, the plugin_name is the name of plugin (or NULL), the
634 option is the option name, and the callback is expected to set the
635 result to a string valid till next call to sasl_getopt_t in the
636 same thread and the len to the length of that string. The result
637 and len parameters are never NULL. If the name of plugin is NULL,
638 a general SASL option is requested, otherwise a plugin specific
641 3.4. Basic SASL C API Utility Routines
643 This section describes utility functions provided as part of the
644 SASL API which may be used both by clients and servers.
646 3.4.1. sasl_decode64 function
658 Newman et al. Expires: August 2003 FORMFEED[Page 11]
664 INTERNET DRAFT SASL C API February 2003
675 SASL_BUFOVER -- output buffer too small
676 SASL_BADPROT -- invalid base64 string
677 SASL_OK -- successful decode
679 This utility routine converts a base64 string of length inlen
680 pointed by in into an octet string. It is useful for SASL profiles
681 which use base64 such as the IMAP [IMAP4] and POP [POP-AUTH] pro-
682 files. The output is copied to the buffer specified by the out
683 parameter. It is NUL terminated and the length of the output is
684 placed in the outlen parameter if outlen is non-NULL. The lenght
685 doesn't include the terminating NUL character.
687 When the size of the output buffer, as specified by outmax, is too
688 small, the function returns SASL_BUFOVER error code and the
689 required length is stored in the outlen parameter if it is not
692 The function may also return SASL_BADPROT error code when it
693 encounters an invalid base64 character.
695 3.4.2. sasl_encode64 function
705 SASL_BUFOVER -- output buffer too small
706 SASL_OK -- successful decode
708 This utility routine converts an octet string of length inlen
709 pointed by in into a base64 string. It is useful for SASL profiles
710 which use base64 such as the IMAP [IMAP4] and POP [POP-AUTH] pro-
713 The output is copied to the buffer specified by the out parameter.
714 It is NUL terminated and the length of the output is placed in the
718 Newman et al. Expires: August 2003 FORMFEED[Page 12]
724 INTERNET DRAFT SASL C API February 2003
727 outlen parameter if outlen is non-NULL. The lenght doesn't include
728 the terminating NUL character.
730 When the size of the output buffer, as specified by outmax, is too
731 small, the function returns SASL_BUFOVER error code and the
732 required length is stored in the outlen parameter if it is not
735 3.4.3. sasl_errstring function
739 const char *langlist,
745 This converts a SASL error number into a constant string. The
746 second argument MAY be NULL for the default language, or a comma-
747 separated list of RFC 1766 language tags. The final parameter is
748 set to the RFC 1766 language tag of the string returned which will
749 be "i-default" if no matching language is found. The strings are
750 UTF-8. This requires no context so it may be used for the result
751 of an sasl_*_init or sasl_*_new result code.
753 3.4.4. sasl_errdetail function
761 This converts the last SASL error code that occured on a connec-
762 tion to UTF8 string. It uses the SASL_CB_LANGUAGE callback (see
763 section 3.3.1) to determine the language to use. It may return
764 more detailed information than sasl_errstring does.
766 3.4.5. sasl_seterror function
778 Newman et al. Expires: August 2003 FORMFEED[Page 13]
784 INTERNET DRAFT SASL C API February 2003
796 This function sets sets the error string which will be returned by
797 sasl_errdetail. It uses syslog()-style formatting (i.e. printf-
798 style with %m as the string form of an errno error).
800 Messages should be sensitive to the current language setting. If
801 there is no SASL_CB_LANGUAGE callback for the connection, text
802 MUST be in US-ASCII. Otherwise UTF-8 is used and use of RFC 2482
803 for mixed-language text is encouraged.
805 <<This will also trigger a call to the SASL logging callback (if
806 any) with a level of SASL_LOG_FAIL unless the SASL_NOLOG flag is
809 This function may be used by server callbacks.
811 If conn is NULL, the function does nothing.
813 3.4.6. sasl_erasebuffer function
822 This function fills the buffer buf of the lenght len with '\0'
823 characters. The function may be used to clear from memory sensi-
824 tive informations, like passwords.
826 3.5. Basic SASL C API Server Routines
828 This section describes the basic routines for a server implementa-
829 tion of a SASL profile.
831 3.5.1. sasl_server_init function
838 Newman et al. Expires: August 2003 FORMFEED[Page 14]
844 INTERNET DRAFT SASL C API February 2003
848 const sasl_callback_t *callbacks,
852 SASL_BADPARAM -- error in config file
853 SASL_NOMEM -- out of memory
854 SASL_BADVERS -- Plug-in version mismatch
857 This function initializes the server routines for the SASL C API.
859 The callbacks argument is the default list of callbacks (see sec-
860 tion 3.1.1 for definition of sasl_callback_t structure) and SHOULD
861 include the sasl_getopt_t callback (see section 3.3.3). The call-
862 backs may be NULL. The appname argument is the name of the calling
863 application and may be used by server plug-ins for logging. On
864 success, SASL_OK is returned, and on failure a SASL C API error
865 code is returned. This function may be called a second time to
866 change the default callbacks, but the first call must be made in a
867 single-threaded environment. The data referenced by the
868 sasl_callback_t structure must persist until sasl_done() is
871 appname specifies the application name. SASL API may use it, for
872 example, for logging or to read an application specific configura-
873 tion. A library must pass NULL as appname. appname can be also be
874 set with sasl_setprop function, and can be queried with sasl_get-
875 prop. <<Specify option name here>>
877 3.5.2. sasl_server_new function
898 Newman et al. Expires: August 2003 FORMFEED[Page 15]
904 INTERNET DRAFT SASL C API February 2003
909 const char *serverFQDN,
910 const char *user_realm,
911 const char *iplocalport,
912 const char *ipremoteport,
913 const sasl_callback_t *callbacks,
919 SASL_NOTINIT -- SASL API not initialized
920 SASL_BADPARAM -- Invalid parameter supplied
921 SASL_NOMECH -- No mechanisms available
922 SASL_NOMEM -- Not enough memory
924 This function creates a server connection context variable. As
925 long as each thread uses its own connection context, the SASL C
928 The service argument is an IANA registered GSSAPI service element
929 as defined in section 1.1. It MUST NOT be NULL.
931 The serverFQDN is the fully qualified name of the server. It MUST
934 The user_realm specifies the default realm. A realm defines a set
935 of users on the system for systems which support multiple user
936 communities ("realms"). If user_realm is NULL, the value of
937 serverFQDN is used as the default realm.
939 The iplocalport is the string with the server IPv4/IPv6 address,
940 followed by ":" and than by port number. An IPv6 address must be
941 enclosed in "[" and "]". NULL may be used for iplocalport, but may
942 result in mechanisms requiring IP address being unavailable.
944 The ipremoteport is the string with the client IPv4/IPv6 address,
945 followed by ":" and than by port number. An IPv6 address must be
946 enclosed in "[" and "]". NULL may be used for ipremoteport, but
947 may result in mechanisms requiring IP address being unavailable.
949 The callbacks argument is a set of server callbacks which may
950 include a connection-specific sasl_getopt_t and/or an authoriza-
953 The flags argument represents server-supported security flags. The
954 only values currently supported are SASL_SECURITY_LAYER to
958 Newman et al. Expires: August 2003 FORMFEED[Page 16]
964 INTERNET DRAFT SASL C API February 2003
967 indicate the server supports the SASL security layer, or 0 to
970 The pconn argument is set to point to the newly created connection
973 3.5.3. sasl_server_start function
978 const char *clientin,
979 insigned int clientinlen,
980 const char **serverout,
981 unsigned int *serveroutlen
984 SASL_CONTINUE -- Another authentication step required
985 SASL_OK -- Authentication Complete
986 SASL_NOTINIT -- SASL API not initialized
987 SASL_BADPARAM -- Invalid parameter supplied
988 SASL_BADPROT -- Client protocol error
989 SASL_NOMECH -- Mechanism not supported
990 SASL_NOVERIFY -- User exists, but no verifier exists for
992 SASL_TRANS -- A password transition is needed to use mechanism
994 This begins an authentication exchange and is called after the
995 client sends the initial authentication command. The mech argu-
996 ment is the mechanism name the client is requesting. If the
997 client includes an optional initial-response, it is passed in the
998 clientin and clientinlen fields. Otherwise NULL and 0 are passed
999 for those arguments. The serverout and serveroutlen are filled in
1000 with the server response, if any. If SASL_CONTINUE is returned,
1001 the server will need to wait for another client message and call
1002 sasl_server_step. If SASL_OK is returned, the authentication is
1003 completed successfully, although server out data may be supplied.
1005 3.5.4. sasl_server_step function
1018 Newman et al. Expires: August 2003 FORMFEED[Page 17]
1024 INTERNET DRAFT SASL C API February 2003
1029 const char *clientin,
1030 insigned int clientinlen,
1031 const char **serverout,
1032 unsigned int *serveroutlen
1035 SASL_CONTINUE -- Another authentication step required
1036 SASL_OK -- Authentication Complete
1037 SASL_NOTINIT -- SASL API not initialized
1038 SASL_NOMECH -- sasl_server_start not called
1039 SASL_BADPARAM -- Invalid parameter supplied
1040 SASL_BADPROT -- Client protocol error
1041 SASL_NOVERIFY -- User exists, but no verifier exists for
1043 SASL_TRANS -- A password transition is needed to use mechanism
1045 This routine performs one step in an authentication sequence.
1047 The conn argument must be a connection context created by
1048 sasl_server_new and used in a previous call to sasl_server_start.
1050 The clientin and clientinlen parameters hold the SASL octet string
1051 received from the client. Note that for those SASL profiles which
1052 base64 encode the exchange, this is the result after the removal
1053 of the base64 encoding (see the sasl_decode64 routine). The cli-
1054 entin MUST have a terminating NUL character not counted by
1057 The serverout and serveroutlen parameters hold the SASL octet
1058 string to encode (if necessary) and send to the client. If
1059 SASL_CONTINUE is returned, the server will need to wait for
1060 another client message and call sasl_server_step. If SASL_OK is
1061 returned, the authentication is completed successfully, although
1062 server out data may be supplied.
1064 3.6. Common SASL API Routines
1066 This section describes the routines that are common to both
1067 clients and servers.
1069 3.6.1. sasl_listmech function
1078 Newman et al. Expires: August 2003 FORMFEED[Page 18]
1084 INTERNET DRAFT SASL C API February 2003
1099 SASL_NOMEM -- Not enough memory
1100 SASL_NOMECH -- No enabled mechanisms
1102 This returns a list of enabled SASL mechanisms in a NUL-terminated
1103 string. The list is constructed by placing the prefix string at
1104 the beginning, placing the sep string between any pair of mecha-
1105 nisms and placing the suffix string at the end.
1107 When calling this function plen and pcount MAY be NULL.
1109 This function returns the list of client side SASL mechanisms, if
1110 the conn was created by sasl_client_new and the list of server
1111 side mechanisms, if the conn was created by sasl_server_new. The
1112 list returned by this function must persist till a next call to
1113 sasl_free_listmech or sasl_listmech.
1115 3.6.2. sasl_free_listmech function
1124 This disposes of the result string returned by sasl_listmech.
1126 3.6.3. sasl_setprop function
1138 Newman et al. Expires: August 2003 FORMFEED[Page 19]
1144 INTERNET DRAFT SASL C API February 2003
1153 SASL_OK -- property set
1154 SASL_BADPARAM -- invalid propnum or value
1155 SASL_NOMEM -- not enough memory to perform operation
1157 This sets a property in a connection context. Commonly used prop-
1158 erties with their descriptions are listed below:
1162 Security layer strength factor (SSF) -- an unsigned integer usable
1163 by the caller to specify approximate security layer strength
1164 desired. It roughly corresponds to the effective key length for
1167 1 = integrity protection only >1 = key lenght of the cipher
1169 SASL_SSF_EXTERNAL property denotes SSF of the external security
1170 layer (e.g. provided by TLS). The value parameter points to
1171 sasl_ssf_t, that is described as follows:
1173 typedef unsigned sasl_ssf_t;
1179 The value parameter for SASL_SEC_PROPS points to sasl_secu-
1180 rity_properties_t structure defined below. A particular implemen-
1181 tation may extend it with additional fields.
1183 typedef struct sasl_security_properties
1188 unsigned maxbufsize;
1190 /* bitfield for attacks to protect against */
1191 unsigned security_flags;
1192 } sasl_security_properties_t;
1194 The min_ssf and the max_ssf define the minimal and the maximal
1198 Newman et al. Expires: August 2003 FORMFEED[Page 20]
1204 INTERNET DRAFT SASL C API February 2003
1209 The maxbufsize specifies the biggest buffer size that the
1210 client/server is able to decode. 0 means that security layer is
1213 The security_flags is a bitmask of the various security flags
1216 SASL_SEC_NOPLAINTEXT -- don't permit mechanisms susceptible to simple
1217 passive attack (e.g., PLAIN, LOGIN)
1218 SASL_SEC_NOACTIVE -- protection from active (non-dictionary) attacks
1219 during authentication exchange.
1220 Authenticates server.
1221 SASL_SEC_NODICTIONARY -- don't permit mechanisms susceptible to passive
1223 SASL_SEC_FORWARD_SECRECY -- require forward secrecy between sessions
1224 (breaking one won't help break next)
1225 SASL_SEC_NOANONYMOUS -- don't permit mechanisms that allow anonymous login
1226 SASL_SEC_PASS_CREDENTIALS -- require mechanisms which pass client
1227 credentials, and allow mechanisms which can pass
1228 credentials to do so
1229 SASL_SEC_MUTUAL_AUTH -- require mechanisms which provide mutual
1234 The value parameter for SASL_AUTH_EXTERNAL property points to the
1235 external authentication ID as provided by external authentication
1236 method, e.g. TLS, PPP or IPSec.
1238 3.6.4. sasl_getprop function
1247 SASL_NOTDONE -- Authentication exchange must complete prior to
1248 retrieving this attribute
1249 SASL_BADPARAM -- bad property number
1251 This requests a pointer to a constant property available through
1252 the SASL API. The most common use by servers is to get the
1253 SASL_USERNAME property which returns the authorization identity
1254 (user to login as) from the SASL mechanism as a UTF-8 string in
1258 Newman et al. Expires: August 2003 FORMFEED[Page 21]
1264 INTERNET DRAFT SASL C API February 2003
1267 the pvalue parameter. Additional properties are listed in section
1270 3.6.5. sasl_dispose function
1278 This function disposes of the connection state created with
1279 sasl_client_new or sasl_server_new, and sets the pointer to NULL.
1280 If the pconn is already NULL the function does nothing.
1282 3.6.6. sasl_done function
1290 A SASL application that is finished with the SASL API must call
1291 this function. This function frees any memory allocated by the
1292 SASL library or any other library state. After this call most of
1293 the SASL API function will again return the SASL_NOTINIT error
1296 There must be a call to sasl_done for every successful call to
1297 sasl_server_init or sasl_client_init made. Only the final
1298 sasl_done does the actual cleanup; the preceding calls simply
1299 decrement an internal reference count.
1301 Connection states MUST be disposed of with sasl_dispose before
1302 calling this function.
1304 4. SASL Security Layer Routines
1306 This section describes the routines need to support a security
1309 4.1. sasl_encode function
1318 Newman et al. Expires: August 2003 FORMFEED[Page 22]
1324 INTERNET DRAFT SASL C API February 2003
1330 unsigned int inputlen,
1331 const char **output,
1332 unsigned int *outputlen
1335 SASL_OK -- Success (returns input if no layer negotiated)
1336 SASL_NOTDONE -- Security layer negotiation not finished
1337 SASL_BADPARAM -- inputlen is greater than the SASL_MAXOUTBUF property
1339 This function encodes a block of data for transmission using secu-
1340 rity layer (if any). The output and outputlen are filled in with
1341 the encoded data and its length respectively. If there is no secu-
1342 rity layer the input buffer is returned in the output. Otherwise,
1343 the output is only valid until a next call to sasl_encode or
1346 4.1. sasl_decode function
1351 unsigned int inputlen,
1352 const char **output,
1353 unsigned int *outputlen
1356 SASL_OK -- Success (returns input if no layer negotiated)
1357 SASL_NOTDONE -- Security layer negotiation not finished
1358 SASL_BADMAC -- Bad message integrity check
1360 This function decodes a block of data received using security
1361 layer (if any). The output and outputlen are filled in with the
1362 decoded data and its length respectively. If there is no security
1363 layer the input buffer is returned in the output. Otherwise, the
1364 output is only valid until a next call to sasl_decode or sasl_dis-
1367 5. Advanced SASL API Routines
1369 This section describes the less frequently used functions avail-
1370 able in the SASL API.
1372 5.1. Additional Initialization Routines
1374 5.1.1. sasl_set_mutex function
1378 Newman et al. Expires: August 2003 FORMFEED[Page 23]
1384 INTERNET DRAFT SASL C API February 2003
1388 sasl_mutex_alloc_t *mutex_alloc,
1389 sasl_mutex_lock_t *mutex_lock,
1390 sasl_mutex_unlock_t *mutex_unlock,
1391 sasl_mutex_free_t *mutex_free
1396 The sasl_set_mutex call sets the callbacks which the SASL API and
1397 plug-ins will use whenever exclusive access to a process shared
1398 resource is needed. A single-threaded client or server need not
1399 call this. The types are designed to be compatible with the LDAP
1402 typedef void *sasl_mutex_alloc_t(void);
1404 On success, this returns a pointer to an allocated and initialized
1405 mutex structure. On failure, it returns NULL.
1407 typedef int sasl_mutex_lock_t(void *mutex);
1409 This will block the current thread until it is possible to get an
1410 exclusive lock on a mutex allocated by the mutex_alloc callback.
1411 On success it returns 0, on failure due to deadlock or bad parame-
1414 typedef int sasl_mutex_unlock_t(void *mutex);
1416 This releases a lock on a mutex allocated by the mutex_alloc call-
1417 back. On success it returns 0, on failure due to an already
1418 unlocked mutex, or bad parameter, it returns -1.
1420 typedef void sasl_mutex_free_t(void *mutex);
1422 This disposes of a mutex allocated by mutex_alloc.
1424 5.1.2. sasl_set_alloc function
1438 Newman et al. Expires: August 2003 FORMFEED[Page 24]
1444 INTERNET DRAFT SASL C API February 2003
1448 sasl_malloc_t *malloc,
1449 sasl_calloc_t *calloc,
1450 sasl_realloc_t *realloc,
1456 This sets the memory allocation functions which the SASL API will
1457 use. The SASL API will use its own routines (usually the standard
1458 C library) if these are not set.
1460 typedef void *sasl_malloc_t(unsigned long mem_size);
1462 This allocates memory mem_size bytes of memory. The memory is not
1463 initialized to any particular value. It returns NULL on a fail-
1464 ure, or when mem_size is 0.
1466 typedef void *sasl_calloc_t(unsigned long elem_size,
1467 unsigned long num_elem);
1469 This allocates elem_size * num_elem bytes of memory. The memory
1470 is initialized to 0. It returns NULL on a failure or when either
1471 elem_size and/or num_elem is 0.
1473 typedef void *sasl_realloc_t(void *mem_ptr, unsigned long
1476 This changes the size of a memory block previously allocated by
1477 malloc or calloc, and returns a pointer to the new location (which
1478 may be different from mem_ptr). If mem_ptr is NULL, it is identi-
1479 cal to the malloc function.
1481 It returns NULL on a failure or when new_size is 0. On failure the
1482 original block is unchanged. When new_size is 0 the function works
1483 as the free function.
1485 typedef void sasl_free_t(void *mem_ptr);
1487 This releases the memory in mem_ptr that was allocated by the mal-
1488 loc or the calloc or resized by the realloc. If mem_ptr is NULL,
1489 the function does nothing and returns immediately. The contents of
1490 the memory may be altered by this call.
1492 6. Additional Properties
1498 Newman et al. Expires: August 2003 FORMFEED[Page 25]
1504 INTERNET DRAFT SASL C API February 2003
1507 SASL_SSF -- security layer security strength factor,
1508 if 0, call to sasl_encode, sasl_decode unnecessary
1509 SASL_MAXOUTBUF -- security layer max output buf unsigned
1510 SASL_DEFUSERREALM -- default realm passed to sasl_server_new or set with
1512 SASL_GETOPTCTX -- context for getopt callback
1513 SASL_CALLBACK -- current callback function list
1514 SASL_IPLOCALPORT -- iplocalport string passed to sasl_server_new/
1516 SASL_IPREMOTEPORT -- ipremoteport string passed to sasl_server_new/
1518 SASL_SERVICE -- service passed to sasl_*_new
1519 SASL_SERVERFQDN -- serverFQDN passed to sasl_*_new
1520 SASL_AUTHSOURCE -- name of the active plugin, if any
1521 SASL_MECHNAME -- active SASL mechanism name, if any
1522 SASL_AUTHUSER -- authentication/admin user (authorization id?)
1526 [IMAP4] Crispin, M., "Internet Message Access Protocol - Version
1527 4rev1", RFC 2060, University of Washington, December 1996.
1529 [KEYWORDS] Bradner, "Key words for use in RFCs to Indicate
1530 Requirement Levels", RFC 2119, Harvard University, March 1997.
1532 [POP3] Myers, J., Rose, M., "Post Office Protocol - Version 3",
1533 RFC 1939, Carnegie Mellon, Dover Beach Consulting, Inc., May 1996.
1535 [POP-AUTH] Myers, "POP3 AUTHentication command", RFC 1734,
1536 Carnegie Mellon, December 1994.
1538 [SASL] Myers, "Simple Authentication and Security Layer (SASL)",
1539 RFC 2222, Netscape Communications, October 1997.
1545 The editor would like to thank Rob Siemborski and Ken Murchison
1546 for providing useful feedback and suggestions.
1548 9. Author's and Editor's Addresses
1554 Innosoft International, Inc.
1558 Newman et al. Expires: August 2003 FORMFEED[Page 26]
1564 INTERNET DRAFT SASL C API February 2003
1568 West Covina, CA 91790 USA
1570 Email: chris.newman@innosoft.com
1576 ACI WorldWide/MessagingDirect
1578 Watford, Hertfordshire, WD17 1FQ, UK
1580 Email: mel@messagingdirect.com
1583 10. Full Copyright Statement
1585 Copyright (C) The Internet Society (2003). All Rights Reserved.
1587 This document and translations of it may be copied and furnished to
1588 others, and derivative works that comment on or otherwise explain it
1589 or assist in its implementation may be prepared, copied, published
1590 and distributed, in whole or in part, without restriction of any
1591 kind, provided that the above copyright notice and this paragraph are
1592 included on all such copies and derivative works. However, this doc-
1593 ument itself may not be modified in any way, such as by removing the
1594 copyright notice or references to the Internet Society or other
1595 Internet organizations, except as needed for the purpose of develop-
1596 ing Internet standards in which case the procedures for copyrights
1597 defined in the Internet Standards process must be followed, or as
1598 required to translate it into languages other than English.
1600 The limited permissions granted above are perpetual and will not be
1601 revoked by the Internet Society or its successors or assigns.
1603 This document and the information contained herein is provided on an
1604 "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
1605 TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
1606 BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
1607 HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MER-
1608 CHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1612 Funding for the RFC Editor function is currently provided by the
1618 Newman et al. Expires: August 2003 FORMFEED[Page 27]
1624 INTERNET DRAFT SASL C API February 2003
1627 A. Appendix A -- Design Goals
1629 The design goals of the SASL C API are as follows:
1632 o To be simple and practical to use.
1634 o To provide related utility services in addition to core SASL func-
1637 o To be reasonably extensible.
1639 o To be suitable for use in a multi-threaded server or client.
1641 o To avoid dependancies on a specific memory allocation system, thread
1642 package or network model.
1644 o To be an independent service rather than a new layer.
1678 Newman et al. Expires: August 2003 FORMFEED[Page 28]