auth/api.h

Go to the documentation of this file.
00001 /*
00002  * $Id: api.h 5375 2008-12-17 10:44:19Z henningw $
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  */
00022 
00023 /*!
00024  * \file
00025  * \brief Digest Authentication Module, API exports
00026  * \ingroup auth
00027  * - Module: \ref auth
00028  */
00029 
00030 #ifndef AUTH_API_H
00031 #define AUTH_API_H
00032 
00033 
00034 #include "../../parser/digest/digest.h"
00035 #include "../../parser/msg_parser.h"
00036 #include "../../parser/hf.h"
00037 #include "../../str.h"
00038 #include "../../usr_avp.h"
00039 #include "rfc2617.h"
00040 
00041 
00042 typedef enum auth_result {
00043    NONCE_REUSED = -6,  /*!< Returned if nonce is used more than once */
00044    AUTH_ERROR,         /*!< Error occurred, a reply has not been sent out */
00045    NO_CREDENTIALS,     /*!< Credentials missing */
00046    STALE_NONCE,        /*!< Stale nonce */
00047    INVALID_PASSWORD,   /*!< Invalid password */
00048    USER_UNKNOWN,       /*!< User non existant */
00049    ERROR,              /*!< Error occurred, a reply has been sent out,
00050                            return 0 to the openser core */
00051    AUTHORIZED,         /*!< Authorized. If returned by pre_auth,
00052                             no digest authorization necessary */
00053    DO_AUTHORIZATION,   /*!< Can only be returned by pre_auth. */
00054                        /*!< Means to continue doing authorization */
00055 } auth_result_t;
00056 
00057 
00058 /*!
00059  * \brief Find credentials with given realm, check if we need to authenticate
00060  *
00061  * The purpose of this function is to find credentials with given realm,
00062  * do sanity check, validate credential correctness and determine if
00063  * we should really authenticate (there must be no authentication for
00064  * ACK and CANCEL
00065  * \param _m SIP message
00066  * \param _realm authentification realm
00067  * \param _hftype header field type
00068  * \param _h header field
00069  * \return authentification result
00070  */
00071 typedef auth_result_t (*pre_auth_t)(struct sip_msg* _m, str* _realm,
00072       hdr_types_t _hftype, struct hdr_field** _h);
00073 
00074 
00075 /*!
00076  * \brief Find credentials with given realm, check if we need to authenticate
00077  *
00078  * The purpose of this function is to find credentials with given realm,
00079  * do sanity check, validate credential correctness and determine if
00080  * we should really authenticate (there must be no authentication for
00081  * ACK and CANCEL
00082  * \param _m SIP message
00083  * \param _realm authentification realm
00084  * \param _hftype header field type
00085  * \param _h header field
00086  * \return authentification result
00087  */
00088 auth_result_t pre_auth(struct sip_msg* _m, str* _realm,
00089       hdr_types_t _hftype, struct hdr_field** _h);
00090 
00091 
00092 /*!
00093  * \brief Do post authentification steps
00094  *
00095  * The purpose of this function is to do post authentication steps like
00096  * marking authorized credentials and so on.
00097  * \param _m SIP message
00098  * \param _h header field
00099  * \return authentification result
00100  */
00101 typedef auth_result_t (*post_auth_t)(struct sip_msg* _m, struct hdr_field* _h);
00102 
00103 
00104 /*!
00105  * \brief Do post authentification steps
00106  *
00107  * The purpose of this function is to do post authentication steps like
00108  * marking authorized credentials and so on.
00109  * \param _m SIP message
00110  * \param _h header field
00111  * \return authentification result
00112  */
00113 auth_result_t post_auth(struct sip_msg* _m, struct hdr_field* _h);
00114 
00115 
00116 /*!
00117  * \brief Calculate the response and compare with given response
00118  *
00119  * Calculate the response and compare with the given response string.
00120  * Authorization is successful if this two strings are same.
00121  * \param _cred digest credentials
00122  * \param _method method from the request
00123  * \param _ha1 HA1 value
00124  * \return 0 if comparison was ok, 1 when length not match, 2 when comparison not ok
00125  */
00126 typedef int (*check_response_t)(dig_cred_t* _cred, str* _method, char* _ha1);
00127 
00128 
00129 /*!
00130  * \brief Calculate the response and compare with given response
00131  *
00132  * Calculate the response and compare with the given response string.
00133  * Authorization is successful if this two strings are same.
00134  * \param _cred digest credentials
00135  * \param _method method from the request
00136  * \param _ha1 HA1 value
00137  * \return 0 if comparison was ok, 1 when length not match, 2 when comparison not ok
00138  */
00139 int check_response(dig_cred_t* _cred, str* _method, char* _ha1);
00140 
00141 
00142 /*!
00143  * \brief Calculate H(A1) as per HTTP Digest spec
00144  * \param _alg type of hash algorithm
00145  * \param _username username
00146  * \param _realm authentification realm
00147  * \param _password password
00148  * \param _nonce nonce value
00149  * \param _cnonce cnonce value
00150  * \param _sess_key session key, result will be stored there
00151  */
00152 typedef void (*calc_HA1_t)(ha_alg_t _alg, str* _username, str* _realm,
00153       str* _password, str* _nonce, str* _cnonce, HASHHEX _sess_key);
00154 
00155 
00156 /*!
00157  * \brief Strip the beginning of a realm string
00158  *
00159  * Strip the beginning of a realm string, depending on the length of
00160  * the realm_prefix.
00161  * \param _realm realm string
00162  */
00163 void strip_realm(str *_realm);
00164 
00165 
00166 /*! Auth module API */
00167 typedef struct auth_api {
00168    int_str rpid_avp;      /*!< Name of AVP containing Remote-Party-ID */
00169    int     rpid_avp_type; /*!< type of the RPID AVP */
00170    pre_auth_t  pre_auth;  /*!< The function to be called before auth */
00171    post_auth_t post_auth; /*!< The function to be called after auth */
00172    calc_HA1_t  calc_HA1;  /*!< calculate H(A1) as per spec */
00173    check_response_t check_response; /*!< check auth response */
00174 } auth_api_t;
00175 
00176 
00177 typedef int (*bind_auth_t)(auth_api_t* api);
00178 
00179 
00180 /*!
00181  * \brief Bind function for the auth API
00182  * \param api binded API
00183  * \return 0 on success, -1 on failure
00184  */
00185 int bind_auth(auth_api_t* api);
00186 
00187 
00188 #endif

Generated on Thu May 17 12:00:24 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6