gsasl.h

Go to the documentation of this file.
00001 /* gsasl.h --- Header file for GNU SASL Library.
00002  * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010  Simon Josefsson
00003  *
00004  * This file is part of GNU SASL Library.
00005  *
00006  * GNU SASL Library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License
00008  * as published by the Free Software Foundation; either version 2.1 of
00009  * the License, or (at your option) any later version.
00010  *
00011  * GNU SASL Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License License along with GNU SASL Library; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef GSASL_H
00024 # define GSASL_H
00025 
00026 # include <stdio.h>             /* FILE */
00027 # include <stddef.h>            /* size_t */
00028 # include <unistd.h>            /* ssize_t */
00029 
00030 # ifndef GSASL_API
00031 #  if defined GSASL_BUILDING && defined HAVE_VISIBILITY && HAVE_VISIBILITY
00032 #   define GSASL_API __attribute__((__visibility__("default")))
00033 #  elif defined GSASL_BUILDING && defined _MSC_VER && ! defined GSASL_STATIC
00034 #   define GSASL_API __declspec(dllexport)
00035 #  elif defined _MSC_VER && ! defined GSASL_STATIC
00036 #   define GSASL_API __declspec(dllimport)
00037 #  else
00038 #   define GSASL_API
00039 #  endif
00040 # endif
00041 
00042 # ifdef __cplusplus
00043 extern "C"
00044 {
00045 # endif
00046 
00054 # define GSASL_VERSION "1.7.0"
00055 
00065 # define GSASL_VERSION_MAJOR 1
00066 
00076 # define GSASL_VERSION_MINOR 7
00077 
00087 # define GSASL_VERSION_PATCH 0
00088 
00098 # define GSASL_VERSION_NUMBER 0x010700
00099 
00100   /* RFC 2222: SASL mechanisms are named by strings, from 1 to 20
00101    * characters in length, consisting of upper-case letters, digits,
00102    * hyphens, and/or underscores.  SASL mechanism names must be
00103    * registered with the IANA.
00104    */
00105   enum
00106   {
00107     GSASL_MIN_MECHANISM_SIZE = 1,
00108     GSASL_MAX_MECHANISM_SIZE = 20
00109   };
00110   extern GSASL_API const char *GSASL_VALID_MECHANISM_CHARACTERS;
00111 
00165   typedef enum
00166   {
00167     GSASL_OK = 0,
00168     GSASL_NEEDS_MORE = 1,
00169     GSASL_UNKNOWN_MECHANISM = 2,
00170     GSASL_MECHANISM_CALLED_TOO_MANY_TIMES = 3,
00171     GSASL_MALLOC_ERROR = 7,
00172     GSASL_BASE64_ERROR = 8,
00173     GSASL_CRYPTO_ERROR = 9,
00174     GSASL_SASLPREP_ERROR = 29,
00175     GSASL_MECHANISM_PARSE_ERROR = 30,
00176     GSASL_AUTHENTICATION_ERROR = 31,
00177     GSASL_INTEGRITY_ERROR = 33,
00178     GSASL_NO_CLIENT_CODE = 35,
00179     GSASL_NO_SERVER_CODE = 36,
00180     GSASL_NO_CALLBACK = 51,
00181     GSASL_NO_ANONYMOUS_TOKEN = 52,
00182     GSASL_NO_AUTHID = 53,
00183     GSASL_NO_AUTHZID = 54,
00184     GSASL_NO_PASSWORD = 55,
00185     GSASL_NO_PASSCODE = 56,
00186     GSASL_NO_PIN = 57,
00187     GSASL_NO_SERVICE = 58,
00188     GSASL_NO_HOSTNAME = 59,
00189     GSASL_NO_SAML20_IDP_IDENTIFIER = 65,
00190     GSASL_NO_SAML20_REDIRECT_URL = 66,
00191     /* Mechanism specific errors. */
00192     GSASL_GSSAPI_RELEASE_BUFFER_ERROR = 37,
00193     GSASL_GSSAPI_IMPORT_NAME_ERROR = 38,
00194     GSASL_GSSAPI_INIT_SEC_CONTEXT_ERROR = 39,
00195     GSASL_GSSAPI_ACCEPT_SEC_CONTEXT_ERROR = 40,
00196     GSASL_GSSAPI_UNWRAP_ERROR = 41,
00197     GSASL_GSSAPI_WRAP_ERROR = 42,
00198     GSASL_GSSAPI_ACQUIRE_CRED_ERROR = 43,
00199     GSASL_GSSAPI_DISPLAY_NAME_ERROR = 44,
00200     GSASL_GSSAPI_UNSUPPORTED_PROTECTION_ERROR = 45,
00201     GSASL_KERBEROS_V5_INIT_ERROR = 46,
00202     GSASL_KERBEROS_V5_INTERNAL_ERROR = 47,
00203     GSASL_SHISHI_ERROR = GSASL_KERBEROS_V5_INTERNAL_ERROR,
00204     GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE = 48,
00205     GSASL_SECURID_SERVER_NEED_NEW_PIN = 49,
00206     GSASL_GSSAPI_ENCAPSULATE_TOKEN_ERROR = 60,
00207     GSASL_GSSAPI_DECAPSULATE_TOKEN_ERROR = 61,
00208     GSASL_GSSAPI_INQUIRE_MECH_FOR_SASLNAME_ERROR = 62,
00209     GSASL_GSSAPI_TEST_OID_SET_MEMBER_ERROR = 63,
00210     GSASL_GSSAPI_RELEASE_OID_SET_ERROR = 64
00211     /* When adding new values, note that integers are not necessarily
00212        assigned monotonously increasingly. */
00213   } Gsasl_rc;
00214 
00227   typedef enum
00228   {
00229     GSASL_QOP_AUTH = 1,
00230     GSASL_QOP_AUTH_INT = 2,
00231     GSASL_QOP_AUTH_CONF = 4
00232   } Gsasl_qop;
00233 
00247   typedef enum
00248   {
00249     GSASL_CIPHER_DES = 1,
00250     GSASL_CIPHER_3DES = 2,
00251     GSASL_CIPHER_RC4 = 4,
00252     GSASL_CIPHER_RC4_40 = 8,
00253     GSASL_CIPHER_RC4_56 = 16,
00254     GSASL_CIPHER_AES = 32
00255   } Gsasl_cipher;
00256 
00264   typedef enum
00265   {
00266     GSASL_ALLOW_UNASSIGNED = 1
00267   } Gsasl_saslprep_flags;
00268 
00274   typedef struct Gsasl Gsasl;
00275 
00281   typedef struct Gsasl_session Gsasl_session;
00282 
00316   typedef enum
00317   {
00318     /* Information properties, e.g., username. */
00319     GSASL_AUTHID = 1,
00320     GSASL_AUTHZID = 2,
00321     GSASL_PASSWORD = 3,
00322     GSASL_ANONYMOUS_TOKEN = 4,
00323     GSASL_SERVICE = 5,
00324     GSASL_HOSTNAME = 6,
00325     GSASL_GSSAPI_DISPLAY_NAME = 7,
00326     GSASL_PASSCODE = 8,
00327     GSASL_SUGGESTED_PIN = 9,
00328     GSASL_PIN = 10,
00329     GSASL_REALM = 11,
00330     GSASL_DIGEST_MD5_HASHED_PASSWORD = 12,
00331     GSASL_QOPS = 13,
00332     GSASL_QOP = 14,
00333     GSASL_SCRAM_ITER = 15,
00334     GSASL_SCRAM_SALT = 16,
00335     GSASL_SCRAM_SALTED_PASSWORD = 17,
00336     GSASL_SAML20_IDP_IDENTIFIER = 18,
00337     GSASL_SAML20_REDIRECT_URL = 19,
00338     /* Client callbacks. */
00339     GSASL_SAML20_AUTHENTICATE_IN_BROWSER = 250,
00340     /* Server validation callback properties. */
00341     GSASL_VALIDATE_SIMPLE = 500,
00342     GSASL_VALIDATE_EXTERNAL = 501,
00343     GSASL_VALIDATE_ANONYMOUS = 502,
00344     GSASL_VALIDATE_GSSAPI = 503,
00345     GSASL_VALIDATE_SECURID = 504,
00346     GSASL_VALIDATE_SAML20 = 505
00347   } Gsasl_property;
00348 
00373   typedef int (*Gsasl_callback_function) (Gsasl * ctx, Gsasl_session * sctx,
00374                                           Gsasl_property prop);
00375 
00376   /* Library entry and exit points: version.c, init.c, done.c */
00377   extern GSASL_API int gsasl_init (Gsasl ** ctx);
00378   extern GSASL_API void gsasl_done (Gsasl * ctx);
00379   extern GSASL_API const char *gsasl_check_version (const char *req_version);
00380 
00381   /* Callback handling: callback.c */
00382   extern GSASL_API void gsasl_callback_set (Gsasl * ctx,
00383                                             Gsasl_callback_function cb);
00384   extern GSASL_API int gsasl_callback (Gsasl * ctx, Gsasl_session * sctx,
00385                                        Gsasl_property prop);
00386 
00387   extern GSASL_API void gsasl_callback_hook_set (Gsasl * ctx, void *hook);
00388   extern GSASL_API void *gsasl_callback_hook_get (Gsasl * ctx);
00389 
00390   extern GSASL_API void gsasl_session_hook_set (Gsasl_session * sctx,
00391                                                 void *hook);
00392   extern GSASL_API void *gsasl_session_hook_get (Gsasl_session * sctx);
00393 
00394   /* Property handling: property.c */
00395   extern GSASL_API void gsasl_property_set (Gsasl_session * sctx,
00396                                             Gsasl_property prop,
00397                                             const char *data);
00398   extern GSASL_API void gsasl_property_set_raw (Gsasl_session * sctx,
00399                                                 Gsasl_property prop,
00400                                                 const char *data, size_t len);
00401   extern GSASL_API const char *gsasl_property_get (Gsasl_session * sctx,
00402                                                    Gsasl_property prop);
00403   extern GSASL_API const char *gsasl_property_fast (Gsasl_session * sctx,
00404                                                     Gsasl_property prop);
00405 
00406   /* Mechanism handling: listmech.c, supportp.c, suggest.c */
00407   extern GSASL_API int gsasl_client_mechlist (Gsasl * ctx, char **out);
00408   extern GSASL_API int gsasl_client_support_p (Gsasl * ctx, const char *name);
00409   extern GSASL_API const char *gsasl_client_suggest_mechanism (Gsasl * ctx,
00410                                                                const char
00411                                                                *mechlist);
00412 
00413   extern GSASL_API int gsasl_server_mechlist (Gsasl * ctx, char **out);
00414   extern GSASL_API int gsasl_server_support_p (Gsasl * ctx, const char *name);
00415 
00416   /* Authentication functions: xstart.c, xstep.c, xfinish.c */
00417   extern GSASL_API int gsasl_client_start (Gsasl * ctx, const char *mech,
00418                                            Gsasl_session ** sctx);
00419   extern GSASL_API int gsasl_server_start (Gsasl * ctx, const char *mech,
00420                                            Gsasl_session ** sctx);
00421   extern GSASL_API int gsasl_step (Gsasl_session * sctx,
00422                                    const char *input, size_t input_len,
00423                                    char **output, size_t * output_len);
00424   extern GSASL_API int gsasl_step64 (Gsasl_session * sctx,
00425                                      const char *b64input, char **b64output);
00426   extern GSASL_API void gsasl_finish (Gsasl_session * sctx);
00427 
00428   /* Session functions: xcode.c, mechname.c */
00429   extern GSASL_API int gsasl_encode (Gsasl_session * sctx,
00430                                      const char *input, size_t input_len,
00431                                      char **output, size_t * output_len);
00432   extern GSASL_API int gsasl_decode (Gsasl_session * sctx,
00433                                      const char *input, size_t input_len,
00434                                      char **output, size_t * output_len);
00435   extern GSASL_API const char *gsasl_mechanism_name (Gsasl_session * sctx);
00436 
00437   /* Error handling: error.c */
00438   extern GSASL_API const char *gsasl_strerror (int err);
00439   extern GSASL_API const char *gsasl_strerror_name (int err);
00440 
00441   /* Internationalized string processing: stringprep.c */
00442   extern GSASL_API int gsasl_saslprep (const char *in,
00443                                        Gsasl_saslprep_flags flags, char **out,
00444                                        int *stringpreprc);
00445 
00446   /* Utilities: base64.c, md5pwd.c, crypto.c */
00447   extern GSASL_API int gsasl_simple_getpass (const char *filename,
00448                                              const char *username,
00449                                              char **key);
00450   extern GSASL_API int gsasl_base64_to (const char *in, size_t inlen,
00451                                         char **out, size_t * outlen);
00452   extern GSASL_API int gsasl_base64_from (const char *in, size_t inlen,
00453                                           char **out, size_t * outlen);
00454   extern GSASL_API int gsasl_nonce (char *data, size_t datalen);
00455   extern GSASL_API int gsasl_random (char *data, size_t datalen);
00456   extern GSASL_API int gsasl_md5 (const char *in, size_t inlen,
00457                                   char *out[16]);
00458   extern GSASL_API int gsasl_hmac_md5 (const char *key, size_t keylen,
00459                                        const char *in, size_t inlen,
00460                                        char *outhash[16]);
00461   extern GSASL_API int gsasl_sha1 (const char *in, size_t inlen,
00462                                    char *out[20]);
00463   extern GSASL_API int gsasl_hmac_sha1 (const char *key, size_t keylen,
00464                                         const char *in, size_t inlen,
00465                                         char *outhash[20]);
00466   extern GSASL_API void gsasl_free (void *ptr);
00467 
00468   /* Get the mechanism API. */
00469 # include <gsasl-mech.h>
00470 
00471 #ifndef GSASL_NO_OBSOLETE
00472   /* For compatibility with earlier versions. */
00473 # include <gsasl-compat.h>
00474 #endif
00475 
00476 # ifdef __cplusplus
00477 }
00478 # endif
00479 
00480 #endif                          /* GSASL_H */